Page 1 of 1

Ultrabay use with an advanced dock (T61).

Posted: Mon Apr 08, 2013 8:38 am
by newyorkpaulie
Can drives in the ultrabay drive slot in the advanced dock be safely removed/inserted while the machine is running? I was not able to do this with my T30 so I'm hesitant to try this without first checking here.

Re: Ultrabay use with an advanced dock (T61).

Posted: Mon Apr 08, 2013 2:26 pm
by Cigarguy
A T61, being PATA at the Ultrabay interface, hot swapping is a no no. It's OK to do this on most SATA interface but I would not recommend it on PATA.

Re: Ultrabay use with an advanced dock (T61).

Posted: Mon Apr 08, 2013 3:15 pm
by newyorkpaulie
Cigarguy wrote:A T61, being PATA at the Ultrabay interface, hot swapping is a no no. It's OK to do this on most SATA interface but I would not recommend it on PATA.
But my ultrabay devices take SATA drives. Does that mean it's OK to swap?

Re: Ultrabay use with an advanced dock (T61).

Posted: Mon Apr 08, 2013 3:20 pm
by Cigarguy
Yes the Ultrabay adapter takes SATA drives, but the Ultrabay adapter hooks up to the computer via a PATA to SATA adapter. So natively it is a PATA connection. You can try it for youself. Take it out with the machine on. Your T61 will whine at you and will not recognize any device in there until you restart.

Re: Ultrabay use with an advanced dock (T61).

Posted: Mon Apr 08, 2013 5:49 pm
by newyorkpaulie
Cigarguy wrote:Yes the Ultrabay adapter takes SATA drives, but the Ultrabay adapter hooks up to the computer via a PATA to SATA adapter. So natively it is a PATA connection. You can try it for youself. Take it out with the machine on. Your T61 will whine at you and will not recognize any device in there until you restart.
Well I didn't get the whine, but you're right about its not seeing the swapped drive. Thanks.

Re: Ultrabay use with an advanced dock (T61).

Posted: Tue Apr 09, 2013 1:00 pm
by jcvjcvjcvjcv
I can remove and insert the optical drive of my T61 as often as I like and it will always get recognized without reboot. Can't speak for the HDD in Ultrabay adapters though. Only have one optical drive and one ultrabay battery.

Re: Ultrabay use with an advanced dock (T61).

Posted: Tue Apr 09, 2013 2:25 pm
by dr_st
I'm also curious as to why it would be problematic via the dock, when it works without issues with the ultrabay on the laptop itself (which is also PATA).

Maybe the problem is with hard drives? I only really tried it with opticals/floppies.

Re: Ultrabay use with an advanced dock (T61).

Posted: Tue Apr 09, 2013 8:25 pm
by Cigarguy
I use 3 Ultrabay adapter with a HDD in my T61s. The few times that I disconnect and reconnect the Ultrabay adapter it did not like it and would not recognize it until I reset the system. Sounds like it varies depending on device. Best way to know is to try it on your machine and see what happens.

Re: Ultrabay use with an advanced dock (T61).

Posted: Tue Apr 09, 2013 10:37 pm
by 91011
If Windows doesn’t detect the Ultrabay HDD when it’s reinserted you can use the Rescan button in Device Manager to reinstall the drive – saves rebooting.

Re: Ultrabay use with an advanced dock (T61).

Posted: Wed Apr 10, 2013 4:57 am
by newyorkpaulie
91011 wrote:If Windows doesn’t detect the Ultrabay HDD when it’s reinserted you can use the Rescan button in Device Manager to reinstall the drive – saves rebooting.
Do you know of a way to duplicate this with Linux? (not a Windows fan)

Re: Ultrabay use with an advanced dock (T61).

Posted: Wed Apr 10, 2013 5:52 am
by rumbero
newyorkpaulie wrote:Do you know of a way to duplicate this with Linux? (not a Windows fan)
See thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices for details and also thinkwiki.org/wiki/Talk:How_to_hotswap_Ultrabay_devices for further discussion about that topic.

I actually had the ultrabay_eject script from this site working in Debian on various T61's and actually could hotswap HDD's this way.
With most recent kernels (3.7 and 3.8, maybe even 3.6) this doesn't appear to be working for me anymore, even after having updated the DEVPATH to the recenty changed value, as explained in the script's comment section.
Still investigating what is failing here.

Re: Ultrabay use with an advanced dock (T61).

Posted: Wed Apr 10, 2013 8:36 am
by aoitenshi
I always do hot-swapping on my ultrabay when my T61 is running ...
Well I guess because I activate the AHCI mode ...

tested on my T61, when I put 7200 rpm HDD or SSD inside the ultrabay (with 2504 dock ) ...
works fine on winXP x86 and Win7 x64

