Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

Identify disks on Linux

By updated

Improve this page

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

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.

Terminal window
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 10G 0 disk
sdb 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 rom

Reading 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:

Terminal window
lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
sdb
├─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:

Terminal window
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:

Terminal window
findmnt /
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sdb2 ext4 rw,relatime

Identify 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:

Terminal window
ls -l /dev/disk/by-uuid/
351fec7c-4727-4cad-b24d-c8a1bcb97ad9 -> ../../sdb2
5157-8E36 -> ../../sdb1

The /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:

Terminal window
ls /dev/disk/by-id/
scsi-0QEMU_QEMU_HARDDISK_incus_root
scsi-0QEMU_QEMU_HARDDISK_incus_extra

Detect 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:

Terminal window
sudo dmesg --follow | grep -i sd
# or, with a systemd journal:
sudo journalctl -kf

After changing a partition table, ask the kernel to reread it:

Terminal window
sudo partprobe /dev/sdb

Then 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:

Terminal window
sudo fdisk -l /dev/sda
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

For a complete inventory (useful to document a machine), lshw details vendor, product and bus:

Terminal window
sudo apt install lshw
sudo lshw -class disk -short

The 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:

  1. lsblk: does the target disk have the right size and no unexpected mount point?
  2. Check that it is not mounted: a system disk (/, /boot) must never be the target.
  3. Compare /dev/disk/by-id/ with the expected model/serial if several disks look alike.

Key points

  • lsblk is the first command: disks, partitions, sizes and mounts as a tree.
  • lsblk -f and blkid give the file system and the UUID; findmnt the 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

6 questions
6 min
70% to pass

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

Is this project useful to you?

The guides, courses, quizzes and labs stay free. If you use them regularly, you can contribute to their upkeep and development.

Become a supporting member (new tab) One-time support (new tab) Learn more

Follow the project on LinkedIn