Difference between revisions of "ThinkPad X6 UltraBase"

From ThinkWiki
Jump to: navigation, search
(UltraBay Slim)
m (Add Docking Solutions category.)
(35 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{| cellspacing="0" cellpadding="2" border="0"
+
{| cellspacing="0" cellpadding="2" border="0"  
 
| style="vertical-align:top;" | __TOC__
 
| style="vertical-align:top;" | __TOC__
[[image:UltraBaseX6.gif|UltraBase X6]]
+
| style="vertical-align:top;" | [[image:UltraBaseX6.gif|UltraBase X6]]
| style="vertical-align:top;" | <div style="margin: 0; margin-right:10px; border: 1px solid #dfdfdf; padding: 0em 1em 1em 1em; background-color:#F8F8FF; align:right;">
+
|}
== Lenovo UltraBase X6 ==
+
 
The IBM UltraBase X6 is a portable dock for the 6-series ThinkPads providing extra ports as well as a bay for an optical drive and a set of stereo speakers. Containing a full featured [[Ultrabay|Ultrabay Slim]] slot, it provides flexibility in drive choice as well as the option of a secondary battery for extended working time on the road.
+
== ThinkPad X6 UltraBase ==
 +
The ThinkPad X6 UltraBase is a portable dock for the 6-series ThinkPads providing extra ports as well as a bay for an optical drive and a set of stereo speakers. Containing a full featured [[Ultrabay|Ultrabay Slim]] slot, it provides flexibility in drive choice as well as the option of a secondary battery for extended working time on the road.
 +
 
 +
It is not to be confused with the [[ThinkPad X6 Tablet UltraBase]].
  
 
=== Features ===
 
=== Features ===
Line 14: Line 17:
 
** Headphone
 
** Headphone
 
* Additional ports:
 
* Additional ports:
** four USB ports (two on left side, two on back)
+
** Four USB ports (two on left side, two on the back side)
 
** [[Serial Port|Serial (DB9-M)]]
 
** [[Serial Port|Serial (DB9-M)]]
 
** [[Parallel Port|Parallel (DB25-F)]]
 
** [[Parallel Port|Parallel (DB25-F)]]
* Ultrabay Slim
+
* [[Ultrabay Slim]]
 
* Stereo speakers
 
* Stereo speakers
 
* Kensington security hole
 
* Kensington security hole
Line 23: Line 26:
 
===Pros & Cons===
 
===Pros & Cons===
 
* Positives: Expansion capability, portable
 
* Positives: Expansion capability, portable
* Negatives: makes the ThinkPad quite thick
+
* Negatives: Makes the ThinkPad quite thick
 
* Compatibility: {{X60}}, {{X60s}}, {{X61}}, {{X61s}}
 
* Compatibility: {{X60}}, {{X60s}}, {{X61}}, {{X61s}}
* Warranty: Three Years
+
* Warranty: 3 years
</div>
 
|}
 
  
 
==Ultrabay Slim==
 
==Ultrabay Slim==
 
The Ultrabay Slim slot in this dock is full featured; it supports hot swapping with all Ultrabay Slim drives, including the following which have been tested by contributors to this site:
 
The Ultrabay Slim slot in this dock is full featured; it supports hot swapping with all Ultrabay Slim drives, including the following which have been tested by contributors to this site:
* [[UltraBay Slim DVD Multi-Burner III]]
+
* [[Ultrabay Slim Multi-Burner III Drive]]
 
 
  
You can also feed it with the UltraBay Slim battery pack to extend the overall battery life time.
+
You can also feed it with the [[Advanced Ultrabay Battery]] to extend the overall battery life time. Be aware, the [[Ultrabay Slim Battery]] won't work because the power connectors were slightly displaced; don't try to push them in by force, they won't work!
  
== UltraBase X6 under Linux (older style) ==
+
== X6 UltraBase under Linux (older style) ==
The docking stations are (at least in openSUSE) supported by the [http://en.opensuse.org/Dockutils Dockutils] project. The dockutils are formed by a set of simple bash scripts that handle docking and undocking of the computer. When the user chooses to undock the laptop, it does some system calls and when properly configured, it could disconnect the DVD drive in UltraBase or internal display resolution.
+
The docking stations are (at least in openSUSE) supported by the [http://en.opensuse.org/Dockutils Dockutils] project. The dockutils are formed by a set of simple bash scripts that handle docking and undocking of the computer. When the user chooses to undock the laptop, it does some system calls and when properly configured, it could disconnect the optical drive in the Ultrabay or update the display resolution.
  
Overally, the UltraBase works pretty same way as under Windows (it only has more configuration possibilites), the user only needs to press key on the dock to undock the PC. Docking is handled automatically.
+
Overally, the UltraBase works pretty much the same way as under Windows, only it has more configuration possibilities. The user only needs to press the key on the dock to undock the PC. Docking is handled automatically.
  
The following code has been tested on {{OpenSUSE}} 10.3 (Linux 2.6.22) with ThinkPad X61 but should work on all dockable ThinkPads with recent kernel and the required software installed.
+
The following code has been tested on {{OpenSUSE}} 10.3 (Linux 2.6.22) with ThinkPad X61 but should work on all dockable ThinkPads with a recent kernel and the required software installed.
  
 
=== Dockutils hook ===
 
=== Dockutils hook ===
In order to have the docking handled automatically, we need to create a hook in Dockutils directory({{path|/usr/lib/dockutils}}). We will put our hook in {{path|hooks/thinkpad/}} directory.
+
In order to have the docking handled automatically, we need to create a hook in the Dockutils directory ({{path|/usr/lib/dockutils/}}). We will put our hook in the {{path|hooks/thinkpad}} subdirectory.
  
 
{{cmdroot|cat /usr/lib/dockutils/hooks/thinkpad/70x61}}
 
{{cmdroot|cat /usr/lib/dockutils/hooks/thinkpad/70x61}}
Line 75: Line 75:
  
 
=== ACPI event handlers ===
 
=== ACPI event handlers ===
You can always run the Dockutils using {{cmdroot|docker dock}} or {{cmdroot|docker undock}} command, but this is not comfortable. We will use the ACPI subsystem to bind {{key|Fn}}{{key|F8}}, {{key|Fn}}{{key|F9}} keys and blue button on the docking station to the Dockutils. This could be performed using the following code:
+
You can always run the Dockutils using {{cmdroot|docker dock}} or {{cmdroot|docker undock}} command, but this is not comfortable. We will use the ACPI subsystem to bind {{key|Fn}}{{key|F8}}, {{key|Fn}}{{key|F9}} keys, and the blue button on the docking station to the Dockutils. This could be performed using the following code:
  
 
{{cmdroot|cat /etc/acpi/events/dock}}
 
{{cmdroot|cat /etc/acpi/events/dock}}
Line 88: Line 88:
 
{{NOTE|[[Thinkpad-acpi|thinkpad_acpi]] and <code>acpid</code> must be installed and running for this to work}}
 
{{NOTE|[[Thinkpad-acpi|thinkpad_acpi]] and <code>acpid</code> must be installed and running for this to work}}
  
== UltraBase X6 under Linux (newer style) ==
+
== X6 UltraBase under Linux (newer style) ==
Since in recent distributions (like openSUSE 11.1), there is no generated ACPI event for undocking the notebook (Alt+F9 still works the same), you need to use udev in order to be able detect the undocking event. You can use the same ACPI hook as in the "older style" docking setting but you need to put this code into your udev rules:
+
 
 +
=== Setup Ultrabay Hotswap for any distribution ===
 +
 
 +
Setup a script "ultrabay_eject" in /usr/local/sbin:
 +
 
 +
{{cmdroot|cat /etc/udev/rules.d/50-thinkpad-ultrabay.rules}}
 +
<pre>
 +
#!/bin/bash
 +
 
 +
# Change the following DEVPATH= to match your system, if you want to run this directly instead of having it called by the udev eject script
 +
# To find the right value, insert the UltraBay optical drive and run:
 +
# udevadm info --query=path --name=/dev/sr0 | perl -pe 's!/block/...$!!'
 +
if [ "$DEVPATH" = "" ]
 +
then
 +
#  DEVPATH="/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0"
 +
  DEVPATH="/devices/pci0000:00/0000:00:1f.1/host0/target0:0:0/0:0:0:0"
 +
fi
 +
 
 +
shopt -s nullglob
 +
export DISPLAY=:0.0 # required for notify-send
 +
ULTRABAY_SYSDIR=/sys$DEVPATH
 +
 
 +
# Find generic dock interface for UltraBay
 +
dock=$( /bin/grep -l ata_bay /sys/devices/platform/dock.?/type )
 +
dock=${dock%%/type}
 +
if [ -n "$dock" -a -d "$dock" ]; then
 +
        logger ultrabay_eject starting eject of $dock
 +
else
 +
        logger ultrabay_eject cannot locate bay dock device
 +
        notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" "Cannot locate bay dock device"
 +
fi
 +
 
 +
# 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);
 +
        }
 +
        # Sort by reverse length of mount point, to unmount sub-directories first
 +
        open MOUNTS,"</proc/mounts" or die "$!";
 +
        @mounts=sort { length($b->[1]) <=> length($a->[1]) } map { [ split ] } <MOUNTS>;
 +
        close MOUNTS;
 +
        foreach $m (@mounts) {
 +
                ($dev,$dir)=@$m;
 +
                next unless -b $dev;  $rdev=(stat($dev))[6];
 +
                next unless grep($_==$rdev, @tgt_rdevs);
 +
                system("umount","-v","$dir")==0  or  $bad=1;
 +
                if ($bad == 1) {
 +
                        system("logger","ultrabay_eject","ERROR unmounting",$dev,$dir);
 +
                        system("notify-send -u critical -t 100000 \"Error unmounting $dir\" \"Unmounting of $dir on $dev failed!\"");
 +
                } else {
 +
                        system("logger","ultrabay_eject","unmounted",$dev,$dir);
 +
                        system("notify-send -u normal -t 5000 \"Unmounted $dir\"");
 +
                };
 +
        }
 +
        exit 1 if $bad;
 +
EOPERL
 +
}
 +
 
 +
# Get the UltraBay's /dev/foo block device node
 +
ultrabay_dev_node() {
 +
        UDEV_PATH="`readlink -e "$ULTRABAY_SYSDIR/block/"*`" || return 1
 +
        UDEV_NAME="`udevadm info --query=name --path=$UDEV_PATH`" || return 1
 +
        echo /dev/$UDEV_NAME
 +
}
 +
 
 +
if [ $( cat $dock/docked ) == 0 ]; then
 +
        logger ultrabay_eject dock reports empty
 +
else
 +
        if [ -d $ULTRABAY_SYSDIR ]; then
 +
                logger ultrabay_eject dock occupied, shutting down storage device $DEVPATH
 +
                sync
 +
                # Unmount filesystems backed by this device
 +
                ## This seems to be very inelegant and prone to failure
 +
                unmount_rdev `cat $ULTRABAY_SYSDIR/block/*/dev    \
 +
                                  $ULTRABAY_SYSDIR/block/*/*/dev`  \
 +
                || {
 +
                        logger ultrabay_eject umounting failed
 +
                        echo 2 > /proc/acpi/ibm/beep  # triple error tone
 +
                        notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" \
 +
"Please do not pull the device, doing so could cause file corruption and possibly hang the system. Unmounting of the filesystem on the ThinkPad Ultrabay device failed. Please put the eject leaver back in place, and try to unmount the filesystem manually. If this succeeds you can try the eject again"
 +
                        exit 1;
 +
                }
 +
                sync
 +
                # Nicely power off the device
 +
                DEVNODE=`ultrabay_dev_node` && hdparm -Y $DEVNODE
 +
                # Let HAL+KDE notice the unmount and let the disk spin down
 +
                sleep 0.5
 +
                # Unregister this SCSI device:
 +
                sync
 +
                echo 1 > $ULTRABAY_SYSDIR/delete
 +
        else
 +
                logger ultrabay_eject bay occupied but incorrect device path $DEVPATH
 +
                notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" "Bay occupied but incorrect device path"
 +
                echo 2 > /proc/acpi/ibm/beep  # triple error tone
 +
                exit 1
 +
        fi
 +
fi
 +
 
 +
# We need sleep here so someone can disconnect the bay and the drive
 +
sleep 1
 +
 
 +
# Turn off power to the UltraBay
 +
logger ultrabay_eject undocking $dock
 +
echo 1 > $dock/undock
 +
 
 +
# Tell the user we're OK
 +
logger ultrabay_eject done
 +
echo 12 > /proc/acpi/ibm/beep
 +
notify-send -u normal -t 10000 "Safe to remove device" "The ThinkPad Ultrabay device can now safely be removed"
 +
</pre>
 +
 
 +
Then set up and udev event that listens to the events from the ultrabay and runs the script:
 +
 
 +
{{cmdroot|cat /etc/udev/rules.d/50-thinkpad-ultrabay.rules}}
 +
<pre>
 +
ENV{BAY_EVENT}=="3", ACTION=="change", SUBSYSTEM=="scsi", RUN+="/usr/local/sbin/ultrabay_eject"
 +
</pre>
 +
 
 +
=== Fix for undocking while Laptop sleeps for any distribution ===
 +
 
 +
Then you just add the following file in /etc/pm/sleep.d/ - it just undocks the notebook before going to sleep. After resuming the acpi events will detect the ultrabay again so it will be "docked" automatically after resuming, but you can still just remove the X6* from the ultrabase while it is sleeping:
 +
 
 +
{{NOTE| It is not known how well this works when using the ultrabase on the go (without ac adapter attached) and running from an ultrabay battery! Any hint from an ultrabay battery owner about this is highly appreciated!}}
 +
 
 +
{{cmdroot|cat /etc/pm/sleep.d/99-x61-docking}}
 +
<pre>
 +
#!/bin/sh
 +
. "${PM_FUNCTIONS}"
 +
 
 +
case $1 in
 +
        hibernate|suspend)
 +
                echo 1 > /sys/devices/platform/dock.0/undock
 +
                ;;
 +
 
 +
        thaw|resume)
 +
                # should dock automatically
 +
                ;;
 +
 
 +
        *) exit $NA
 +
                ;;
 +
