You are here: Home Linux and free software A better way to create a customized USB drive with Ubuntu Live on it

A better way to create a customized USB drive with Ubuntu Live on it

Got a thumb USB drive or an SD card, and you'd like to put Linux on it? Did the other HOWTOs fail you? This is the real deal, through and through. This trick also works out-of-the-box with Kubuntu and other Ubuntu variants as well. Moreover, you can adapt it with very few changes to any other live CD Linux distributions out there.

Note that these instructions have been superseded by the Portable Linux creator.  Visit that link to find out how to create your own live Linux distribution in minutes, and how to run memtest86+ or MS-DOS from your USB stick easily as well.

Many modern Linux distributions (Ubuntu included) provide a Live CD that you can download, burn and run directly without installing Linux on your computer.

But what if your computer doesn't have a working CD drive?  Or perhaps you'd like to carry your Linux around in your pocket?  Well, no problem.  Ubuntu and many other distributions can also boot and install themselves from an USB thumb drive or an SD card (henceforth, for simplicity's sake, "USB drive").  All you need is a drive that is 1GB or bigger.

Problem is, not everybody can use the famous liveusb program to create bootable live USB drives.  Some of us are using Fedora on our workstations.  Others  might actually want to run Knoppix or another live distribution, not Ubuntu.  Yet others might not like the way liveusb partitions the disk space in your USB drive, or might want extra functionality not provided by it.

So we'll cover those bases, using Ubuntu as the distribution (and tips for other distributions).

After following it:

  1. Your USB drive will allow you to boot Live Ubuntu Linux on any computer you plug it into.  Just reboot, select USB boot, and off you go.
  2. Any customizations or files you create or change within your Linux will be preserved even after rebooting the computer or using the USB drive in another machine.
  3. You will be able to use your USB drive to install your Linux system on your friends' computers, or (if you know how) even use it to recover Linux installations that don't boot correctly anymore.
  4. (With some extra steps) you will even be able to use the drive to boot Memtest+ (to test hardware) and many other legacy programs such as MS-DOS (for those pesky BIOS updates).
  5. You will have learned valuable Linux knowledge.
  6. Best thing is, only a small portion of your USB drive will be used for this tutorial, so you get to keep the rest to do what you normally do: save music, share movies, move files around, either in Windows or in Linux.

So here's what you need to do, explained step by step.  On each step, colored insets will show you example console commands you can run to accomplish the step; you're free to do each step in the way you feel the most comfortable, and referring to the commands as merely guidelines.

Creating the bootable USB drive

Get the utilities we'll be using in this tutorial

Install the following programs (that might not already be installed) on your computer:

  1. dosfstools
  2. cfdisk

Use your distribution's software installation tool do to this job.

Get Ubuntu (or your favorite Linux distribution)

What you need to do first is get Ubuntu.  You can use either a CD or an ISO CD image downloaded from the Internet.

If you have an ISO image ready, great.  Verify the image using the MD5 sums generally available on the place you downloaded it -- trust me, you don't want to burn a malfunctioning image on your USB drive, it happened to me and it's very frustrating.    If, conversely, you have a CD, extract an ISO image from it:

This and all subsequent examples assume that your distribution uses sudo to run administrative commands.  If your distribution does not use sudo, become an administrator with the command su, then ignore the sudo prefix in all examples that follow.

sudo dd if=/dev/cdrom of=/path/to/iso/image.iso

Adjust the path of the of= parameter to point to the directory where you want to save the ISO image.  For the rest of this tutorial, /path/to/iso/image.iso will represent the path to your ISO image.

Plug your USB drive in

Now plug your USB drive and ensure it is not mounted.  The system log (accessible by issuing the command dmesg) will tell you what the device file corresponding to the USB drive is (it is usually /dev/sdb or /dev/sdc).  For the purposes of this tutorial, we'll assume that the device file is named /dev/sdc.

Repartition your USB drive

Be very, very careful to specify the correct device to any partitioning tool -- a mistake can cost you all your data.  And don't forget to back up the files in your USB drive -- this procedure will destroy any files present on the drive.

What we'll do now is simple.  We'll create two partitions:

  1. The first partition will contain a regular Windows FAT32 filesystem where you can put whatever files you want, wherever you go.  It will also store whatever customizations you perform in your Linux installation.
  2. The second partition will hold the contents of your CD's ISO image.  It will be hidden from view.

So the real trick here is to get the second partition to be just a tiny bit larger than the ISO image (which is just under 700 MB in Ubuntu). We'll use cfdisk to do this job.

sudo cfdisk /dev/sdc

cfdisk is pretty easy to use: you select partitions by using the up/down arrows, and you select functions by using the left/right arrows plus the ENTER key.  Here's what you'll do:

  1. Delete any existing partitions.
  2. Create a new, primary partition.  Make it the entire size of your USB drive minus 730 MB or so.
  3. Create a new, primary partition, covering the 730 MB you left out.
  4. Make the first partition bootable.
  5. Change the type of the first partition to C (Windows FAT32).
  6. Write the new partition table.
  7. Quit the program.

After doing this, your USB drive will be divided in two partitions.  One partition will be visible on My Computer, and you'll be able to store files just fine.  The other one will contain the Linux live CD, and will be invisible.

If you did it right, you should see no errors and the partition table in your USB drive has been re-read.  If not (probably because you forgot to unmount any old partitions in the drive), unplug it, plug it again, and check that the device file name did not change.  As long as no partitions on your USB drive are mounted, you do not need to reboot or unplug your USB drive for the partition table to be re-read by Linux.

Linux automatically names partitions with the device file name and a number at the end, so /dev/sdc1 represents the first partition we created, and /dev/sdc2 represents the second, hidden one.

Verify that your USB drive does not have bad blocks

Before you commit to using the USB drive, you need to know whether the USB drive has sectors that have gone bad -- a common occurrence in USB drives.  If a bad block damages the area where the live CD image is stored, your USB drive may malfunction or cause you to lose data.

sudo badblocks /dev/sdc2

This command will tell you if your USB drive is not usable as a live USB drive.

Format the newly created partition for Windows to use

Now it's time to create a brand new, Windows file system on the recently created partition (the first one) in your USB drive.

sudo mkfs.vfat -F 32 -c /dev/sdc1
sudo dosfslabel /dev/sdc1 UBUNTULIVE

This creates the FAT32 file system and labels it UBUNTULIVE.  The formatting process will take some time because the command tries to detect bad sectors and mark them as unusable.

Mount the Windows partition

sudo mkdir -p /media/USBDRIVE
sudo mount /dev/sdc1 /media/USBDRIVE

This mounts your USB drive in the folder /media/USBDRIVE.  From now on, we'll assume that's where it's mounted.

Install GRUB on the Windows partition of your USB drive

GRUB is the GRand Unified Bootloader, and its job is to pick up from where the BIOS of your computer left off and continue loading the operating system.  We'll use GRUB to bootstrap Ubuntu.  The reason we use GRUB is because GRUB is much more resilient and easier to set up than other boot managers like Syslinux.

sudo grub-install --no-floppy --root-directory=/media/USBDRIVE /dev/sdc

This command installs GRUB on the /media/USBDRIVE directory where your USB drive is mounted -- more accurately, on a boot/grub subdirectory inside it.

Copy the kernel and initial RAM disk from the ISO image to your GRUB directory

Now we're going to copy two key files from your ISO image to the boot/grub directory in the Windows partition of your USB drive (not the one in the root of your Linux file system). GRUB needs to load these two files successfully; since apparently GRUB cannot "see" what's within an ISO image, we're simply going to copy these files from the ISO to the GRUB directory.

sudo mkdir -p /mnt/isoimage
sudo mount -o loop /path/to/iso/image.iso /mnt/isoimage
sudo cp /mnt/isoimage/casper/{vmlinuz,initrd.gz} /media/USBDRIVE/boot/
sudo umount /mnt/isoimage
sudo rmdir /mnt/isoimage

This example assumes your ISO image is Ubuntu or Kubuntu -- in those ISO images, the kernel and RAM disk are in the /casper directory within the disc.  You may adjust accordingly for the live distribution you're going to run.

Now you should have two new files in the GRUB directory, named vmlinuz and initrd.gz.

Create a persistent file system to store data and customizations

Now we're going to create a small file.  This file will contain a Linux file system which will be automatically used by Ubuntu and other similar distributions to store your data, configuration, updated and extra software you install on it.  This step is not required if you do not want your data and customizations be remembered after rebooting your computer.

dd if=/dev/zero of=/media/USBDRIVE/casper-rw bs=1M count=256
mkfs.ext3 -F /media/USBDRIVE/casper-rw

This example creates a file 256 MB large, named casper-rw, in the Windows partition of your USB drive.  Adjust the number 256 to make it bigger or smaller (try not to make it smaller, though -- 256 MB is pretty small).

Write the ISO image to the hidden partition

Now we need to make a byte-by-byte copy of your Ubuntu ISO image to the hidden partition (the second one we created on the step before this one).  For that, we can use the dd command:

sudo dd if=/path/to/iso/image.iso of=/dev/sdc2

Be very careful when running the dd command, and double-check the of= parameter before hitting ENTER.  One typo can cost you all of your data.

This will take a long time.  If everything went well, you will be returned to the prompt with a small message noting how many bytes were copied in total, but no error messages.

Create a nice GRUB boot menu

Because GRUB is so flexible, you can use any live CD distribution instead of Ubuntu on your USB drive.

Refer to your favorite distribution's documentation to find out where you may obtain the appropriate vmlinuz and initrd.gz files (usually in the ISO image of your favorite distribution) and what parameters to specify in the kernel line of the GRUB configuration file.

Once you've done that, you can create the GRUB boot menu that will let you select and boot Ubuntu when the computer boots up.  We're going to create a file named grub.conf within the /media/USBDRIVE/boot/grub directory we created earlier using grub-install.

sudo nano /media/USBDRIVE/boot/grub/grub.conf

That command will launch the nano text editor ready to edit the file.  Put the following contents inside that brand new file:

default         0
timeout         10

title           Ubuntu (Live)
root            (hd0,0)
kernel          /boot/vmlinuz boot=casper file=/preseed/ubuntu.seed persistent
initrd          /boot/initrd.gz

If you're using a Kubuntu image, you need to make a small tweak: instead of ubuntu.seed, type kubuntu.seed.  Other Ubuntu flavors may need similar tweaks.

Save the file and exit the text editor (if you're using nano, hit Ctrl+X, answer Yes to the answer to save the file, hit ENTER, and you're done).

Unmount the Windows partition of your USB drive

Once you're done with the file, you can safely unmount the partition containing those files.  Close any text editors, terminals or folder windows you might have open with the contents of the USB drive, then run:

sudo umount /media/USBDRIVE
sudo rmdir /media/USBDRIVE

That's it.  Now your USB drive has only one folder named boot inside it, with some pretty important files.  Don't touch them from now on, and don't use a disk defragmenter on your USB drive either.

Sync up, then unplug

sync writes any pending data to all the disk drives in your computer.  This guarantees that everything is safely stored on disk before unplugging any device.  Normally, when you click the Eject icon on your desktop, sync is run for you automatically.

Now that you've done all of these steps, run:

sync

Once sync returns you to the prompt, it's safe to unplug the USB drive.

Now you're done.

Using your USB drive

Starting up your Linux system

Wherever you go, all you have to do (in this order) is:

Some BIOSes let you press a key (usually F8) to give you a boot menu.  Using this boot menu, you can temporarily choose to boot from your USB drive without changing any BIOS configuration permanently.
  1. Plug your USB drive in.
  2. Reboot the computer.
  3. As soon as the computer starts up, repeatedly press DEL, F1, F2 or F10 until you get to the BIOS configuration menu.  The correct key is usually briefly flashed across the screen as soon as the computer powers up.
  4. On the BIOS configuration menu, locate the Boot order options (usually under a Boot or an Advanced options menu)
  5. Select as first boot device your USB drive.  Ssometimes you need to select Hard Disk, and within Hard Disk, your USB flash or thumb drive.  On other BIOSes, you might need to first select Hard Disk, then go to a separate submenu to select which hard disk.
  6. Save the changes and reboot.

That's it.  If you did it right, next time the computer boots, your USB drive will be used as a "hard disk", and your Live Linux will come to life right away.

Accessing your Windows partition from within your Linux system

If you want to access the files stored on your Windows partition on your Linux system:

  1. Add the following commands to the /etc/rc.local file (before the exit 0 line):
    /sbin/losetup /dev/loop2 /dev/disk/by-label/UBUNTULIVE
    mkdir -p /media/windows
    mount -t vfat -o umask=000,noatime /dev/loop2 /media/windows
    
  2. reboot

From this point on, you can simply browse to /media/windows to see your files.  The partition mounts automatically on boot.

Care and feeding of your USB drive

Upgrading your USB drive to the latest Linux

We've got, what, six months between Linux releases?  Well, you don't want to be caught running an old Linux distribution, do you?

Fortunately, upgrading is extremely easy.  All you have to do is:

  1. download the latest Linux release, then
  2. re-run the step named Write the ISO image to the hidden partition, then
  3. re-run the step named Copy the kernel and initial RAM disk from the ISO image to your GRUB directory, then

If you've already performed software installations or upgrades, you might want to remove them from your persistent casper-rw file, because they will overshadow files in your new Linux distribution.  To do that, mount the file (using the loopback driver) on an installed Linux system, then remove /var, /usr, /bin, /sbin and /lib from it.  Note that you will have to reinstall any third-party packages that do not ship with your new Linux distribution.

Periodic file system checks

The following tests you need to run as an administrator on a Linux computer every once in a while, or if you experience malfunctions while using your USB drive.  You can't run these tests while running the live distribution on the USB drive.

The first test checks whether the area where the live CD is stored has gone bad and is no longer usable:

badblocks /dev/sdc2

The second test checks and repairs bad sectors in the Windows partition where you store files and the persistent file system is located:

dosfsck -atv /dev/sdc1

The third test checks whether there is any corruption in the persistent file system itself (if you are using this feature):

mkdir -p /media/USBDRIVE
mount /dev/sdc1 /media/USBDRIVE
dosfsck -atv /media/USBDRIVE/casper-rw
umount /dev/sdc1
rmdir /media/USBDRIVE

Dealing with low disk space on your persistent file system

You might find that the 128 MB we assigned earlier for your persistent file system turn out to be too small.  You can fix this by making the file larger without deleting your customizations.

  1. Plug the USB drive in a computer that has Linux, but do not boot from it.  Mount the Windows partition on your USB drive.  Become an administrator to run the subsequent steps.
  2. Create an empty temporary file using the dd command:
    dd if=/dev/zero of=/tmp/tempfile bs=1M count=256
    This example command creates a 256 MB file.  That's a bit small, but it should suffice to install a few programs -- like multimedia codecs and VLC in case you want to roll around with an all-purpose multimedia machine.
  3. Now tack that file onto the end of your casper-rw persistent file  You can do that with the command:
    cat /tmp/tempfile >> /media/USBDRIVE/casper-rw
  4. Finally, enlarge the file system to encompass the added disk space:
    e2fsck -f /media/USBDRIVE/casper-rw
    resize2fs /media/USBDRIVE/casper-rw
  5. Now unmount your USB drive.
Document Actions
Filed under: , , , ,

Comments (31)

Klaus Bogotz Apr 13, 2009 11:34 PM
I followed your description and got stuck when I tried to boot the first time. Booting stopped with a GRUB-Shell. After some experiments I found out that your file /media/USBDRIVE/boot/grub/grub.conf should be named /media/USBDRIVE/boot/grub/menu.lst.
For me with Ubuntu 8.10 that worked at a glance.
Te molestaría si lo traduzco al Español y lo mejoro un poco?

Klaus
Senthilkumar Balakrishnan Aug 22, 2011 04:08 AM
I followed the instructions. I had the file initrd.lz. I updated the grub.conf accordingly. I configured the boot sequence in the BIOS configuration. When i reboot my laptop, Windows Xp is getting booted. I can see LED in the USB stick is blinking immediately after POST. But no luck. I even tried changing the name of grub.conf as commented by other members here. Please let me know if I could do anything else for this.

Thanks
buster Nov 05, 2011 04:49 PM
used mkfs.ext4
named it grub.cfg
used grub2 syntax
used initrd.lz

now working with ubuntu 11.10 :)
Blagoj Kangalov Apr 18, 2009 03:19 PM
I got stuck when I tried to boot. Booting stopped with a GRUB-Shell. Renaming /media/USBDRIVE/boot/grub/grub.conf to /media/USBDRIVE/boot/grub/menu.lst did not help. Any other help?
Houchy Jul 14, 2009 05:56 PM
Hi!

