[Howto] Linux to USB bootable device (external disk / thumb-drive / mem card).

Associate
Joined
10 Nov 2004
Posts
2,237
Location
Expat in Singapore
Hi,

As people probably know, I have been trying to do this and have come across a few issues and confusions. I have spent a number of hours pulling hair out, swearing and asking for divine intervention. I have now done it in two ways and thought I would give information here as there seem to be a lot of these questions.

There are two methods I have used and both have been verified working. I used a memory card but it should work just the same for a thumb drive or a USB hard drive. Make sure your machine can boot from USB devices in your Bios before trying this.

Both require a boot CD and as I installed Ubuntu 8.04.1 I will use that as the reference distro for this. The iso can be downloaded from the Ubuntu 8.04.1 release site and I found downloading via a torrent client to be much faster.

I prefer option 2. but both are valid.

1. - Pen Drive Linux

Pros;
Less space required.
Quicker to setup.
Easy boot configuration.
Many different Linux Distros documented.

Cons;
Limited space.
Small install.
Linux command line experience makes it easier (not essential).
More configuration required to utilise any spare space on USB device.
Not able to view / manage Linux file system unless booted into it.

The guide on the Pen Drive Linux site works if but is easier if you have some Linux experience as you need to run command line utils like fdisk to partition disks etc.

You will end up with a pseudo 'bootable CD' partition on your memory stick which is restricted in size (750MB) and then another partition with the remaining space. You can then play around with config scripts and mount the extra space on the file system of the Linux system during boot or just use it for a storage partition but I find this solution not suitable for myself.

The file system is essentially stored in a compressed file on the USB device making it hard to access when not booted into Linux. The persistent install is meant to save changes back to the file system file although with only 750MB available and a standard UbuntU 8 install coming in at around 2.5GB + updates it will be a severely cut down system. This makes it good for small thumb drives / memory sticks but then these are now pretty cheap for 4+ GB capacity. If you have a small +750MB thumb drive / memory card available and just want a basic Linux system on a stick then this is fairly quick to get setup and easy to use. Just follow the steps on the website and it should work fine. If you cannot boot then remember to try the lilo -M command to fix the MBR of the USB device. This fixed it for me.

2. - Ubuntu8 standard install on a USB device.

Pros;
Full (standard) install.
Mostly easy to setup (standard Ubuntu install via GUI)
Utilises most space in one partition unless told to do otherwise
Can access from any other system able to read the partition format (i.e. ext2 / ext3)
Should work with different Linux Distros.

Cons;
More space required (2.5 GB).
More difficult boot re-configuration required.
Linux command line experience makes it easier (not essential).
Takes much longer to install.
Can create a swap file on your USB device (default setting). If it is a memory card or thumb-drive then it can reduce it's lifespan.

Boot with the CD / DVD and follow the steps for an install until it asks you where to install to.
On the partitioning screen I found it easier to choose the 'Guided - use entire disk' partitioning and then select the USB drive (thumb drive / memory card etc). It should be quite easy to spot as the device sizes are listed. Note the device names (i.e. sda / hda etc) and the operating systems they have installed. This will make a later stage easier.

Continue along with the installer adding a login name and passwords etc until you get to step 7/7 (It is giving you a textbox displaying all the options chosen).

This step is important).........(I missed it a few times as a number of guides miss it out)
Choose the 'advanced' button. On the pop up window, change the boot loader location to the USB card / drive (the one you chose in the partitioning screen).

If you set this up correctly then the software that boots the Linux OS will go onto the USB device and will not affect the main computer at all. If you do not change this then it defaults to installing the boot loader on to your machines main drive which is not what we want.

Close this window and kick off the installation.

The OS will now be installed on your USB device and this can take quite a bit of time (even longer than a Windows XP install :eek:). My install took over 1 hour.

Once completed it will prompt you to reboot. While it shuts down it will umount (eject) the CD disc. Remove it.

Make sure the Bios is set to boot from a USB device when you reboot.

This is the stage I found hard to find details about. A non USB boot device setup does not require this (i.e. standard HDD install).

You should be presented with a Grub boot-up screen listing various options like ‘Ubuntu 8.04.1’, ‘Ubuntu 8.04.1 (recovery)’. If you choose one of these then do not be worried if you get an error message saying Grub cannot mount drive. This is a common issue with USB device installs.

You need to tell Grub that the disk devices have changed name. As you are now booting from the USB device (not the CD rom as before), the devices have changed name with the USB device becoming the first device.

Grub see's the drives as hd(x) where x is a number denoting the order it was found on booting. For the install the Grub config file listed the USB drive as hd1 (or higher) as it was not the first 'boot' drive. Now it has become hd0 as it is the boot drive but the config file entries still have it listed as hd1. All clear ??........ nope, well no matter, it is easy to fix.

Select the line in the Grub boot screen for the Ubuntu OS you wish to start (usually the top option if you have not manually changed the config file up to this point).

Press 'e' to edit and you will see a number of lines listed.
Select the line listing something like 'root (hd1,0)' and type 'e' to edit this line.
Change the hd1 to hd0 and hit [RETURN], [ESC] goes to the previous menu but doesn’t record the changes.
Don’t worry about the other entries yet and choose 'b' to boot.

To get a listing of devices with the boot files installed then you can run 'list /boot/grub/stage1' from the Grub command entry screen (IIRC it is 'c' for command entry).

You should now be able to boot into Ubuntu but you are not quite finished.

The changes you made on the Grub boot screen will not stick and so the config file with these details needs to be amended.

Open a terminal session (applications -> accessories -> terminal).
In the terminal session type 'cd /boot/grub'
Now type 'sudo chmod 777 menu.lst' to make the file writable or you will not be able to save it later.
Now open the file manager (places -> filesystem)
Navigate to /boot/grub and open the menu.lst file
Go to the bottom of the file and you will see entries like;

title Ubuntu 8.04.1
root (hd1,1)
kernel /boot/vmlinuz-2.4.22-1.2149.nptl ro
initrd /boot/initrd-2.4.22-1.2149.nptl.img

Change the hd(x) entries (hd1 in the above example) to hd0 for all the entries relating to the USB install, you can also change the titles to something more meaningful to you if you would like.

For the 'other OS' section usually at the bottom there are the entries for any Windows OS you may have on the other drives of your machine. Because the drive designations at bootup from the USB device are now different these need to be changed to hd1 rather than hd0. Changing the root to rootnoverify is also required.

So you need to change the entry which looks something like this;

title Microsoft Windows XP Pro
root (hd0,0)
savedefault
makeactive
chainloader +1

to;

title Microsoft Windows XP Pro
rootnoverify (hd1,0)
makeactive
chainloader +1

Save and close the file.
In the Terminal session type 'sudo chmod 644 menu.lst' to re-secure the file. Using sudo is not required but good practice.

You should now be able to boot from the USB device into Linux and whatever OS(s) were on the computer.

Removing the USB device should allow you to boot your computer exactly as before.

This is the method I now use and it works fine.

I will try to help people with questions about these installs, although the first is just following the Pen Drive Linux site instructions, if they are posted in this thread.

A reference in the F.A.Q. for this forum maybe good for people wanting to do this (seems to be quite a few) in order to cut down on the common questions.

RB
 
Last edited:
Back
Top Bottom