Script for Quickly Docking/Undocking a Thinkpad Ultrabay HDD
Thinkpads are pretty awesome. They're durable, support Linux really well, and are easy to fix and extend. For developers, they also feature good screens and great keyboards (yes, even the new keyboards are well above anything else on the market). I got a used T420 off ebay in the summer of 2013 and it's my main development machine to this day. I swapped out the hard drive with an SSD drive and threw in 4 gigs of extra ram for a total o 8gigs. This set up allows me to take care of all my professional development needs, although I've been eyeing the new T460s for their improved screens, slimmer cases, and better power management.
One thing that's been sort of a pain is that I've been making due with a 250gb Crucial drive (amazing power stats btw). It's about enough for development, but I've got a bunch of things that could use some sort of expanded storage - whether it's virtual machines that I don't use often, dumping a few gigabytes of pictures from my phone, or archiving old projects. Something a bit more handy than an external hard drive.
Behold, the ultrabay! What could be easier than to swap out the pretty useless DVD drive for an extra hard drive? I did just that - I got a pretty cheap ultrabay knockoff off ebay and fitted it out with the original 320gb 2.5" that came with the T420. Everything was good until, by listening to the sounds the machine made, I figured that the drive is constantly powered on.
This is bad due to two things:
- Uses up battery power when not needed.
- You don't know whether the drive head is parked, makes me very uneasy about using it on a bus or plane in fear of damaging the drive.
Like many small projects, this languished in TODO hell for over a year before I got around to it a few days ago. I researched the web and I glued together some modified scripts to take care of this problem. The result is a simple script that can unmount and power off the drive, power it on again, and finally power if off and undock it.
This way I can pretty quickly power everything down when I want to conserve power or when I want to make sure the drive is safe to bump around and power it back on when I need it. The core functionality of the script comes from the thinkpad wiki and everything else are snippets of code that I found somewhere else or modified myself.
The usage is pretty straightforward:
Usage: ultrabay.sh [-d|-u|-e|-h] -d - rescan scsi hosts, will power up the ultrabay. -u - unmount, put disk to sleep, then remove it from the scsi list. -e - eject: basically do -u but also power off the dock. Disk has to be re-inserted to get it up again. -h - help
To make it more convenient, I symlinked it to the
sudo ln -s /home/matt/ultrabayman.sh /usr/local/bin/ultrabayman
Once I have the disk in the dock, all I do is either
sudo ultrabayman -d if I want to access it and
sudo ultrabayman -u if I want to power it off. When I wanna take it out, I use
sudo ultrabayman -e - this essentially does
-u but also tells the docking subsystem that the dock is undocked. I don't know if this is required, but it was in the original script and I kept it.
Finally, here's the link to the script itself: https://github.com/sirMackk/dotfiles/blob/master/ultrabayman.sh