I followed this detailled tutorial, everything went fine with no error.
Then, when I boot on my USB stick, I get stuck after 10 seconds at :

(initramfs)

Then I can type help that is giving me a list of commands I can use but I have no idea what to do ...
Does anybody have any clue how to go through this?

Thanks in advance for your help.
Houchy
Eric Stearns Aug 27, 2009 09:20 PM
These instructions worked great. I had to do the same thing as Klaus, and change the name of grub.conf to menu.lst.
Jason Armstrong Jan 04, 2010 02:08 AM
In the latest version of Ubuntu, use initrd.lz instead of initrd.gz
Sami Olmari Jan 04, 2010 02:08 AM
I tried Karmic (Ubuntu 9.10) livecd, and mine "mother" system also runs Karmic, which has grub2... It hangs at boot, I have managed basically "convert" grub legacy config into grub2 format, but it hangs basically right after the one menuentry is selected... I think we should figure out how to boot the USB-stick with grub2 too, I can be the guineapig :) Sami
David Snyder Jan 04, 2010 02:08 AM
I followed the original instructions, recieved a GRUB shell on first boot and then changed to /media/USBDRIVE/boot/grub/menu.lst and everything worked fine. However, I received an error when it finally booted up and when I rebooted nwith the pendrive, it wouldn't load ubuntu at all and this time I wasn't at the Grub shell, just a random screen with all kinds of error messages. I'll try it again so I can get back to you on the specifics of the errors.
Roberto Uy Nov 30, 2010 01:40 PM
Tried it out with Lucid, since the current portable linux release (0.9.3) didn't work for me.
+ Klaus suggestion (grub.conf -> menu.lst)
+ Jason note (initrd.gz -> initrd.lz)

