Booting USB hard drives

Q I have been reading about creating a USB bootable hard disk, and I was wondering if I can just do the same with an external hard drive? Also I understand that you can test ISO images using VirtualBox, but how do I convert an ISO image to VDI?

A It is possible to put a distro on a USB hard drive, but the procedure is different. Install the distro as normal, just as if it were an internal hard drive and let the installer put Grub on the drive, then tell the BIOS to boot from the USB hard drive and it should just work.

Unfortunately, life is rarely that simple and there are a couple of problems that can arise, caused by the installer thinking this is the second drive on your system. These can be avoided on a desktop system if you disconnect the internal hard drive(s) - with your computer powered off, of course - then the installer will see only one drive. If this is not an option, you have two potential problems to fix. You may find that the second drive is referred to as sdb in /etc/fstab, causing all mounts to fail when you boot from it. This is because BIOSes tend to put internal drives ahead of external USB ones, except when you boot from the external drive. So the USB drive was sdb when you booted from the CD to install and sda when you booted from the drive itself. This is easily fixed by editing /etc/fstab, either while booted from a live CD or in your normal desktop environment.

The other potential problem is that the installer may have tried to install your bootloader to the first drive. Watch out for any options during installation to specify where the bootloader goes, as some distro installers keep this well hidden. Specify sdb here and you should be fine, otherwise run grub-install after you've finished installing to make sure the disk is set up correctly:

sudo grub-install /dev/sdb

If the automatic installation of Grub doesn't work, it is easy enough to do manually. Assuming your USB disk is /dev/sdb and that the distro is installed on /dev/sdb1, you should run these commands:

sudo grub
root (hd1,0)
setup (hd1)
quit

The first line takes you into the Grub shell, and the next tells Grub where your distro and its Grub files are installed. Then it writes the bootloader to the disk's MBR and exits the Grub shell with the remaining commands. Remember that Grub numbers from zero, so hd1,0 refers to the second drive, first partition.

You don't need to convert an ISO image to a VDI file to use it in VirtualBox either - a VDI file is an image of a hard drive, whereas an ISO image contains the contents of a CD or DVD. Set up a CD-ROM drive in VirtualBox and set it to use your ISO image. When you boot the virtual machine, it will behave as though its CD/DVD drive contains the disc held in that ISO image.

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar