Hard Disk Drives under Linux

useful oneliners

turn off disk (sleep mode) hdparm -Y /dev/sdX or udisksctl power-off -b /dev/sdX
remove disk from system1 echo 1 | sudo tee /sys/block/sdc/device/delete
check power status (might wake up the disk) smartctl -i -n standby or hdparm -C2

check for bad sectors

Since badblocks was originally written to verify floppy disks, its design isn’t construed for modern HDD drives. With sizes such as 18 TB drives, even the regular tip to use -b 4096 won’t help anymore. This is an alternative: Span a crypto layer above the device:3

# cryptsetup open /dev/device name --type plain --cipher aes-xts-plain64

Fill the now opened decrypted layer with zeroes, which get written as encrypted data:

# shred -v -n 0 -z /dev/mapper/name

Compare fresh zeroes with the decrypted layer:

# cmp -b /dev/zero /dev/mapper/name

If it just stops with a message about end of file, the drive is fine. This method is also way faster than badblocks even with a single pass.4


[1] this means that it's not detected anymore and you need to turn it off and on again for it to appear in the Kernel's list of block devices
[2] hdparm -C is reported to be more likely to wake up the disk