+ My suggestion: use ext4 as the filesystem for Lucid since the default initial ramdisk does not support mounting ext3
Hence, the step "Create a persistent file system to store data and customizations"
will be modified from mkfs.ext3 to mkfs.ext4 like so:

mkfs.ext4 -F /media/USBDRIVE/casper-rw

Great article, very helpful
Leon Schmechel Nov 30, 2010 01:40 PM
does this work with lucid lynx?
jahn brinkmann Nov 05, 2011 04:49 PM
I solved my problem with this little script of grub.conf and menu.lst for Grub Legacy and Grub2 when I was trying to make a bootable USB MoonOS e17 Kachana Version with my Xubuntu Karmic. It works for me, just give it a try.

GRUB LEGACY

default 0
timeout 5

title Distro
root (hd0,0)
kernel /boot/vmlinuz boot=casper file=/preseed/distro.seed persistent
initrd /boot/initrd.gz



GRUB 2

works perfect by creating the file /boot/grub/grub.cfg with following content


set default=0
set timeout=5
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Ubuntu" {
search --set -f /boot/vmlinuz
linux /boot/vmlinuz boot=casper file=/preseed/ubuntu.seed
initrd /boot/initrd.lz
}
### END /etc/grub.d/10_Linux ###
jahn brinkmann Nov 05, 2011 04:49 PM