I just select "eject" and then the pop-up message show up, telling me that it's now safe to remove the hardware (the ultrabay) ... and I can insert the optical drive back, and the system will recognized the optical drive ..

[SOLVED] Re: Ultrabay use with an advanced dock (T61).

Posted: Wed Apr 10, 2013 3:44 pm
by newyorkpaulie
aoitenshi wrote:I always do hot-swapping on my ultrabay when my T61 is running ...
Well I guess because I activate the AHCI mode ...

tested on my T61, when I put 7200 rpm HDD or SSD inside the ultrabay (with 2504 dock ) ...
works fine on winXP x86 and Win7 x64

I just select "eject" and then the pop-up message show up, telling me that it's now safe to remove the hardware (the ultrabay) ... and I can insert the optical drive back, and the system will recognized the optical drive ..
The answer then is to first "unmount" (Linux) or "safely remove" (Windows) the drive in the docking station's Ultrabay slot. Since I did not (really) have to do this with the bay in the PC itself I had the wrong idea that this step wasn't necessary when swapping out Ultrabays in the Dock.

Re: Ultrabay use with an advanced dock (T61).

Posted: Fri Apr 12, 2013 11:08 pm
by rumbero
Investigation complete, and here is my solution for Debian Linux on a T61, based on the information and scripts found in the aforementioned Thinkwiki resource at thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Script_for_Ultrabay_eject:

Save as "/etc/udev/rules.d/50-thinkpad-ultrabay.rules":

Code: Select all

# Change the DEVPATH variable to match your system, if it doesn't match your ThinkPad model
# The DEVPATH value used here should hopefully be working out of the box on any T6x ThinkPad.
# To find the correct value for your ThinkPad, insert the UltraBay optical drive and execute:
# udevadm info --query=path --name=/dev/sr0 | perl -pe 's!/block/...$!!'

SUBSYSTEMS=="block", DEVPATH=="/devices/pci0000:00/0000:00:1f.1/ata4/host3/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"
ENV{EVENT}=="undock", KERNEL=="dock.1", ACTION=="change", SUBSYSTEM=="platform", RUN+="/usr/local/sbin/ultrabay_eject"
ENV{EVENT}=="dock", KERNEL=="dock.1", ACTION=="change", SUBSYSTEM=="platform", RUN+="/usr/local/sbin/ultrabay_insert"
Save as "/usr/local/sbin/ultrabay_eject":

Code: Select all

#!/bin/bash
#set -x

# Sources:
# http://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Script_for_Ultrabay_eject
# http://www.thinkwiki.org/wiki/Talk:How_to_hotswap_Ultrabay_devices

SCRIPTNAME="$(basename $0)"

# Change the DEVPATH variable to match your system, if it doesn't match your ThinkPad model
# The DEVPATH value used here should hopefully be working out of the box on any T6x ThinkPad.
# To find the correct value for your ThinkPad, insert the UltraBay optical drive and execute:
# udevadm info --query=path --name=/dev/sr0 | perl -pe 's!/block/...$!!'

if [ "$DEVPATH" = "" ]
then
   DEVPATH="/devices/pci0000:00/0000:00:1f.1/ata4/host3/target3:0:0/3:0:0:0"
fi

shopt -s nullglob
export DISPLAY=:0.0 # required for notify-send

DISP0_USER=$(who | grep "tty" | awk '{ print $1 }')
DISP0_USER_HOME=`getent passwd ${DISP0_USER} | cut -d':' -f6`
export XAUTHORITY=${DISP0_USER_HOME}/.Xauthority # also required for notify-send

ULTRABAY_SYSDIR=/sys$DEVPATH

# Find generic dock interface for UltraBay
dock=$(dirname $(/bin/grep -l ata_bay /sys/devices/platform/dock.?/type))

if [ ! -n "$dock" -a -d "$dock" ]; then
        logger "$SCRIPTNAME": cannot locate bay dock device
        notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" "Cannot locate bay dock device"
        exit 1
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 "$SCRIPTNAME": dock reports empty
else 
    if [ -d $ULTRABAY_SYSDIR ]; then
	logger "$SCRIPTNAME": 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 "$SCRIPTNAME": umounting failed
		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 "$SCRIPTNAME": bay occupied but incorrect device path $DEVPATH
	notify-send -u critical -t 100000 "ThinkPad Ultrabay eject failed" "Bay occupied but incorrect device path"
	exit 1
    fi
fi

# We need to sleep here to wait for the bay and the drive to disconnect
sleep 1

# Undocking the UltraBay:
logger "$SCRIPTNAME": undocking $dock
if [ "$(cat $dock/docked)" != "0" ]; then
    echo 1 > $dock/undock
