IMPORTANT: If you decide to follow the steps below always make sure that you work on the right disk (i.e. external) to not wipe out the data from your internal drive. Also doing a backup of your internal disk is a good idea in case things don’t go as expected.
0. Prerequisites
- Ubuntu on Live USB stick with some presistent storage
- Small USB key which will be used for booting
- External hard drive connected though eSata
1. Ubuntu installation on external disk
This is done using Live USB. Go through the installation steps until you reach the screen about partitioning. Here I had to used the “advanced” option (the radio button at the very bottom) as none of the others seemed to be able to work with the external disk. Once you get to the next screen it should show partitions on the internal disk but also on the external disk. Let’s say my external disk is “/dev/sdb”.
Here I selected my external disk and created 2 primary partitions: swap - with 2x the size of RAM in my laptop, ext4 - using the remaining space and mounted to “/”.
Go to through the following screen(s) until you reach the summary with “Advanced” button. Hit this button and uncheck the box about updating the boot record - I didn’t want to do it as my BIOS does not support eSata booting anyway (otherwise I would specify it should boot from my external disk, i.e. /dev/sdb instead of /dev/sda).
Review the changes to make sure that any disk changes will only be done on the external drive. And then GO - Ubuntu should be installed in your external drive.
2. “kexec-loader” ISO preparation
While running Ubuntu from the Live USB key go to
http://www.solemnwarning.net/kexec-loader/download.cgi and download from there kexec-loader-2.2.1-cdrom.tar.gz and modules-2.6.30.5-1.tar.gz.
Unpack both of them. From the modules copy “sata.tlz” and “ext4.tlz” into “kexec-loader-2.2.1-cdrom/iso-modules” directory. Note that if you used another file system than “ext4” to install Ubuntu you should take the appropriate module for your installation.
In kexec-loader-2.2.1-cdrom run “mkiso.sh kexecloader.iso”. This will create ISO image that we will use for boot.
3. Bootable USB preparation
Plug the 2nd USB key that we will use for boot. With GParted format it to FAT32 and label the partition as KEXECLOADER. The label is important as “kexec-loader” during boot will look for a partition with that name to read its configuration file from there.
Get access to the files in the created ISO image using the following commands:
$ mkdir /mnt/kexecloadercd
$ mount -o loop path/to/iso /mnt/kexecloadercd
Download UNetBootin tool used to create bootable USB. If you run plain Ubuntu, it will complain about missing “p7zip-full”. I don’t know if this is really needed but I installed it following one of the “to do list after installing Ubuntu 10.04” posts.
Run UNetBootin. Select “Custom”. In “Kernel” open the one in /mnt/kexecloadercd/isolinux/vmlinuz. In “Initrd” open the one in /mnt/kexecloadercd/isolinux/initrd.img. In the USB dropdown make sure you select the one that we just formated above and that will be used for boot. In my case it was visible as “/dev/sdd” device. Hit OK.
If used as-is the UNetBootin USB stick will show a menu at start up. If you want to avoid that backup “syslinux.cfg” present there and replace it with one containing just this line:
default /ubnkern initrd=/ubninit
4. “kexec-loader.conf” configuration file
The final step is to tell kexec-loader about the external disk Ubuntu is installed on.
In the root directory of the USB boot disk create file called “kexec-loader.conf” with the following content:
timeout 5
title Lucid Lynx on eSata
root sdb3
kernel /vmlinuz
cmdline root=/dev/sdb3
initrd /initrd.img
... and replace “sdb3” with the device name for the partition of your external disk where Ubuntu is installed.
Alternatively, you can use UUID instead of “sdbN”. To get UUID execute in terminal “ls -l /dev/disk/by-uuid” and then in “kexec-loader.conf” file use:
...
root UUID=<your uuid>
...
cmdline root=UUID=<your uuid>
...
(“=” is present twice in cmdline)
Note that “kexec-loader” has a shell that you can use for troubleshooting. Its commands are documented at
http://www.solemnwarning.net/kexec-loader/readme.html in “Shell” and “Shell Reference” sections.
5. BIOS boot order
If you want to automatically boot from your USB key when it’s plugged in you’ll need to change the boot order in BIOS and put the USB hard drive above internal hard drive.