Create the file /boot/grub/grub.cfg with the following content, then it should work!

set default=0
set timeout=5
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Ubuntu" {
search --set -f /boot/vmlinuz
linux /boot/vmlinuz boot=casper file=/preseed/ubuntu.seed
initrd /boot/initrd.lz
}
### END /etc/grub.d/10_Linux ###
Huib Piguillet Nov 30, 2010 01:40 PM
Still no one who knows how to setup the USB stick's bootmenu using grub 2?
suresh saragadam Nov 30, 2010 01:40 PM
Yet there should be a better way, Because only the linux iso image is hidden, but still the windows pendrive part of the Linux USB KEY contains the linux part.

PENDRIVE PARTITION + LINUX PARTITION completely separated is it possible?

Because if i use my LINUX USB KEY as a pendrive i may loose my files in Pendrive, If this is the case here.
Julio Irigoyen Nov 30, 2010 01:40 PM
I solved my problem with this little script of grub.conf and menu.lst for Grub Legacy and Grub2 when I was trying to make a bootable USB MoonOS e17 Kachana Version with my Xubuntu Karmic. It works for me, just give it a try.

GRUB LEGACY

default 0
timeout 5

title Distro
root (hd0,0)
kernel /boot/vmlinuz boot=casper file=/preseed/distro.seed persistent
initrd /boot/initrd.gz



GRUB 2

set default=0
set timeout=5
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Distro" {
search --set -f /boot/vmlinuz
linux /boot/vmlinuz boot=casper file=/preseed/distro.seed
initrd /boot/initrd.lz
}
### END /etc/grub.d/10_Linux ###
Littlebig1 Nov 30, 2010 01:40 PM
Hi, first of all many thanks for the tutorial ! Please can you explain if it is possible to have the whole installation only on one ext3 partition on the usb pendrive instead of having two partitions (one Fat32 and one ext3) like you explained ? and if possible, how to do it ? is there a problem with casper preventing the use of only 1 ext3 partition ? Does casper absolutely needs a fat32 partition to store the datas ? -- Thank you very much for answers :-)
I tried to put everything inside an ext3 partition, and though the boot goes ok, I can't get persistance working.
Ayn Belonio Nov 30, 2010 01:40 PM
Hi, I'm new to this. Just wondering...when frequently running the system from the USB, won't this wear out the USB?
Julio Irigoyen Nov 30, 2010 01:40 PM
I had the same problem with the Xubuntu 9.10 grub.cfg file and just solved it like this

set default=0
set timeout=5
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Xubuntu" {
search --set -f /boot/vmlinuz
linux /boot/vmlinuz boot=casper file=/preseed/xubuntu.seed
initrd /boot/initrd.lz
}
### END /etc/grub.d/10_Linux ###

