I bought a trayless mobile SATA rack and explored the linux SATA hot-swap capabilities. My mainboard (with a quite new AHCI compatible chipset) does support hot-swap and so I put a hdd into my mobile rack, watched dmesg to show it settle down and apear under /dev. After that, I removed the drive and noted the following dmesgoutput:
ata3.00: detaching (SCSI 2:0:0:0)
sd 2:0:0:0: [sdf] Synchronizing SCSI cache
sd 2:0:0:0: [sdf] Result: hostbyte=0x04 driverbyte=0x00
sd 2:0:0:0: [sdf] Stopping disk
sd 2:0:0:0: [sdf] START_STOP FAILED
sd 2:0:0:0: [sdf] Result: hostbyte=0x04 driverbyte=0x00
ata3: exception Emask 0x10 SAct 0x0 SErr 0x40c0000 action 0xe frozen
ata3: irq_stat 0x00000040, connection status changed
ata3: SError: { CommWake 10B8B DevExch }
ata3: hard resetting link
ata3: SATA link down (SStatus 0 SControl 300)
ata3: EH complete
That looked rather ill to me so I startet digging around to learn how to tell the system that I soon will remove the harddrive so that all cached data can be written safely to disk. I discovered how to disable SCSI devices via the /proc interface and tried it and now my dmesg looked a lot nicer to me:
sd 2:0:0:0: [sdf] Synchronizing SCSI cache
sd 2:0:0:0: [sdf] Stopping disk
ata3.00: disabled
The nasty thing is that you need to know the SCSI id of the drive to remove. So I created a small bash script that can shut down a drive by using its /dev/sdX name:
#!/bin/bash
# (c) 2009 by Dennis Birkholz (firstname DOT lastname [at] nexxes.net)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can received a copy of the GNU General Public License at
# <http://www.gnu.org/licenses/>.
function usage {
echo "Usage $0 [device]"
echo
echo "Disable supplied SCSI device"
exit
}
# Need a parameter
[ "$1" == "" ] &&
usage
# Verify parameter exists
( [ ! -e "$1" ] || [ ! -b "$1" ] ) &&
echo "Supplied devices does not exist or is not a block device." >/dev/stderr &&
exit 1
# Verify SCSI disk entries exist in /sys
[ ! -d "/sys/class/scsi_disk/" ] &&
echo "Could not find SCSI disk entries in sys, aborting." >/dev/stderr &&
exit 2
# Get major/minor device string of device
major=$(stat --dereference --format='%t' "$1")
major=$(printf '%d\n' "0x${major}")
minor=$(stat --dereference --format='%T' "$1")
minor=$(printf '%d\n' "0x${minor}")
deviceID="${major}:${minor}"
echo "Major/Minor number for device '$1' is '${deviceID}'..."
for device in /sys/class/scsi_disk/*; do
[ "$(< ${device}/device/block*/dev)" != "${deviceID}" ] && continue
scsiID=$(basename "${device}")
echo "Found SCSI ID '${scsiID}' for device '${1}'..."
echo 1 > ${device}/device/delete
echo "SCSI device removed."
exit 0
done
echo "Could not identify device as SCSI device, aborting." >/dev/stderr
exit 4
Put it under /usr/local/sbin and name it like hotremove and you can remove your devices by calling hotremove /dev/sdX without the pain of knowing SCSI ids.
(Warning: don’t forget to unmount first! Maybe later I will add auto unmounting also …)

