Making the drive bootable

We are going to install the linux bootloader ‘syslinux’. This bootloader gets its menu from ‘syslinux/txt.cfg’. We will modify this file. Open ‘syslinux/txt.cfg’ from the USB drive with your favorite text editor. For instance:

cd /media/ubuntu/syslinux
gedit txt.cfg

The following edits need to be made:

  • Search and replace ‘/cdrom’ with nothing;
  • Copy the first ‘label’ section, paste it in before itself, and make the following edits to this new section:
    • The ‘label’ argument should be changed to something unique, here we use ‘persistent’;
    • The ‘menu label’ should be changed to describe the option; ‘^Use Ubuntu in persistent mode’ would seem suitable, with a caret before the “U” to make it a shortcut key for this option;
    • The word ‘persistent’ should be added into the ‘append’ line (this is the crucial point!);
  • Optionally, change the ‘default’ to the label name used above (e.g. ‘persistent’).

The following is an example of what you might end up with:

default persistent
label persistent
  menu label ^Use Ubuntu in persistent mode
  kernel /casper/vmlinuz
  append  file=/preseed/ubuntu.seed boot=casper persistent initrd=/casper/initrd.lz quiet splash --
label live
  menu label ^Try Ubuntu without installing
  kernel /casper/vmlinuz
  append  file=/preseed/ubuntu.seed boot=casper initrd=/casper/initrd.lz quiet splash --
label live-install
  menu label ^Install Ubuntu
  kernel /casper/vmlinuz
  append  file=/preseed/ubuntu.seed boot=casper only-ubiquity initrd=/casper/initrd.lz quiet splash --
label check
  menu label ^Check disc for defects
  kernel /casper/vmlinuz
  append  boot=casper integrity-check initrd=/casper/initrd.lz quiet splash --
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80

The menu choice called ‘persistent’ was made the default so that when booting up you can just hit ‘Enter’ to start your customized session.

Install bootloader

The last thing to do is install the bootloader. Make sure you have the ‘syslinux’ and ‘mtools’ packages installed. If not, open ‘synaptic’ and select them from the package list to mark them to be installed, then “apply” the changes.

Or use ‘aptitude’ or ‘apt-get’ from the command line. For example, the following command should be harmless if they are already installed.

sudo aptitude install syslinux mtools

First you need to unmount your usb stick using ‘disk utility’, or use ‘terminal’ to enter the following commands (replacing ‘sdX1’ with the appropriate partition name for the 750 MB ubuntu partition on your USB device):

cd ~
sudo umount /dev/sdX1

This command will install the bootloader on your drive:

syslinux /dev/sdX1
  • don’t know why, but i had to use the -f switch, (syslinux -f /dev/sdc1) – bernstein
    • same here – I had to use the -f switch – krishnan

    syslinux complained it couldn’t create LDLINUX.SYS, but it worked in the Windows version (see below) – JanSchlüter

    According to this page1 syslinux 3.35 should be used to get support for fat32, edgy ships with 3.11. According to the changelog 3.35 only seems to introduce support for subdirectories.

If you get the error:

sh: mcopy: command not found
syslinux: failed to create ldlinux.sys

then you will need to install the ‘mtools’ package.

Eject the drive:

eject /dev/sdX

Boot on the USB drive, change some settings, reboot again and check if the changes are kept (persistence check).

Do not forget to check if the computer you are going to use, boots USB devices first (look in BIOS settings).

So that is it. Enjoy (k)ubuntu where ever you go.

  • If you boot the drive and persistency works but when you log in to gnome you get a message saying that it couldn’t write to .ICEauthority, then a simple fix is deleting .ICEauthority. You can automate that by doing this:
      echo >> .bashrc
      echo "# This makes GNOME work" >> .bashrc
      echo "rm .ICEauthority 1>/dev/null 2>/dev/null" >> .bashrc

Those using Lucid (10.04) to make a pen drive to boot Precise (12.04) that is to say, using the previous LTS release to go to the next one, will need to be aware of this incompatibility between the syslinux versions involved:

https://bugs.launchpad.net/ubuntu/+source/syslinux/+bug/608382

there are a couple of work-arounds (eg, typing ‘help’ at the prompt and then hitting ‘enter’) but the bug has been triaged and labeled WONTFIX since Maverick and as late as March 2012.