Difference between revisions of "How to hotswap Ultrabay devices"

From ThinkWiki
Jump to: navigation, search
(When using the <tt>ata_piix</tt> driver)
(When using the <tt>ata_piix</tt> driver)
Line 24: Line 24:
**[http://home-tj.org/files/libata-tj-stable/libata-tj- Patch tarball against] ([http://lwn.net/Articles/183407/ Announce])
**[http://home-tj.org/files/libata-tj-stable/libata-tj- Patch tarball against] ([http://lwn.net/Articles/183407/ Announce])
**[http://home-tj.org/files/libata-tj-stable/libata-tj-2.6.17-20060625-1.tar.bz2 Patch tarball against 2.6.17/] ([http://article.gmane.org/gmane.linux.ide/11598 Announce])
**[http://home-tj.org/files/libata-tj-stable/libata-tj-2.6.17-20060625-1.tar.bz2 Patch tarball against 2.6.17/] ([http://article.gmane.org/gmane.linux.ide/11598 Announce])
**[http://home-tj.org/files/libata-tj-stable/libata-tj- Patch tarball against]
**[http://home-tj.org/files/libata-tj-stable/libata-tj- Patch tarball against]
* Confirmed to work on
* Confirmed to work on

Revision as of 16:48, 10 July 2006

The following discusses hotswap (AKA "hotplug") of devices in the UltraBay.

When using the ide-disk driver

The following applies if you use the ide-disk driver for the UltraBay device.

Hotswapping is supposed to be supported as well, using either hdparm/Debian hotswap or lt_hotswap to (un)register IDE devices. The latter is the recommended method with kernels from 2.6, since it will leave DMA working. However, for recent models (R52, T43, X41, Z60 and later) no method is known to work while maintaining DMA support; see Problems with SATA and Linux.

Only IDE devices (HDD's, optical drives, zip drives) require special treatment - batteries, floppies and other devices can just be pulled from the bay, provided they are not mounted or in use at the time. However, you should still power them down first using the ibm-acpi eject function.

The ibm-acpi kernel module has an eject function (# echo eject > /proc/acpi/ibm/bay). This only manages the ACPI calls to power down the device and the bay. It does not actually unregister the device from the IDE driver. # cat /proc/acpi/ibm/bay shows "unoccupied" unless an IDE device is present, but the eject function still works and should still be used.

To unregister the device, you can either use the Debian hotswap package, or lt_hotswap.

Debian hotswap also allows the drive to be swapped as a normal user by default, which is useful. You should use hotswap to unregister the device and then # echo eject > /proc/acpi/ibm/bay. However, if you use this method on a 2.6 kernel, you will lose DMA support for the reinserted drive. This is due to kernel issues. This method was reported to work on a ThinkPad T23 (kernels, and 2.6.15-arch) and T42 (kernel 2.6.13), but fails on a ThinkPad T43 (kernel

lt_hotswap is now the recommended method to un- and reregister the IDE device. It installs as a kernel module and has support for automatically unregistering the device when the eject event is generated by ibm-acpi. It will leave DMA support intact. It has supported to work on a ThinkPad T22 and T40 and should work with many other models (but not recent models which require the ata_piix driver for disk DMA support).

When using the ata_piix driver

The following applies when using the ata_piix driver, which is necessary for many recent ThinkPad models that use an Intel ICH6-M controller. See also Problems with SATA and Linux.

Mainline kernels cannot yet reliably recognize newly (re-)inserted UltraBay drives without a reboot. There are experimental hotplug patches against mainline kernels here. Fixes for this are scheduled for 2.6.18.

  • Confirmed to work on

If your kernel was patched to support ata_piix hotplug (don't try it otherwise!) then issue the following after inserting an UltraBay drive to rescan the port:

# echo 0 0 0 >  /sys/class/scsi_host/host1/scan

The inserted drive should now be recognized by the kernel, and appropriate /dev/* entries created automatically (e.g., by udev).

You can safely shut down the drive by issuing the following (this works with all recent mainline kernels):

# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/delete
# echo eject >  /proc/acpi/ibm/bay

The drive can now be ejected.

Scripts for hotswapping

The following scripts and acpid daemon configuration files do the following:

  • Automatically unmounts the relevant filesystems and power off the UltraBay when the UltraBay eject lever is released. Screams if some filesystem can't be unmounted.
  • Rescans the UltraBay port when then UltraBay eject lever is pushed back in.

They assumes you're using the ata_piix driver with an appropriate kernel (see above).

Create /usr/local/sbin/ultrabay_close with permissions 755:

echo 12 > /proc/acpi/ibm/beep
echo 0 0 0 > /sys/class/scsi_host/host1/scan

Create /usr/local/sbin/ultrabay_open with permissions 755:


# Umount the filesystem(s) backed by the given major:minor device(s)
unmount_rdev() { perl - "$@" <<'EOPERL'  # let's do it in Perl
	for $major_minor (@ARGV) {
		$major_minor =~ m/^(\d+):(\d+)$/ or die;
		push(@tgt_rdevs, ($1<<8)|$2);
	open MOUNTS,"</proc/mounts" or die "$!";
	while (<MOUNTS>) {
		next unless -b $dev;  $rdev=(stat($dev))[6];
		next unless grep($_==$rdev, @tgt_rdevs);
		system("umount","-v","$dir")==0  or  $bad=1;
	exit 1 if $bad;

shopt -s nullglob
if [ -d $SYSDIR ]; then
	# Unmount filesystems backed by this device
	unmount_rdev `cat $SYSDIR/block\:*/dev     \
	                  $SYSDIR/block\:*/*/dev`  \
	|| {
		echo 10 > /proc/acpi/ibm/beep; 
		exit 1;
	# Unregister this SCSI device:
	sleep 0.3   # Let HAL+KDE notice the unmount
	echo 1 > $SYSDIR/delete
# Turn off power to the UltraBay:
echo eject > /proc/acpi/ibm/bay
# Tell the user we're OK
echo 12 > /proc/acpi/ibm/beep

Create /etc/acpi/events/ultrabay-close:

event=ibm/bay MSTR 00000001 00000000

Create /etc/acpi/events/ultrabay-open:

event=ibm/bay MSTR 00000003 00000000

Restart acpid.

HAL support

Many programs, KDe included, rely on HAL to get notifications and information about device hotplugging. You need to tell HAL that devices connected the UltraBay port are hotpluggable. To do so, create the file /etc/hal/fdi/information/10-ultrabay.fdi as follows:

<?xml version="1.0" encoding="UTF-8"?> <!-- -*- SGML -*- --> 

<deviceinfo version="0.2">

    <!-- UltraBay Devices -->
    <match key="storage.bus" string="scsi">
      <match key="storage.physical_device" string="/org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0">
        <merge key="storage.hotpluggable" type="bool">true</merge>



By default, HAL doesn't know that UltraBay devices are hotpluggable:

# PHYSDEV=/org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0
# UDI=`hal-find-by-property --key storage.physical_device --string $PHYSDEV` || echo Failed
# hal-get-property --udi $UDI --key block.device
# hal-get-property --udi $UDI --key storage.hotpluggable

After creating /etc/hal/fdi/information/10-ultrabay.fdi as above and re-plugging the device, it will get marked correctly:

# PHYSDEV=/org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0
# UDI=`hal-find-by-property --key storage.physical_device --string $PHYSDEV` || echo Failed
# hal-get-property --udi $UDI --key block.device
# hal-get-property --udi $UDI --key storage.hotpluggable

The string "8086_2653" gives the PCI ID of the Intel 82801FBM southbridge. If your model has a different southbridge, or the UltraBay is attached to a different port, then you can find the appropriate storage.physical_device value by finding out the block device of the currently running UltraBay device (/dev/sdb in the following example) and then running:

# DEVICE=/dev/sdb
# UDI=`hal-find-by-property --key block.device --string $DEVICE` || echo Failed
# hal-get-property --udi $UDI --key storage.physical_device

If you have a different storage.physical_device value, please report your findings.