This is the GRUB2 configuration for the grub.cfg file, 'ONLY WITH GRUB2'
I've also formated the sdc2 partition of the USB pendrive in fat16 (I don't know if that helped) and runned fine.
Also my USB appears in "Widow$" like 2 separated drives... Always wanted that, now i need to prove this with a Linux format in sdc2.

Klaus, te tardas mucho pasando esto al español.
Tim Jan 06, 2011 07:26 PM
Hi all,
I'm trying to apply this tutorial to BackBox, which is based on Ubuntu 10.04. However it keeps hanging at the grub shell after boot. I've changed initrd.gz to initrd.lz and renamed grub.conf to menu.lst.

What else do i need to do?

Thanks in advance,
jawatim
Tim Jan 30, 2011 02:52 AM
I've also made the casper filesystem ext4 as suggested earlier.
Hou Zhongfeng Aug 22, 2011 04:08 AM
I've got the same error. After I rename menu.lst back to grub.conf, it turns out to be right.
My PC : F13
grub : v0.97
iso file : ubuntu 11.04
Senthilkumar Balakrishnan Aug 22, 2011 04:08 AM
I followed the instructions. I had the file initrd.lz. I updated the grub.conf accordingly. I configured the boot sequence in the BIOS configuration. When i reboot my laptop, Windows Xp is getting booted. I can see LED in the USB stick is blinking immediately after POST. But no luck. I even tried changing the name of grub.conf as commented by other members here. Please let me know if I could do anything else for this.

Thanks
Senthilkumar Balakrishnan Aug 22, 2011 04:08 AM
Hi, I am a new bee in linux. I tried this (with the initrd.lz). I changed the boot sequence in the BIOS. While booting, I can see the LED in the USB blinking. But the computer boots up with Windows Xp.

Please let me know any commented. Thanks
buster Nov 05, 2011 04:49 PM
- persistent file system with mkfs.ext4 ... instead of ext3
- grub config file is named grub.cfg instead of grub.conf
- grub.cfg follows grub2 syntax insted of grub legacy syntax
- initrd has extension lz instead of gz

up and running

some error messages during boot up will need closer inspection .. anyway .. overall a good guidance, thx
Bro Nov 05, 2011 04:49 PM
Hi

I created a shell script with the necessary steps copied from this guide and changes from the comments. I've tested this on Ubuntu 11.04 x64, and creating using ISO of Ubuntu 11.04 and 11.10 beta works. Also the grub file created is for grub2.
Remember to adjust the variables 'device' and 'iso_file' for your system.

#!/bin/bash
device=sdb
iso_file=ubuntu-11.10-beta1-desktop-amd64+mac.iso
 
echo "Creating a bootable USB stick."
echo "ISO Image: $iso_file"
echo "Device: /dev/$device"
 
echo -n -e "\nAre you sure you want to continue? (y/n): "
read confirm
 
