Before any storage operation (partitioning, formatting, mounting, wiping), the first step is to identify the disks precisely. Picking the wrong device, /dev/sda instead of /dev/sdb, destroys data. This guide shows how to list disks with lsblk, find the file system and the UUID with blkid, detect a freshly plugged-in disk, and adopt the reflex that avoids the fatal mistake. Commands tested on AlmaLinux.
What you will learn
- List disks and partitions with
lsblk - Find the file system and the UUID (
lsblk -f,blkid) - Detect a newly plugged-in disk
- Target the right disk before a destructive command
Prerequisites
sudoaccess on the system- Understanding the layered storage model (disk, partition, FS)
List disks with lsblk
lsblk is the reference tool: it shows block devices as a tree, without any particular privilege. It is the first command to run on an unknown machine.
lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsda 8:0 0 10G 0 disksdb 8:16 0 20G 0 disk├─sdb1 8:17 0 100M 0 part /boot/efi└─sdb2 8:18 0 19.9G 0 part /sr0 11:0 1 12.9M 0 romReading it is immediate: sda is a blank 10 GB disk (no partition, not mounted), sdb holds the system (sdb1 for /boot/efi, sdb2 for /), and sr0 is an optical drive. The TYPE column distinguishes disk, part (partition), lvm (logical volume) and rom.
See file systems and UUIDs
To know what each partition contains, add the -f (filesystem) option:
lsblk -fNAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTSsdasdb├─sdb1 vfat FAT32 UEFI 5157-8E36 89.6M 9% /boot/efi└─sdb2 ext4 1.0 rootfs 351fec7c-4727-4cad-b24d-c8a1bcb97ad9 18.1G 6% /You can see that sda has no file system (empty columns), whereas sdb2 is ext4 with its UUID and its usage rate. The blkid command gives the same information in condensed form, plus the PARTUUID:
sudo blkid/dev/sdb2: LABEL="rootfs" UUID="351fec7c-4727-4cad-b24d-c8a1bcb97ad9" TYPE="ext4" PARTUUID="a90da887-6966-453e-acfd-f7eb38208a17"/dev/sdb1: LABEL="UEFI" UUID="5157-8E36" TYPE="vfat" PARTUUID="8275327b-ed4c-495e-aa2b-2133cea38f71"To see only the mounted file systems and their options, findmnt is more readable than mount:
findmnt /TARGET SOURCE FSTYPE OPTIONS/ /dev/sdb2 ext4 rw,relatimeIdentify by UUID rather than by /dev/sdX
The /dev/sdX name is not stable: it depends on the detection order at boot. Plugging in a USB disk can shift the letters, and sdb becomes sdc. That is why a volume is referenced by its UUID (or its label) in /etc/fstab, never by /dev/sdX.
udev (the systemd-udevd daemon) maintains stable links in /dev/disk/, created by the rules in /usr/lib/udev/rules.d/60-persistent-storage.rules:
ls -l /dev/disk/by-uuid/351fec7c-4727-4cad-b24d-c8a1bcb97ad9 -> ../../sdb25157-8E36 -> ../../sdb1The /dev/disk/by-id/ directory identifies the disk by its hardware model and serial number, independent of the kernel's enumeration, ideal to target a precise physical disk:
ls /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_incus_rootscsi-0QEMU_QEMU_HARDDISK_incus_extraDetect a newly plugged-in disk
A disk added while running does not always show up immediately. Two commands help without rebooting: one follows the detection by the kernel live, the other makes the kernel reread a partition table you have just changed.
To follow the kernel's detection live:
sudo dmesg --follow | grep -i sd# or, with a systemd journal:sudo journalctl -kfAfter changing a partition table, ask the kernel to reread it:
sudo partprobe /dev/sdbThen confirm with lsblk. If the disk stays invisible, check the cabling or the controller; on a VM, check that it is really attached.
Detailed hardware inventory
For the model, the manufacturer and the interface of a disk, fdisk -l already gives the essentials:
sudo fdisk -l /dev/sdaDisk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectorsDisk model: QEMU HARDDISKUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesFor a complete inventory (useful to document a machine), lshw details vendor, product and bus:
sudo apt install lshwsudo lshw -class disk -shortsudo dnf install lshwsudo lshw -class disk -shortThe reflex against destructive mistakes
Most storage incidents come from a command run on the wrong disk. Before any mkfs, parted, dd or wipefs, take three seconds:
lsblk: does the target disk have the right size and no unexpected mount point?- Check that it is not mounted: a system disk (
/,/boot) must never be the target. - Compare
/dev/disk/by-id/with the expected model/serial if several disks look alike.
Key points
lsblkis the first command: disks, partitions, sizes and mounts as a tree.lsblk -fandblkidgive the file system and the UUID;findmntthe mounts.- Always reference a volume by UUID (stable), never by
/dev/sdX(which can change). /dev/disk/by-id/targets a physical disk by model and serial.- A blank disk (no partition, no mount) is typically the one to prepare.
- Check size and mounts before any destructive command: no confirmation is asked.
Knowledge check
Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Manage partitions on Linux
A new full quiz with random questions
Work again only on the questions you missed