Warning: for Linux geeks and my notes only. Not general interest!
I experienced an especially painful Ubuntu upgrade over the weekend, made worse by the installer refusing to read packages from a CD. I suspect that whatever driver the installer employs to read from the CD doesn’t like my CD-DVD drive, as the CD disc itself was just fine. Anyway, I then spent a long afternoon figuring out how to boot and install from a USB stick. Here’s how.
1. Prepare the USB stick
This assumes that you have a working machine on which to mount the stick. All operations should be run as su or sudo.
- Plug it in and determine the device either by typing “mount” or looking at “tail /var/log/syslog”. The device is pretty likely to be “/dev/sda”.
- Run fdisk: “fdisk /dev/sda”.
- Type “p” to see existing partitions. Type “d” and select partition numbers until all existing partitions are gone.
- Type “n” to create a new partition. Accept the defaults (“enter” twice for one partition on the whole stick).
- Type “t” for the partition type and “6” for FAT16.
- Type “a” to toggle the flag of the partition to bootable.
- Type “w” to write the partition and exit.
- Now create the FAT16 filesystem using “mkdosfs /dev/sda1”.
- “sudo apt-get install mbr” if you don’t have it
- Add a master boot record to the stick: “install-mbr /dev/sda”.
You should now have a bootable stick with a single FAT16 partition (/dev/sda1).
2. Add GRUB bootloader to the stick
Mount the stick again. We’re assuming that the mount point is /media/usbdisk.
- Create /boot/grub on the stick: “mkdir -p /media/usbdisk/boot/grub”.
- Copy over grub files: “cp /lib/grub/i386-pc/* /media/usbdisk/boot/grub/”.
- Create grub device map: ‘echo “(hd0) /dev/sda” > /media/usbdisk/boot/grub/device.map’.
- Install grub to the stick: “grub-install ––root-directory=/media/usbdisk /dev/sda”.
Now use an editor (e.g. nano) to open /media/usbdisk/boot/grub/menu.lst and add these lines:
title Ubuntu root (hd0,0) kernel /vmlinuz root=/dev/rd/0 /init=/linuxrc rw initrd /initrd.gz boot
You can also add a “ramdisk_size=” parameter to the kernel line. These lines tell grub which files to use when booting. We don’t have these files yet, so…
3. Copy required files to stick
- Head over to http://archive.ubuntu.com/ubuntu/dists/dapper/main/installer-i386/current/images/hd-media/ (or the appropriate directory for your distro and architecture).
- Grab the files “boot.img.gz”, “vmlinuz”, “initrd.gz” and copy to the root directory of the stick.
- Finally, get yourself any Ubuntu ISO image. If your stick is 1 GB or larger, the normal installer images (something like ubuntu-6.06-alternate-i386.iso) will fit just fine.
4. Boot and install
You’re ready to go. You might have to enter the BIOS to make sure that your machine can boot from a USB device and change the boot order. My BIOS has a “USB-HDD” option which works for sticks – this is quite common, but there are variations.
In theory the machine will now boot from your stick, GRUB will start up, find the kernel and ramdisk images, locate the ISO and the installer will run as it would from a CD. These instructions derived in large part from Rene Mayrhofer.