if [ "$confirm" != "y" ]; then
    echo "You have chosen to exit. Goodbye."
    exit 0
fi
 
echo -e "\nVerifying that your USB drive does not have bad blocks"
sudo badblocks "/dev/$device""2"
 
# Format as FAT32
echo -e "\nFormating /dev/$device""1 as FAT32"
sudo mkfs.vfat -F 32 -c "/dev/$device""1"
sudo dosfslabel /dev/$device1 UBUNTULIVE
 
echo -e "\nCreating dir /media/USBDRIVE and mounting $iso_file"
sudo mkdir -p /media/USBDRIVE
sudo mount "/dev/$device""1" /media/USBDRIVE
 
# Install GRUB on the FAT32 partition of your USB drive
echo -e "\nInstalling GRUB to /media/USBDRIVE on /dev/$device"
sudo grub-install --no-floppy --root-directory=/media/USBDRIVE /dev/$device
 
## Copy the kernel and initial RAM disk from the ISO image to your GRUB directory
echo -e "\nCreating directory /mnt/isoimage, mounting $iso_file and copying kernel and RAM disk to /media/USBDRIVE/boot/"
sudo mkdir -p /mnt/isoimage
sudo mount -o loop $iso_file /mnt/isoimage
sudo cp /mnt/isoimage/casper/{vmlinuz,initrd.lz} /media/USBDRIVE/boot/
sudo umount /mnt/isoimage
sudo rmdir /mnt/isoimage
 
# Create a persistent file system to store data and customizations
echo -e "\nCreate a persistent file system to store data and customizations"
sudo dd if=/dev/zero of=/media/USBDRIVE/casper-rw bs=1M count=256
sudo mkfs.ext3 -F /media/USBDRIVE/casper-rw
 
# Write the ISO image to the hidden partition
echo -e "\nWriting IOS image ($iso_file) to /dev/$device""2"
sudo dd if=$iso_file of="/dev/$device""2"
 
echo -e "\nCreating /media/USBDRIVE/boot/grub/grub.cfg"
 
cat <<EOF >>/tmp/grub.cfg
 
set default=0
set timeout=5
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Distro" {
search --set -f /boot/vmlinuz
linux /boot/vmlinuz boot=casper file=/preseed/distro.seed
initrd /boot/initrd.lz
}
### END /etc/grub.d/10_Linux ###
 
EOF
 
sudo cp /tmp/grub.cfg /media/USBDRIVE/boot/grub/grub.cfg
rm /tmp/grub.cfg
 
echo -e "\nFinished!"
Enrique Dargallo Dec 20, 2011 08:02 PM
Hi, this tutorial is great and with the comments it's easy to make a bootable usb.

However, I'm still confused because mine doesn't keep the changes, it's not persistent.

The casper-rw file within the Ubuntulive partition and boot file keeps appearing as an extra usb drive attached and I don't think that's a good sign.

From other tutorials I learn that to achieve persistance it is necessary to edit syslinux.cfg, but it doesn't exist in the ISO image so don't know what to do next.

The grub.cfg file is edited as jahn brinkmann Nov 05, 2011 03:49 PM says.
The casper-rw file ext4 with 2000Mb and the ISO is Ubuntu 10.04.3

As I said it boots and works, but my problem is with the persistence. Any tips will be well appreciated.

Thanks.
nicksw Apr 24, 2012 11:57 PM
Thanks everyone - following all the tips, I have a bootable USB stick -- but like gakon77, no persistence.

Did anyone figure out this last step?

Thanks
Sathish Dec 20, 2011 08:02 PM
Great Bro , It worked . I did with a Fedora lap . The success gives me boost to try it with other variants now . Thank You Anyway .
LCosta Dec 20, 2011 08:02 PM
buster Nov 05, 2011 03:49 PM
used mkfs.ext4
named it grub.cfg
used grub2 syntax
used initrd.lz

now working with ubuntu 11.10 :)
--------------------------
Could you, please, provide detail for the steps 1, 3, and 4 above? If you have the info in another link location, let us know how to get there if not via ftp or e-mail.

Thank you.
Jack van Lisdonk Apr 24, 2012 11:57 PM
Looks like this link to the portable linux project: http://rudd-o.com/new-projects/portablelinux from the ubuntu wiki is no longer active?