else
    # Tell the user we're OK once done
    logger "$SCRIPTNAME": successfully completed
    notify-send -u normal -t 10000 "Safe to remove device" "The ThinkPad Ultrabay device can now be safely removed"
    exit 0
fi
Save as "/usr/local/sbin/ultrabay_insert":

Code: Select all

#!/bin/bash
#set -x

# Source:
# http://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Script_for_Ultrabay_eject
# http://www.thinkwiki.org/wiki/Talk:How_to_hotswap_Ultrabay_devices

SCRIPTNAME="$(basename $0)"

export DISPLAY=:0.0 # required for notify-send
DISP0_USER=$(who | grep "tty" | awk '{ print $1 }')
DISP0_USER_HOME=`getent passwd ${DISP0_USER} | cut -d':' -f6`
export XAUTHORITY=${DISP0_USER_HOME}/.Xauthority # also required for notify-send

# Change the DEVPATH variable to match your system, if it doesn't match your ThinkPad model
# The DEVPATH value used here should hopefully be working out of the box on any T6x ThinkPad.
# To find the correct value for your ThinkPad, insert the UltraBay optical drive and execute:
# udevadm info --query=path --name=/dev/sr0 | perl -pe 's!/block/...$!!'

if [ "$DEVPATH" = "" ]
then
   DEVPATH="/devices/pci0000:00/0000:00:1f.1/ata4/host3/target3:0:0/3:0:0:0"
fi

ULTRABAY_SYSDIR=/sys$DEVPATH

# 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
}

DOCKDEVICE=$(lsscsi | grep $(ultrabay_dev_node) | tr -s " ")

# Find generic dock interface for UltraBay
dock=$(dirname $(/bin/grep -l ata_bay /sys/devices/platform/dock.?/type))

if [ ! -n "$dock" -a -d "$dock" ]; then
    logger "$SCRIPTNAME": cannot locate bay dock device
    notify-send -u critical -t 100000 "ThinkPad Ultrabay device docking failed" "Cannot locate bay dock device"
    exit 1
fi

# Tell the user we're OK once done

if [ "$(cat $dock/docked)" = "1" ]; then
    sync
    logger "$SCRIPTNAME": Scanning ThinkPad Ultrabay for new device
    echo 0 0 0 > /sys/class/scsi_host/host3/scan
    logger "$SCRIPTNAME": Docking of ThinkPad Ultrabay device successfully completed.
    notify-send -u normal -t 10000 "Docking ThinkPad Ultrabay device completed" "The ThinkPad Ultrabay device is now available for use."
    exit 0
else
    logger "$SCRIPTNAME": ThinkPad Ultrabay device docking failed
    notify-send -u normal -t 10000 "Docking ThinkPad Ultrabay device failed" "Docking the ThinkPad Ultrabay device failed. Please check what went wrong and fix it."
    exit 1
fi
Should (hopefully) work out of the box on at least a T61. Works for me so far. Please try it out and correct my silly errors.

Hope this helps, so enjoy!

EDIT: For those who can read German, an article about this topic is now available at the German language Thinkwiki at thinkwiki.de/Linux_UltraBay_Hotswap.

Re: Ultrabay use with an advanced dock (T61).

Posted: Sun Apr 14, 2013 2:55 am
by TuuS
Some great work there, it will be an asset to the community :)

Re: Ultrabay use with an advanced dock (T61).

Posted: Tue Jan 13, 2015 10:39 am
by ericvb69
Cigarguy wrote:A T61, being PATA at the Ultrabay interface, hot swapping is a no no. It's OK to do this on most SATA interface but I would not recommend it on PATA.
Well he isn't asking about swapping the ultrabay in his T61, rather hotswapping the ultrabay drive in the dock bay.

I own a T60 running linux, I can hotswap the ultrabay disk adapter in the laptop bay (it works as PATA though) and if I plug the disk adapter in the advanced dock, it it detected as USB Mass Storage device:

Code: Select all

[681428.942731] usb 1-6.1: Product: CY4611B V2.50RC16
[681428.942736] usb 1-6.1: Manufacturer: IBM
[681428.942742] usb 1-6.1: SerialNumber: 00000A517286
[681428.943307] usb-storage 1-6.1:1.0: USB Mass Storage device detected
[681428.949697] scsi16 : usb-storage 1-6.1:1.0

Re: Ultrabay use with an advanced dock (T61).

Posted: Tue Jan 13, 2015 12:49 pm
by dr_st
ericvb69 wrote:
Cigarguy wrote:if I plug the disk adapter in the advanced dock, it it detected as USB Mass Storage device:
Really! So the Ultrabay in the dock is connected via USB? :o