esac
 +
</pre>
 +
 
 +
=== Dockutils hooks ===
 +
 
 +
{{NOTE|There is a pretty annoying [http://bugzilla.novell.com/show_bug.cgi?id=434742 bug in openSUSE 11.1] , undocking while the laptop sleeps causes freeze or restart}}
 +
 
 +
Since in recent distributions (like openSuSE 11.1), there is no generated ACPI event for undocking the notebook (Alt+F9 still works the same), you need to use udev in order to be able detect the undocking event. You can use the same ACPI hook as in the "older style" docking setting but you need to put this code into your udev rules:
  
 
{{cmdroot|cat /etc/udev/rules.d/10-docking.rules}}
 
{{cmdroot|cat /etc/udev/rules.d/10-docking.rules}}
Line 95: Line 243:
 
ENV{EVENT}=="dock", KERNEL=="dock.0", SUBSYSTEM=="platform", RUN+="/usr/lib/dockutils/hooks/thinkpad/70x61 dock"</pre>
 
ENV{EVENT}=="dock", KERNEL=="dock.0", SUBSYSTEM=="platform", RUN+="/usr/lib/dockutils/hooks/thinkpad/70x61 dock"</pre>
 
After this change, the notebook will change it's resolution automatically after you remove it from the UltraBase.
 
After this change, the notebook will change it's resolution automatically after you remove it from the UltraBase.
 +
 +
[[Category:Docking Solutions]]

Revision as of 18:23, 24 March 2020

UltraBase X6

ThinkPad X6 UltraBase

The ThinkPad X6 UltraBase is a portable dock for the 6-series ThinkPads providing extra ports as well as a bay for an optical drive and a set of stereo speakers. Containing a full featured Ultrabay Slim slot, it provides flexibility in drive choice as well as the option of a secondary battery for extended working time on the road.

It is not to be confused with the ThinkPad X6 Tablet UltraBase.

Features

  • Passthrough ports:
    • Gigabit Ethernet (RJ45)
    • Modem (RJ11)
    • VGA
    • Microphone
    • Headphone
  • Additional ports:
  • Ultrabay Slim
  • Stereo speakers
  • Kensington security hole

Pros & Cons

  • Positives: Expansion capability, portable
  • Negatives: Makes the ThinkPad quite thick
  • Compatibility: X60, X60s, X61, X61s
  • Warranty: 3 years

Ultrabay Slim

The Ultrabay Slim slot in this dock is full featured; it supports hot swapping with all Ultrabay Slim drives, including the following which have been tested by contributors to this site:

You can also feed it with the Advanced Ultrabay Battery to extend the overall battery life time. Be aware, the Ultrabay Slim Battery won't work because the power connectors were slightly displaced; don't try to push them in by force, they won't work!

X6 UltraBase under Linux (older style)

The docking stations are (at least in openSUSE) supported by the Dockutils project. The dockutils are formed by a set of simple bash scripts that handle docking and undocking of the computer. When the user chooses to undock the laptop, it does some system calls and when properly configured, it could disconnect the optical drive in the Ultrabay or update the display resolution.

Overally, the UltraBase works pretty much the same way as under Windows, only it has more configuration possibilities. The user only needs to press the key on the dock to undock the PC. Docking is handled automatically.

The following code has been tested on OpenSUSE 10.3 (Linux 2.6.22) with ThinkPad X61 but should work on all dockable ThinkPads with a recent kernel and the required software installed.

Dockutils hook

In order to have the docking handled automatically, we need to create a hook in the Dockutils directory (/usr/lib/dockutils/). We will put our hook in the hooks/thinkpad subdirectory.

# cat /usr/lib/dockutils/hooks/thinkpad/70x61

#!/bin/bash
# dock/undock script for Thinkpad X61

export DISPLAY=:0

if [ "$1" = "dock" ]; then
        echo "X61 dock"
        # non-present dvd drive workaround, not required in newer distros
        /bin/rescan-scsi-bus.sh --hosts=1 --channels=0 --ids=0 --luns=0 --forceremove &

        # set external display resolution & dpi
        /usr/bin/xrandr --output VGA --auto
        /usr/bin/xrandr --screen 0 -s 1920x1200
        /usr/bin/xrandr --screen 0 --dpi 96x96

elif [ "$1" = "undock" ]; then
        echo "X61 undock"

        # turn external display off, internal on and set res
        /usr/bin/xrandr --screen 0 -s 1024x768
        /usr/bin/xrandr --output LVDS --auto
        /usr/bin/xrandr --output VGA --off
        /usr/bin/xrandr --screen 0 --dpi 96x96
fi
NOTE!
If you don't use external display, remove the /usr/bin/xrandr lines from the script

The # xhost +local:root command has to be in /etc/X11/xinit/xinitrc.d/<script name> to get xrandr working from the root account.

ACPI event handlers

You can always run the Dockutils using # docker dock or # docker undock command, but this is not comfortable. We will use the ACPI subsystem to bind FnF8, FnF9 keys, and the blue button on the docking station to the Dockutils. This could be performed using the following code:

# cat /etc/acpi/events/dock

event=(ibm/dock GDCK 00000000 00000003|ibm/hotkey HKEY 00000080 00001008)
action=/usr/sbin/docker dock

and

# cat /etc/acpi/events/undock

event=(ibm/dock GDCK 00000003 00000001|ibm/hotkey HKEY 00000080 00001009)
action=/usr/sbin/docker undock

Now, you should be able to undock your PC using the keyboard keys and the dock button.

NOTE!
thinkpad_acpi and acpid must be installed and running for this to work

X6 UltraBase under Linux (newer style)

Setup Ultrabay Hotswap for any distribution

Setup a script "ultrabay_eject" in /usr/local/sbin:

# cat /etc/udev/rules.d/50-thinkpad-ultrabay.rules

#!/bin/bash

# Change the following DEVPATH= to match your system, if you want to run this directly instead of having it called by the udev eject script
# To find the right value, insert the UltraBay optical drive and run:
# udevadm info --query=path --name=/dev/sr0 | perl -pe 's!/block/...$!!'
if [ "$DEVPATH" = "" ]
then
#   DEVPATH="/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0"
   DEVPATH="/devices/pci0000:00/0000:00:1f.1/host0/target0:0:0/0:0:0:0"
fi

shopt -s nullglob
export DISPLAY=:0.0 # required for notify-send
ULTRABAY_SYSDIR=/sys$DEVPATH

# Find generic dock interface for UltraBay
dock=$( /bin/grep -l ata_bay /sys/devices/platform/dock.?/type )
dock=${dock%%/type}
if [ -n "$dock" -a -d "$dock" ]; then
        logger ultrabay_eject starting eject of $dock
else
        logger ultrabay_eject cannot locate bay dock device
        notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" "Cannot locate bay dock device"
fi

# 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);
        }
        # Sort by reverse length of mount point, to unmount sub-directories first
        open MOUNTS,"</proc/mounts" or die "$!";
        @mounts=sort { length($b->[1]) <=> length($a->[1]) } map { [ split ] } <MOUNTS>;
        close MOUNTS;
        foreach $m (@mounts) {
                ($dev,$dir)=@$m;
                next unless -b $dev;  $rdev=(stat($dev))[6];
                next unless grep($_==$rdev, @tgt_rdevs);
                system("umount","-v","$dir")==0  or  $bad=1;
                if ($bad == 1) {
                        system("logger","ultrabay_eject","ERROR unmounting",$dev,$dir);
                        system("notify-send -u critical -t 100000 \"Error unmounting $dir\" \"Unmounting of $dir on $dev failed!\"");
                } else {
                        system("logger","ultrabay_eject","unmounted",$dev,$dir);
                        system("notify-send -u normal -t 5000 \"Unmounted $dir\"");
                };
        }
        exit 1 if $bad;
EOPERL
}

# Get the UltraBay's /dev/foo block device node
ultrabay_dev_node() {
        UDEV_PATH="`readlink -e "$ULTRABAY_SYSDIR/block/"*`" || return 1
        UDEV_NAME="`udevadm info --query=name --path=$UDEV_PATH`" || return 1
        echo /dev/$UDEV_NAME
}

if [ $( cat $dock/docked ) == 0 ]; then
        logger ultrabay_eject dock reports empty
else 
        if [ -d $ULTRABAY_SYSDIR ]; then
                logger ultrabay_eject dock occupied, shutting down storage device $DEVPATH
                sync
                # Unmount filesystems backed by this device
                ## This seems to be very inelegant and prone to failure
                unmount_rdev `cat $ULTRABAY_SYSDIR/block/*/dev     \
                                  $ULTRABAY_SYSDIR/block/*/*/dev`  \
                || {
                        logger ultrabay_eject umounting failed
                        echo 2 > /proc/acpi/ibm/beep  # triple error tone
                        notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" \
"Please do not pull the device, doing so could cause file corruption and possibly hang the system. Unmounting of the filesystem on the ThinkPad Ultrabay device failed. Please put the eject leaver back in place, and try to unmount the filesystem manually. If this succeeds you can try the eject again"
                        exit 1;
                }
                sync
                # Nicely power off the device
                DEVNODE=`ultrabay_dev_node` && hdparm -Y $DEVNODE
                # Let HAL+KDE notice the unmount and let the disk spin down
                sleep 0.5
                # Unregister this SCSI device:
                sync
                echo 1 > $ULTRABAY_SYSDIR/delete
        else
                logger ultrabay_eject bay occupied but incorrect device path $DEVPATH
                notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" "Bay occupied but incorrect device path"
                echo 2 > /proc/acpi/ibm/beep  # triple error tone
                exit 1
        fi
fi

# We need sleep here so someone can disconnect the bay and the drive
sleep 1

# Turn off power to the UltraBay
logger ultrabay_eject undocking $dock
echo 1 > $dock/undock

# Tell the user we're OK
logger ultrabay_eject done
echo 12 > /proc/acpi/ibm/beep
notify-send -u normal -t 10000 "Safe to remove device" "The ThinkPad Ultrabay device can now safely be removed"

Then set up and udev event that listens to the events from the ultrabay and runs the script:

# cat /etc/udev/rules.d/50-thinkpad-ultrabay.rules

ENV{BAY_EVENT}=="3", ACTION=="change", SUBSYSTEM=="scsi", RUN+="/usr/local/sbin/ultrabay_eject"

Fix for undocking while Laptop sleeps for any distribution

Then you just add the following file in /etc/pm/sleep.d/ - it just undocks the notebook before going to sleep. After resuming the acpi events will detect the ultrabay again so it will be "docked" automatically after resuming, but you can still just remove the X6* from the ultrabase while it is sleeping:

NOTE!
It is not known how well this works when using the ultrabase on the go (without ac adapter attached) and running from an ultrabay battery! Any hint from an ultrabay battery owner about this is highly appreciated!

# cat /etc/pm/sleep.d/99-x61-docking

#!/bin/sh
. "${PM_FUNCTIONS}"

case $1 in
        hibernate|suspend)
                echo 1 > /sys/devices/platform/dock.0/undock
                ;;

        thaw|resume)
                # should dock automatically
                ;;

        *) exit $NA
                ;;
esac

Dockutils hooks

NOTE!
{{{1}}}

Since in recent distributions (like openSuSE 11.1), there is no generated ACPI event for undocking the notebook (Alt+F9 still works the same), you need to use udev in order to be able detect the undocking event. You can use the same ACPI hook as in the "older style" docking setting but you need to put this code into your udev rules:

# cat /etc/udev/rules.d/10-docking.rules

ENV{EVENT}=="undock", KERNEL=="dock.0", SUBSYSTEM=="platform", RUN+="/usr/lib/dockutils/hooks/thinkpad/70x61 undock"
ENV{EVENT}=="dock", KERNEL=="dock.0", SUBSYSTEM=="platform", RUN+="/usr/lib/dockutils/hooks/thinkpad/70x61 dock"

After this change, the notebook will change it's resolution automatically after you remove it from the UltraBase.