Disks and filesystems

Identify a new device

Confirm a newly attached disk by stable facts before running any command that can overwrite data.

8 minute lesson

~~~

Device names such as /dev/sdb can change when hardware or attachment order changes.

The kernel hands out names in discovery order. Add a disk, reboot, change a cable or a cloud attachment, and yesterday’s /dev/sdb can become today’s /dev/sdc. Formatting a device is irreversible, so identifying the target by name alone is how people destroy the wrong disk.

Never choose a destructive target from position alone. Confirm it with facts that don’t depend on ordering: size, model, serial number, and what’s already on it.

Collect the facts

Start with lsblk and ask for the columns that identify hardware:

lsblk -o NAME,SIZE,TYPE,MODEL,SERIAL
NAME   SIZE TYPE MODEL            SERIAL
sda     80G disk Samsung SSD 870  S5XANG0N123456A
sdb    500G disk WDC WD5000AZLX   WD-WCC6Z4123456

SIZE should match what you attached. MODEL and SERIAL should match the label on the physical disk or the volume metadata in your cloud provider’s console.

Then check for existing filesystem signatures:

sudo blkid /dev/sdb

If the disk is genuinely new, blkid prints nothing. Output like TYPE="ext4" means there is already a filesystem there. Stop and find out whose data that is before going further.

The kernel log confirms what was just attached:

sudo dmesg | tail -5
# [9128.442] sd 2:0:1:0: [sdb] 976773168 512-byte logical blocks: (500 GB/465 GiB)
# [9128.451] sd 2:0:1:0: [sdb] Attached SCSI disk

If the disk isn’t brand new, smartctl -i /dev/sdb from the smartmontools package gives you the model and serial again, plus SMART health data. A used disk that’s already failing is worth knowing about before you trust it.

The rule

Compare lsblk, blkid, size, model, serial, filesystem signatures, and provider metadata. You want at least three independent facts pointing at the same device. “It’s the second one in the list” is not a fact. Unmount and back up anything uncertain.

Attach a disposable volume. Record at least three independent facts that identify it, then explain why another existing device is not the target.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →