scripts-fabq/notes/storage.md
Fabrice Quenneville 13c0acd990 feat: split and clean drive/storage notes into three focused files
* notes/btrfs.md : remove generic drive commands, genericize all UUIDs/paths/hostnames, add Placeholders section, add command shorthands table, collapse backup procedures into a single generic template
* notes/linux.md : remove all storage and drive-related content, genericize all hardcoded usernames/hostnames/paths
* notes/storage.md : new file consolidating all storage tooling (smartctl, badblocks, dd, hdparm, fsck, findmnt, fstab) from both btrfs.md and linux.md
2026-04-05 18:22:20 -04:00

5.6 KiB

Storage

Table of Contents

Placeholders

Replace the placeholders below with the appropriate values for your setup:

  • Devices

    • Block device: <device> (e.g., /dev/sda)
    • Partition: <partition> (e.g., /dev/sda1)
    • UUID: <uuid> (e.g., a1b2c3d4-e5f6-7890-abcd-ef1234567890)
  • Paths

    • Mount point: <mountpoint> (e.g., /mnt/media)
    • Directory path: <dirpath> (e.g., /mnt/data)

Drive Information

List Block Devices

Check all attached block devices by type:

ls /dev/sd*
ls /dev/nv*

List Mountpoints and Usage

Tree view of all block devices with sizes and mountpoints

lsblk
lsblk -f
  • -f: Add filesystem type, label, and UUID to the tree.

Disk space usage for all mounted filesystems

df -h
  • -h: Human-readable.

Disk space usage for a specific device

df -h | grep <device>

Inspect fstab

View all configured mount entries

cat /etc/fstab

Find Device Path from UUID

Using lsblk:

lsblk -o NAME,UUID,MOUNTPOINT

Using blkid:

blkid | grep <uuid>
blkid -U <uuid>

Power On Hours

Check power-on hours across multiple drives at once:

for dev in /dev/sd{a,b,c,d}; do echo -n "$dev: "; smartctl -a $dev | grep "Power_On_Hours"; done

Partitions and Filesystems

View partition table and disk details:

fdisk -l <device>

Check and repair a filesystem:

fsck <partition>

Mounting

Validate all fstab entries

findmnt --verify --verbose

Dry-run mount of all fstab entries, reports what would succeed or fail

mount -fav
  • -f: Fake mount — goes through the motions without making the actual syscall.
  • -a: Process all entries in /etc/fstab (excluding noauto).
  • -v: Verbose output.

Find mount point details:

findmnt <device>
mount | grep <device>

Apply fstab changes without rebooting

mount -o remount -a

Unmount and Safely Remove

umount <device>
eject <device>

SMART Diagnostics

Get full SMART information for a drive:

smartctl -a <device>

Get drive identity and model info only:

smartctl -i <device>

Run a short SMART test:

smartctl -t short <device>

Run a long SMART test:

smartctl -t long <device>

View test results:

smartctl -a <device>

Check SMART device statistics (error counters, etc.):

smartctl -A <device>

Badblocks

Read-only test:

badblocks -v <device>

Non-destructive read-write test:

Save to RAM -> Write Pattern -> Verify -> Restore

badblocks -nsv <device>
  • -n: Non-destructive read-write test.
  • -s: Show progress.
  • -v: Verbose output.
  • Warning: If the computer loses power or the kernel panics after Step 2 but before Step 4, that specific block of data will be lost

Destructive write test

Overwrites all data — use only on blank drives or drives to be deleted.

badblocks -wsv <device>

Cloning drives and images with dd

Clone a drive or create an image:

dd if=<source-device> of=<destination-device> bs=4M status=progress
dd if=<source-device> of=<image-file>.img bs=4M status=progress

Restore from image:

dd if=<image-file>.img of=<destination-device> bs=4M status=progress
sync

Benchmarking

Measure read speed with hdparm:

hdparm -t <device>

USB Devices

Device Recognition

Check if the system recognizes the device and show recent USB-related kernel messages:

lsusb
dmesg | tail -n 20

Test Device Integrity

Warning: The write test is destructive. All data on will be permanently overwritten. Verify the target device with lsblk before running.

  1. Unmount the device (if mounted):

    umount <mountpoint>
    
  2. Write test:

    dd if=/dev/zero of=<device> bs=4M count=256 status=progress
    
  3. Read test:

    dd if=<device> of=/dev/null bs=4M count=256 status=progress
    
  4. Check for bad blocks:

    badblocks -wsv <device>
    
  5. Run a SMART test:

    smartctl -t short <device>
    smartctl -a <device>
    

Switching Two USB Keys

Copy data off, reformat, and restore:

cp -r /media/<username>/<volume-label> /tmp/<backup-folder>
umount <device-partition>
mkfs.vfat <device-partition>

cp -r /tmp/<backup-folder> /media/<username>/<new-volume-label>
umount <device-partition>

Or clone with dd:

dd if=<source-device> of=/tmp/usb_image.img bs=4M status=progress
mkfs.vfat <device-partition>
dd if=/tmp/usb_image.img of=<destination-device> bs=4M status=progress
sync