
Low‑level Device Insights Using blkid & lsblk (Existing, but highlight)
Table of Contents
- What Is This Article About?
- It All Started with a Missing Disk…
- Why Should You Care?
- blkid and lsblk: The Low-Level Sidekicks
- How do blkid and lsblk Work?
- Use Cases Tree & Benefits
- Fast Setup Guide: blkid & lsblk in Action
- Mini Glossary with Real-Talk Definitions
- Examples and Cases (Comic Metaphor Table)
- Beginner Mistakes, Myths & Similar Tools
- “Use This If…” Decision Tree
- Automation, Unconventional Hacks & Scripts
- A Short Admin Story
- Conclusion: Wrap-Up & Recommendations
What Is This Article About?
Ever been knee-deep in a server setup or migration, only to discover that your disks aren’t where you thought they’d be, or your partitions look like a cyberpunk spaghetti mess? If you’re juggling cloud, Docker, VPS, or even a proud, humming dedicated server, mastering low-level disk insight is a superpower. This post is your practical, no-nonsense guide to using blkid and lsblk—two native Linux tools that let you see, identify, and untangle your block devices with ninja precision. We’ll cover what they are, why they matter, and how you can use them to avoid downtime, data loss, and those “uh-oh” moments that haunt sysadmins in their sleep.
It All Started with a Missing Disk…
Picture this: You’ve spun up a fresh cloud VPS, attached a juicy new SSD, and you’re ready to roll out your next epic project. But wait… Where is my disk?
You run ls /dev/sd*
and see… nothing new. Mounting fails. Partition tools scratch their heads. Your filesystem? Still MIA. Panic sets in; your coffee goes cold.
This scenario isn’t rare—it’s almost a rite of passage. Disks get swapped, partitions go rogue, UUIDs mismatch, Docker volumes vanish, and your cloud provider’s dashboard shrugs with indifference. When uptime is life, you need to know exactly what block devices are present, what they’re called, and what’s on them. That’s where blkid and lsblk come to the rescue.
Why Should You Care?
- Accurate Disk Management: Avoid data loss by knowing exactly what device you’re formatting or mounting.
- Zero-Downtime Upgrades: Confidently swap, clone, or migrate disks without breaking your services.
- DevOps Automation: Script your infrastructure with device UUIDs that never change, not fragile device names.
- Troubleshooting Superpowers: When Docker, RAID, LVM, or cloud APIs get weird, see what’s really there.
If you want reliable uptime (and who doesn’t?), these tools are your new best friends.
blkid and lsblk: The Low-Level Sidekicks
In the Linux world, blkid and lsblk are your X-ray specs for block devices. They’re built-in, fast, and don’t require you to install or maintain extra software. Here’s a quick intro:
- blkid: Shows you the “identity” of block devices—UUIDs, filesystem types, labels, etc.
- lsblk: Visualizes the structure of your disks—think family tree style, with parents (disks), children (partitions), and grandkids (LVM, loop devices, etc).
Together, they make sense of even the messiest server storage setups.
How do blkid and lsblk Work?
blkid: Device Detective
- Algorithm: Scans /dev for block devices, reads metadata superblocks, and prints identifiers (UUID, LABEL, TYPE, etc).
- Structure: Each device is a line, with key=value pairs.
- Speed: Blazing fast (doesn’t read entire disks, only headers).
lsblk: Device Tree Whisperer
- Algorithm: Reads kernel device tree, builds parent/child map for disks, partitions, and nested devices.
- Output: Tabular or tree, with columns for NAME, SIZE, TYPE, MOUNTPOINT, and more.
- Bonus: Can show filesystem info with
-f
, or output as JSON for scripts.
Setup: Fast as Typing
You don’t have to install anything—most Linux systems ship with these tools pre-installed. Just open your terminal and start typing!
Use Cases Tree & Benefits
-
Server Provisioning:
- Identify attached disks in a new cloud or VPS instance.
- Map cloud provider disk names to Linux device names.
- Verify partition and filesystem types before automation scripts run wild.
-
Disk Upgrades & Swaps:
- Clone or move data by UUID, not device letter (bye-bye, sda/sdb mixups).
- Check new disks for filesystem signatures before mounting.
-
Docker, LVM, and RAID:
- Pinpoint which block device backs a Docker volume or LVM logical volume.
- Spot RAID members and reconstruct arrays with confidence.
-
Forensic & Recovery:
- Find orphaned partitions or “lost” disks after a reboot or migration.
- Identify corrupted or wrongly labeled filesystems at a glance.
Bottom line: If you need to know what’s really on your server’s metal (or virtual metal), blkid and lsblk are your first stop.
Fast Setup Guide: blkid & lsblk in Action
Step 1: See All Block Devices
lsblk
This gives you a beautiful tree like:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk ├─sda1 8:1 0 96G 0 part / ├─sda2 8:2 0 1G 0 part [SWAP] sdb 8:16 0 100G 0 disk
Step 2: Identify Filesystem Types and UUIDs
blkid
Which spits out:
/dev/sda1: UUID="abcd-1234" TYPE="ext4" PARTUUID="0001" /dev/sda2: UUID="efgh-5678" TYPE="swap" PARTUUID="0002" /dev/sdb: (no filesystem yet!)
Step 3: Match Devices to Mount Points
lsblk -f
This adds columns for FSTYPE and UUID, so you see all the info in one place.
Step 4: Use UUIDs in /etc/fstab
Never use /dev/sda1 directly in /etc/fstab. Use the UUID from blkid or lsblk -f:
UUID=abcd-1234 / ext4 defaults 0 1
Step 5: Output as JSON for Scripts
lsblk -O -J
Perfect for parsing in Python, Bash, or Ansible.
Step 6: Find Devices by Label or Type
E.g., to find all swap partitions:
blkid -t TYPE=swap
Or to find a disk by label:
blkid -L mydata
Mini Glossary with Real-Talk Definitions
- Block Device: Any hardware or virtual storage that moves data in “blocks” (disks, SSDs, USB sticks, loop devices, etc).
- Partition: A slice of a block device, like a pizza slice on your disk.
- UUID: A globally unique identifier for a partition or filesystem. Like a tattoo—never changes (unless you wipe/reformat).
- LABEL: A human-readable name you can slap onto a filesystem. Like writing “MyCoolDisk” on your hard drive with a Sharpie.
- fstab: The file that tells Linux what to mount where, during boot.
- Mount Point: Where a disk or partition shows up in your filesystem tree (e.g., /mnt/data).
Examples and Cases (Comic Metaphor Table)
Case | blkid/lsblk as Superhero | Without blkid/lsblk (Chaos Mode) |
---|---|---|
Mounting a new disk on a cloud VPS | 🦸♂️ “I see your UUID and filesystem. Formatted, mounted, done.” | 🤡 “Which /dev/sdX is it? Oops, formatted the wrong disk. Panic!” |
Upgrading server disks | 🦸♂️ “Mapping old and new by UUIDs. No mixups. Smooth sailing.” | 🤡 “Device names changed after reboot. Mount failed. Server down.” |
Recovering after a reboot | 🦸♂️ “lsblk -f reveals that lost /data partition in seconds.” | 🤡 “Digging through dmesg. Guessing. Nothing works. Boss is angry.” |
Writing an Ansible/Bash automation | 🦸♂️ “Script finds disks by TYPE/LABEL. No hardcoding, no surprises.” | 🤡 “Script fails if device order changes. ‘Works on my VM!’” |
Beginner Mistakes, Myths & Similar Tools
Common Mistakes
- Confusing device names (e.g., sda, sdb) with permanent IDs. (They’re not!)
- Forgetting to use
sudo
—some info might be hidden as regular user. - Assuming disks are auto-mounted because they show up in lsblk (not always true!).
- Editing /etc/fstab with device names instead of UUIDs or LABELs.
Popular Myths
- “ls /dev/sd* tells me everything.” (It doesn’t—won’t show filesystems, labels, or structure.)
- “blkid is only for advanced users.” (Nope—it’s as easy as typing ‘blkid’.)
Similar Tools & Programs
- fdisk/parted: For partition editing—not for quick inventory or scripting.
- mount/umount: Only for mounting, doesn’t show device metadata.
- ls /dev/disk/by-uuid/: Shows UUID symlinks, but not as human-friendly as blkid/lsblk.
- udevadm info: For deep device metadata, but more complex.
For most admin and automation needs, blkid and lsblk hit the sweet spot of power and simplicity.
“Use This If…” Decision Tree
🤔 Do you need to see what disks/partitions your server really has? ⬇️ Yes ➡️ Use lsblk ⬇️ Do you need filesystem types, UUIDs, or labels? ⬇️ Yes ➡️ Use blkid (or lsblk -f) ⬇️ Need to automate? Want JSON? ⬇️ Yes ➡️ Use lsblk -J and parse output in your scripts! ⬇️ Complex RAID/LVM setups? ⬇️ Yes ➡️ Use lsblk -o +UUID and blkid together.
For extra-reliable, scalable hosting, check out MangoHost VPS or MangoHost Dedicated Servers!
Automation, Unconventional Hacks & Scripts
Automation Awesomeness
- Use
lsblk -J
in Python or Bash to generate dynamic fstab files. - Verify disks on boot, auto-mount new volumes, or send alerts if a disk goes missing.
- Template your Ansible playbooks to use
blkid -L
orblkid -t TYPE=…
for bulletproof, device-independent automation.
Unconventional Hacks
- “Disk Health Check” scripts that scan all block devices, log their sizes, and alert on changes.
- Auto-label new disks on first boot with
e2label
and verify withblkid
. - Auto-format and mount disks based on type (e.g., auto-mount all new XFS disks to /mnt/xfs-UUID).
Practical Bash Script Example
#!/bin/bash # Mount all EXT4 disks with label 'data' to /mnt/data for dev in $(blkid -t TYPE=ext4 -o device); do LABEL=$(blkid -o value -s LABEL $dev) if [ "$LABEL" = "data" ]; then mountpoint="/mnt/data" mkdir -p $mountpoint mount $dev $mountpoint echo "Mounted $dev at $mountpoint" fi done
You can extend this to auto-mount new disks by UUID, or to generate /etc/fstab entries on the fly!
A Short Admin Story
Meet Alex, a sleep-deprived admin. One night, a customer’s high-traffic site goes down after a cloud provider “helpfully” remaps device names on reboot. The app expects /dev/sdb, but that device is now a blank disk. Database missing, panic rising.
Alex runs lsblk -f
and instantly spots the real database disk—UUID intact, just renamed to /dev/sdc. Alex updates /etc/fstab to use the UUID, remounts, and the site is back up before anyone notices. Coffee saved, reputation intact. All thanks to blkid and lsblk!
Conclusion: Wrap-Up & Recommendations
- blkid and lsblk give you instant, reliable, low-level insight into all block devices—essential for any server, VPS, Docker, or cloud admin.
- Use them to avoid catastrophic mistakes, automate reliably, and solve storage mysteries fast.
- Always mount by UUID or LABEL, not device names. Trust blkid and lsblk to tell you the truth.
- For more advanced scripting, leverage their JSON output or grep/filter by type/label.
- Don’t wait for disaster—add these tools to your workflow now, and you’ll sleep better at night!
Ready to take on bigger projects? Get your next VPS or dedicated server and use blkid and lsblk for a rock-solid setup from day one!
More info at the official project pages: lsblk man page, blkid man page.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.