That’s just a few records on my personal experience regarding the hot-swapping/hot-plugging capabilities of SATA…
First, make sure the controller is set to AHCI in the BIOS so it will issue the required hotplug-messages on status changes (which seems quite likely to be suppressed in legacy-mode, since PATA doesn’t know anything about hotplug)
Next, check if nothing on the harddisk is mounted, preferrably do the whole testing from a live-cd like grml or similar. Then try to talk to the suspected device to ensure it is working correctly, and you’re addressing the right one. I like to check the S.M.A.R.T values for this:
smartctl -A /dev/sdb
In theory, you could just disconnect the drive’s SATA- and power-cables now, I’ve tested this several times without any problems. Just after detaching the cables, the kernel writes some statusmessages to syslog. Should be something like this here:
kernel: ata1: exception Emask 0×10 SAct 0×0 SErr 0×4010000 action 0xe frozen
kernel: ata1: irq_stat 0×00400040, connection status changed
kernel: ata1: SError: { PHYRdyChg DevExch }
kernel: ata1: hard resetting link
kernel: ata1: SATA link down (SStatus 0 SControl 300)
kernel: ata1: EH complete
kernel: ata1.00: detaching (SCSI 0:0:0:0)
If you want to be nicer to your friendly kernel (or safer, depending on how you look at this…), check for the supported SCSI-commands of your drive via sdparm:
sdparm -e -C x /dev/sdb
In my case, this yields the following output (coming from a 500GB Seagate drive):
Available commands:
capacity
eject
load
ready
sense
start
stop
sync
unlock
Now you could try to detach the drive using those commands:
sdparm -C stop /dev/sdb
sdparm -C eject /dev/sdb
Another possibility is the tool “scsiadd”, first print the status using “-p”, then eject the appropriate device using “-r”:
scsiadd -p
scsiadd -r 1
Hello, I am looking for information on proper SATA hot-swap / hot-plug on Ubuntu for about a month and there doesn’t seem to be any consensus. Your blog post caught my attention because I see the exact same kernel messages on my syslog when I pull one of my sata drives out.
My motherboard bios says nothing about AHCI, nor does its documentation, so I am guessing it is not AHCI compliant.
I wanted to ask you: Do you issue any command prior to inserting a new drive? I mean, suppose you want to add a new drive to your array, not replace a drive. If so, does your system recognize it? Mine does, but in wrong PIO/udma modes.
Hi!
If you can’t find anything like AHCI in your BIOS settings, look for things like “legacy” mode or similar in the controller config.
To answer your question: no, I don’t issue any command prior to inserting drives – but I’ve never checked the transfer modes on the new drives. The system just recognized them and I was happy 🙂 (to be more verbose, I didn’t do this on any production server but just on my stupid desktop machine at work that does not have enough SATA-ports – so I used the hotplugging feature just to avoid the unnecessary reboot when changing drives).
Ah, here’s the link my posting is based on: http://blog.shadypixel.com/safely-removing-external-drives-in-linux/
Some time ago, I wrote a small GUI to hotunplug eSATA drives I use for backup. It should be distrib and desktop independent (but requires Qt, but NOT kde).
https://github.com/ibressler/dfmon
Wow great article and specially thanks for the codes