brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: dmesg -w shows the name a disk gets when you plug it in

Disk
~/tips/tip-disk-dmesg-w-plug-in

sudo dmesg -wT

Watches kernel messages live, so you see the device name and any errors of a disk you connect.

Which name did that USB disk get, sdc or sdd? Rather than compare lists before and after, I’d let the kernel tell me.

sudo dmesg -wT

-w (follow) keeps dmesg running and prints new kernel messages as they arrive, a bit like tail -f. -T shows readable times instead of seconds since boot. Plug in the disk and you’ll see lines with the model, its size and the name it got, like sd 6:0:0:0: [sdc] 7814037168 512-byte logical blocks, followed by the partitions it found.

It’s just as useful when something goes wrong. A cable or port problem shows up as resets, I/O errors or the disk connecting and disconnecting in a loop, and a USB disk that only gets slow often shows a drop to a lower speed. Those messages are invisible in a file manager.

Press Ctrl+C to stop following. If you only want what arrives from now on, without the history first, use -W instead of -w.

Two notes. Reading the kernel log needs root on most distributions. And the times from -T can be off after the machine has been suspended, as the man page warns, so on a laptop that has slept, don’t trust them to the second. journalctl -kf shows the same messages with correct times.

Further reading: dmesg(1) manual page

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link