<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.thinkwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Max2k</id>
	<title>ThinkWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.thinkwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Max2k"/>
	<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/wiki/Special:Contributions/Max2k"/>
	<updated>2026-04-13T03:30:43Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.12</generator>
	<entry>
		<id>https://www.thinkwiki.org/w/index.php?title=How_to_hotswap_Ultrabay_devices&amp;diff=28227</id>
		<title>How to hotswap Ultrabay devices</title>
		<link rel="alternate" type="text/html" href="https://www.thinkwiki.org/w/index.php?title=How_to_hotswap_Ultrabay_devices&amp;diff=28227"/>
		<updated>2007-02-14T10:38:53Z</updated>

		<summary type="html">&lt;p&gt;Max2k: /* Details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following discusses hotswap (AKA &amp;quot;hotplug&amp;quot;) of devices in the [[UltraBay]].&lt;br /&gt;
&lt;br /&gt;
==When using the &amp;lt;tt&amp;gt;ide-disk&amp;lt;/tt&amp;gt; driver==&lt;br /&gt;
The following applies if you use the &amp;lt;tt&amp;gt;ide-disk&amp;lt;/tt&amp;gt; driver for the UltraBay device.&lt;br /&gt;
&lt;br /&gt;
Hotswapping is supposed to be supported as well, using either hdparm/[http://packages.debian.org/unstable/admin/hotswap 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]].&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The [[ibm-acpi]] kernel module has an eject function ({{cmdroot|echo eject &amp;gt; /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. {{cmdroot|cat /proc/acpi/ibm/bay}} shows &amp;quot;unoccupied&amp;quot; unless an IDE device is present, but the eject function still works and should still be used.&lt;br /&gt;
&lt;br /&gt;
To unregister the device, you can either use the [http://packages.debian.org/unstable/admin/hotswap Debian hotswap] package, or [[lt_hotswap]].&lt;br /&gt;
&lt;br /&gt;
[http://packages.debian.org/unstable/admin/hotswap Debian hotswap] also allows the drive to be swapped as a normal user by default, which is useful. You should use &amp;lt;tt&amp;gt;hotswap&amp;lt;/tt&amp;gt; to unregister the device and then {{cmdroot|echo eject &amp;gt; /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 2.6.8.1, 2.6.14.2 and 2.6.15-arch) and {{T42}} (kernel 2.6.13), but fails on a ThinkPad {{T43}} (kernel 2.6.14.3).&lt;br /&gt;
&lt;br /&gt;
[[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 (if loaded with the auto_eject=1 option) 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 &amp;lt;tt&amp;gt;ata_piix&amp;lt;/tt&amp;gt; driver for disk DMA support). With the [[lt_hotswap]] kernel module loaded, run: {{cmdroot|modprobe -r ide_cd &amp;amp;&amp;amp; modprobe -r cdrom &amp;amp;&amp;amp; echo &amp;quot;MSTR eject&amp;quot; &amp;gt; /proc/acpi/lths}}&lt;br /&gt;
&lt;br /&gt;
===HAL support===&lt;br /&gt;
&lt;br /&gt;
HAL support also can also be configured To do so, create the file {{path|/etc/hal/fdi/information/10-ultrabay.fdi}} as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt; &amp;lt;!-- -*- SGML -*- --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;deviceinfo version=&amp;quot;0.2&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;device&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;!-- UltraBay Devices --&amp;gt;&lt;br /&gt;
    &amp;lt;match key=&amp;quot;storage.bus&amp;quot; string=&amp;quot;ide&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;match key=&amp;quot;storage.physical_device&amp;quot; string=&amp;quot;/org/freedesktop/Hal/devices/pci_8086_24ca_ide_1_0&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;merge key=&amp;quot;storage.hotpluggable&amp;quot; type=&amp;quot;bool&amp;quot;&amp;gt;true&amp;lt;/merge&amp;gt;&lt;br /&gt;
      &amp;lt;/match&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/device&amp;gt;&lt;br /&gt;
&amp;lt;/deviceinfo&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For more details see HAL section for ata driver.&lt;br /&gt;
&lt;br /&gt;
==When using the &amp;lt;tt&amp;gt;ata_piix&amp;lt;/tt&amp;gt; driver==&lt;br /&gt;
The following applies when using the &amp;lt;tt&amp;gt;ata_piix&amp;lt;/tt&amp;gt; driver, which is necessary for many recent ThinkPad models that use an [[Intel ICH6-M]] controller. See also [[Problems with SATA and Linux]]. &lt;br /&gt;
&lt;br /&gt;
Mainline kernels before 2.6.18 cannot reliably recognize newly (re-)inserted UltraBay drives without a reboot. There are experimental hotplug patches against pre-2.6.18 mainline kernels [http://home-tj.org/wiki/index.php/Libata-tj-stable here].&lt;br /&gt;
&lt;br /&gt;
* Available hotplug patches&lt;br /&gt;
**[http://home-tj.org/files/libata-tj-stable/libata-tj-2.6.16.16-20060512.tar.bz2 Patch tarball against 2.6.16.16] ([http://lwn.net/Articles/183407/ Announce])&lt;br /&gt;
**[http://home-tj.org/files/libata-tj-stable/libata-tj-2.6.17-20060625-1.tar.bz2 Patch tarball against 2.6.17/2.6.17.1] ([http://article.gmane.org/gmane.linux.ide/11598 Announce])&lt;br /&gt;
**[http://home-tj.org/files/libata-tj-stable/libata-tj-2.6.17.4-20060710.tar.bz2 Patch tarball against 2.6.17.4]&lt;br /&gt;
**[http://whoopie.gmxhome.de/linux/patches/2.6.17.14-tj/00-libata-tj-2.6.17.4-20060710.patch Patch against 2.6.17.14]&lt;br /&gt;
&lt;br /&gt;
* Confirmed to work on&lt;br /&gt;
**ThinkPad {{T43}}, {{T43p}}&lt;br /&gt;
**ThinkPad {{R52}}&lt;br /&gt;
&lt;br /&gt;
For 2.6.18 kernels, or older kernels that were patched to support &amp;lt;tt&amp;gt;ata_piix&amp;lt;/tt&amp;gt; hotplug (don't try it otherwise!), one can issue the following after inserting an UltraBay drive to rescan the port:&lt;br /&gt;
 {{cmdroot|echo 0 0 0 &amp;gt;  /sys/class/scsi_host/host1/scan}}&lt;br /&gt;
The inserted drive should now be recognized by the kernel, and appropriate {{path|/dev/*}} entries created automatically (e.g., by &amp;lt;tt&amp;gt;udev&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
You can safely shut down the drive by issuing the following (this works with all recent mainline kernels):&lt;br /&gt;
 {{cmdroot|echo 1 &amp;gt; /sys/class/scsi_device/1\:0\:0\:0/device/delete}}&lt;br /&gt;
 {{cmdroot|echo eject &amp;gt;  /proc/acpi/ibm/bay}}&lt;br /&gt;
The drive can now be ejected.&lt;br /&gt;
&lt;br /&gt;
===Scripts for hotswapping===&lt;br /&gt;
&lt;br /&gt;
The following scripts and [[acpid]] daemon configuration files do the following:&lt;br /&gt;
* 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.&lt;br /&gt;
* Rescans the UltraBay port when then UltraBay eject lever is pushed back in.&lt;br /&gt;
&lt;br /&gt;
They assumes you're using the &amp;lt;tt&amp;gt;ata_piix&amp;lt;/tt&amp;gt; driver with an appropriate kernel (see above).&lt;br /&gt;
&lt;br /&gt;
Create {{path|/usr/local/sbin/ultrabay_close}} with permissions 755:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
echo 12 &amp;gt; /proc/acpi/ibm/beep&lt;br /&gt;
sync&lt;br /&gt;
echo 0 0 0 &amp;gt; /sys/class/scsi_host/host1/scan&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create {{path|/usr/local/sbin/ultrabay_open}} with permissions 755:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ULTRABAY_SYSDIR='/sys/class/scsi_device/1:0:0:0/device'&lt;br /&gt;
shopt -s nullglob&lt;br /&gt;
&lt;br /&gt;
# Umount the filesystem(s) backed by the given major:minor device(s)&lt;br /&gt;
unmount_rdev() { perl - &amp;quot;$@&amp;quot; &amp;lt;&amp;lt;'EOPERL'  # let's do it in Perl&lt;br /&gt;
	for $major_minor (@ARGV) {&lt;br /&gt;
		$major_minor =~ m/^(\d+):(\d+)$/ or die;&lt;br /&gt;
		push(@tgt_rdevs, ($1&amp;lt;&amp;lt;8)|$2);&lt;br /&gt;
	}&lt;br /&gt;
        # Sort by reverse length of mount point, to unmount sub-directories first&lt;br /&gt;
        open MOUNTS,&amp;quot;&amp;lt;/proc/mounts&amp;quot; or die &amp;quot;$!&amp;quot;;&lt;br /&gt;
        @mounts=sort { length($b-&amp;gt;[1]) &amp;lt;=&amp;gt; length($a-&amp;gt;[1]) } map { [ split ] } &amp;lt;MOUNTS&amp;gt;;&lt;br /&gt;
        close MOUNTS;&lt;br /&gt;
        foreach $m (@mounts) {&lt;br /&gt;
                ($dev,$dir)=@$m;&lt;br /&gt;
		next unless -b $dev;  $rdev=(stat($dev))[6];&lt;br /&gt;
		next unless grep($_==$rdev, @tgt_rdevs);&lt;br /&gt;
		system(&amp;quot;umount&amp;quot;,&amp;quot;-v&amp;quot;,&amp;quot;$dir&amp;quot;)==0  or  $bad=1;&lt;br /&gt;
	}&lt;br /&gt;
	exit 1 if $bad;&lt;br /&gt;
EOPERL&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Get the UltraBay's /dev/foo block device node&lt;br /&gt;
ultrabay_dev_node() {&lt;br /&gt;
	UDEV_PATH=&amp;quot;`readlink -e &amp;quot;$ULTRABAY_SYSDIR/block:&amp;quot;*`&amp;quot; || return 1&lt;br /&gt;
	UDEV_NAME=&amp;quot;`udevinfo -q name -p $UDEV_PATH`&amp;quot; || return 1&lt;br /&gt;
	echo /dev/$UDEV_NAME&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [ -d $ULTRABAY_SYSDIR ]; then&lt;br /&gt;
	sync&lt;br /&gt;
	# Unmount filesystems backed by this device&lt;br /&gt;
	unmount_rdev `cat $ULTRABAY_SYSDIR/block\:*/dev     \&lt;br /&gt;
	                  $ULTRABAY_SYSDIR/block\:*/*/dev`  \&lt;br /&gt;
	|| {&lt;br /&gt;
		echo 10 &amp;gt; /proc/acpi/ibm/beep;  # error tone&lt;br /&gt;
		exit 1;&lt;br /&gt;
	}&lt;br /&gt;
        sync&lt;br /&gt;
        # Nicely power off the device&lt;br /&gt;
	DEVNODE=`ultrabay_dev_node` &amp;amp;&amp;amp; hdparm -Y $DEVNODE&lt;br /&gt;
        # Let HAL+KDE notice the unmount and let the disk spin down&lt;br /&gt;
	sleep 0.5&lt;br /&gt;
	# Unregister this SCSI device:&lt;br /&gt;
	sync&lt;br /&gt;
	echo 1 &amp;gt; $ULTRABAY_SYSDIR/delete&lt;br /&gt;
fi&lt;br /&gt;
sync&lt;br /&gt;
# Turn off power to the UltraBay:&lt;br /&gt;
if [ -d /sys/devices/platform/bay.0 ]; then&lt;br /&gt;
	echo 1 &amp;gt; /sys/devices/platform/bay.0/eject&lt;br /&gt;
else&lt;br /&gt;
	echo eject &amp;gt; /proc/acpi/ibm/bay&lt;br /&gt;
fi&lt;br /&gt;
# Tell the user we're OK&lt;br /&gt;
echo 12 &amp;gt; /proc/acpi/ibm/beep&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create {{path|/etc/acpi/events/ultrabay-close}}:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
event=(ibm/bay|bay) MSTR 00000001 00000000&lt;br /&gt;
action=/usr/local/sbin/ultrabay_close&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create {{path|/etc/acpi/events/ultrabay-open}}:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
event=(ibm/bay|bay) MSTR 00000003 00000000&lt;br /&gt;
action=/usr/local/sbin/ultrabay_open&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart &amp;lt;tt&amp;gt;acpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===HAL support===&lt;br /&gt;
&lt;br /&gt;
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 {{path|/etc/hal/fdi/information/10-ultrabay.fdi}} as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt; &amp;lt;!-- -*- SGML -*- --&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;deviceinfo version=&amp;quot;0.2&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;device&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;!-- UltraBay Devices --&amp;gt;&lt;br /&gt;
    &amp;lt;match key=&amp;quot;storage.bus&amp;quot; string=&amp;quot;scsi&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;match key=&amp;quot;storage.physical_device&amp;quot; string=&amp;quot;/org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;merge key=&amp;quot;storage.hotpluggable&amp;quot; type=&amp;quot;bool&amp;quot;&amp;gt;true&amp;lt;/merge&amp;gt;&lt;br /&gt;
      &amp;lt;/match&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/device&amp;gt;&lt;br /&gt;
&amp;lt;/deviceinfo&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Details====&lt;br /&gt;
&lt;br /&gt;
By default, HAL doesn't know that UltraBay devices are hotpluggable:&lt;br /&gt;
&lt;br /&gt;
 # PHYSDEV=/org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0&lt;br /&gt;
 # UDI=`hal-find-by-property --key storage.physical_device --string $PHYSDEV` || echo Failed&lt;br /&gt;
 # hal-get-property --udi $UDI --key block.device&lt;br /&gt;
 /dev/sdb&lt;br /&gt;
 # hal-get-property --udi $UDI --key storage.hotpluggable&lt;br /&gt;
 false&lt;br /&gt;
&lt;br /&gt;
After creating {{path|/etc/hal/fdi/information/10-ultrabay.fdi}} as above and re-plugging the device, it will get marked correctly:&lt;br /&gt;
&lt;br /&gt;
 # PHYSDEV=/org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0&lt;br /&gt;
 # UDI=`hal-find-by-property --key storage.physical_device --string $PHYSDEV` || echo Failed&lt;br /&gt;
 # hal-get-property --udi $UDI --key block.device&lt;br /&gt;
 /dev/sdb&lt;br /&gt;
 # hal-get-property --udi $UDI --key storage.hotpluggable&lt;br /&gt;
 true&lt;br /&gt;
&lt;br /&gt;
The string &amp;quot;8086_2653&amp;quot; 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 &amp;lt;tt&amp;gt;storage.physical_device&amp;lt;/tt&amp;gt; value by finding out the block device of the currently running UltraBay device (&amp;lt;tt&amp;gt;/dev/sdb&amp;lt;/tt&amp;gt; in the following example) and then running:&lt;br /&gt;
&lt;br /&gt;
 # DEVICE=/dev/sdb&lt;br /&gt;
 # UDI=`hal-find-by-property --key block.device --string $DEVICE` || echo Failed&lt;br /&gt;
 # hal-get-property --udi $UDI --key storage.physical_device&lt;br /&gt;
 /org/freedesktop/Hal/devices/pci_8086_2653_scsi_host_scsi_device_lun0&lt;br /&gt;
&lt;br /&gt;
If you have a different &amp;lt;tt&amp;gt;storage.physical_device&amp;lt;/tt&amp;gt; value, please report your findings.&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
|+ Known South Bridge PCI IDs&lt;br /&gt;
! ID !! ThinkPad model !! South Bridge chip&lt;br /&gt;
|-&lt;br /&gt;
| 8086_2653 || 2525FAG (X41) || Intel 82801FBM&lt;br /&gt;
|-&lt;br /&gt;
| 8086_24ca || 237358U (T40) || Intel 82801DBM (ICH4-M)&lt;br /&gt;
|-&lt;br /&gt;
| 8086_27c4 || X60           || Intel 82801GBM (ICH7 Family)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Other comments==&lt;br /&gt;
&lt;br /&gt;
If you are hot-swapping a hard disk on a disk tray, make sure the disk does not have a password set, otherwise it will not be recognized on reinsertion.&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripts]]&lt;/div&gt;</summary>
		<author><name>Max2k</name></author>
		
	</entry>
</feed>