place to discuss Linux
Installing Ubuntu on a USB Pen Drive
Being able to run Linux straight out of a USB drive is a great way to enjoy the liveCD experience, letting you run Linux from any computer you want. And it saves you from the trouble of carrying a CD along all the time, with your USB drive easily tucked away in your pocket.

Here’s a simple tutorial that shows you how to install Ubuntu on a USB drive. Even though this tutorial uses Ubuntu as its base distribution, you can virtually use any type of Linux liveCD distribution.
What you need
In order to be able to execute this simple tutorial, you will need:
- Ubuntu liveCD
- USB drive of at least 1 GB capacity
- Running Linux operating system.
Step 1: Finding the device
First of all, plug in your USB drive and check which device it is associated under. To find out that out, run:
$ sudo fdisk –l
On my system, the device appears as being /dev/sdb; therefore, we’ll be using /dev/sdb as a reference for this tutorial. Please make the replacement according to your system (for example, sda, sdc, etc)
Once the device has been located, the next step is creating the partitions.
Using the wrong device name might be fatal to your system partitions, so make sure you double check.
Step 2: Creating the partitions
Before you continue, make sure that you un-mount ALL your mounted partitions. To do so, run:
$sudo umount /dev/sdb1
Now launch fdisk, a tool to edit partition under Linux.
$sudo fdisk /dev/sdb
What we are going to do now is delete all the partitions, and then create 2 new partitions: one FAT partition of 750 MB to host the files from the liveCD iso, and the other for the rest of the files.
At fdisk prompt, type d x, where x denotes the partition number (you can simply type d if you have only one partition).
Then:
- n to create a new partition
- p to make it primary
- 1 so that it is the first primary partition
Accept the default or type 1 to start from the first cylinder
- +750M to make it 750 Meg big
- a to toggle the partition active for boot
- 1 to choose the 1 partition
- 6 to set it to FAT16
Our first partition is now set up. Let’s move onto the next one:
- n to create a new partition
- p to make it primary
- 2 to be the second partition
- Accept the default by hitting Enter
- Accept the default to make your partition as big as possible
- Finally, type w to write the change to your USB drive
- Partition creation process is now complete. The next step is formatting them.
Step 3: Formatting the partitions
We are going to format the first partition as a FAT file system of size 16 and we are then going to attribute it the label “liveusb”.
$ sudo mkfs.vfat -F 16 -n liveusb /dev/sdb1
The second partition is going to be of type ext2, with a blocksize of 4096 bytes and the label casper-rw. Make sure that the label is casper-rw; otherwise the tutorial will not work.
$ sudo mkfs.ext2 -b 4096 -L casper-rw /dev/sdb2
And now, our USB drive is ready to host the liveCD image. The next step is copying the files to the USB stick.
Step 4: Mounting Ubuntu liveCD image
First off, we need to mount our Ubuntu iso. Depending on you having the .iso file or the CD, there are two different ways of doing it.
Mounting from the CD:
People using Ubuntu or any other user-friendly distribution might just have to stick the CD in, and it will be mounted automatically. If that doesn’t happen, the following command should mount it:
$ sudo mount /media/cdrom
Mounting from an .iso image file:
You will have to create a temporary directory, for example let’s use /tmp/ubuntu-livecd, and then mount your iso. (We will be using a feisty fawn iso).
$ mkdir /tmp/ubuntu-livecd
$ sudo mount -o loop /path/to/feisty-desktop-i386.iso /tmp/ubuntu-livecd
Once the CD image is ready, it is time to mount the newly created USB stick partitions.
Step 5: Mounting the USB stick partitions
Like we experienced with mounting the Ubuntu liveCD image directly from the CD, you might be able to get both partitions by simply re-plugging the USB drive. Partitions might appear as /media/liveusb and /media/casper-rw. If that doesn’t happen, you will have to mount them manually:
$ mkdir /tmp/liveusb
$ sudo mount /dev/sdb1 /tmp/liveusb
All the partitions we need are now mounted. Now lets move on to the next step.
Step 6: Copying the files to the USB stick
Access the CD image directory (/tmp/ubuntu-livecd in my case, but it might be /media/cdrom) and copy at the root of your USB first partition:
Directories: “casper”, “disctree”, “dists”, “install”, “pics”, “pool”, “preseed”, “.disk”
The content of Directory “isolinux”
and files “md5sum.txt”, “README.diskdefines”, “ubuntu.ico”
as well as files: “casper/vmlinuz”, “casper/initrd.gz” and “install/mt86plus”
$ cd /tmp/ubuntu-livecd
$ sudo cp -rf casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines ubuntu.ico casper/vmlinuz casper/initrd.gz install/mt86plus /tmp/liveusb/
Ignore any complaints your screen shows about symbolic links not being able to create.
Now let’s go to the first partition of your USB drive and rename isolinux.cfg to syslinux.cfg
$ cd /tmp/liveusb
$ sudo mv isolinux.cfg syslinux.cfg
Change /tmp/liveusb according to your settings.
Edit syslinux.cfg so that it looks like this:
DEFAULT persistent
GFXBOOT bootlogo
GFXBOOT-BACKGROUND 0xB6875A
APPEND file=preseed/ubuntu.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash –
LABEL persistent
menu label ^Start Ubuntu in persistent mode
kernel vmlinuz
append file=preseed/ubuntu.seed boot=casper persistent initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash –
LABEL live
menu label ^Start or install Ubuntu
kernel vmlinuz
append file=preseed/ubuntu.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash –
LABEL xforcevesa
menu label Start Ubuntu in safe ^graphics mode
kernel vmlinuz
append file=preseed/ubuntu.seed boot=casper xforcevesa initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash –
LABEL check
menu label ^Check CD for defects
kernel vmlinuz
append boot=casper integrity-check initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash –
LABEL memtest
menu label ^Memory test
kernel mt86plus
append -
LABEL hd
menu label ^Boot from first hard disk
localboot 0×80
append -
DISPLAY isolinux.txt
TIMEOUT 300
PROMPT 1
F1 f1.txt
F2 f2.txt
F3 f3.txt
F4 f4.txt
F5 f5.txt
F6 f6.txt
F7 f7.txt
F8 f8.txt
F9 f9.txt
F0 f10.txt
Finally, we have our USB drive almost usable. Which brings us to our final step.
Step: 6: Making the USB stick bootable
In order to do this, we need to install syslinux and mtools:
$ sudo apt-get install syslinux mtools
And finally, unmount /dev/sdb1 and make it bootable:
$ cd
$ sudo umount /tmp/liveusb$ sudo syslinux -f /dev/sdb1
There you are!
Reboot, set your BIOS to boot from the USB drive and enjoy Ubuntu Linux from a flash drive.
Troubleshooting
If you run into trouble booting on the USB stick, this could be due to your MBR being corrupted. In order to fix this, you can use lilo.
$ lilo -M /dev/sdb
This should fix the MBR on device /dev/sdb.
| Print article | This entry was posted by Ashik on April 5, 2009 at 1:47 pm, and is filed under Ubuntu. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |




about 1 year ago
Always good to see the manual way of doing it, so that its easy to tweak it, but it would be worth mentioning
unetbootin – a general purpose iso to usb tool (intrepid users can use the jaunty package)
and usb-creator – a Ubuntu USB desktop image creator
Both these methods use casper-rw file in a -o loop mount so no need to split the disk.
about 1 year ago
When I try to create the partitions using fdisk the step where you enter a 6 to set it to FAT16 does not work. Should I put all four steps on one line or should this work one step at a time? fdisk on 8.04 does not seem to work as shown here.
about 1 year ago
I found that you left out a step in setting up a FAT16. Just before you enter a 6 you first need to enter a t for file partition type