WARNING: I use some very powerful (ie potentially destructive) tools as root. Please be careful! You have been warned!
While I'm at it, you're playing in the Big Leagues now, sort out your own root privileges.
This is actually a generic guide to preparing a Persistent USB stick of Linux on any computer capable of booting from a USB drive. These instructions are solely for Linux users (we are creating the bootable usb using Linux tools on an existing Linux desktop). Windows or OSX users should install linux and then follow this tutorial.
We will be using OzOS as our example - but the basic steps will apply to any distro that has a live iso image available. In fact, there are several ways to make a bootable usb drive for live/installation images. You might want to try Google for other methods.
The method covered here is based largely on DebianLive Custom Install
Please note: If you are new to Linux or are not comfortable using the command line, tough, get over it, this is linux after all, and I use the command line. However the management at OzOs suggest some pictures of bunnies, a good (legal) calmative or perhaps a long bath with a few drops of lavender oil, if need be before you proceed.
Do note that this is a method to use if you are looking to create a "persistent" usb distro - ie one that can save changes to settings or installed packages.
Overview
We are going to make our persistent usb stick by doing the following steps:
0. Get Started - the materials needed, sort out which distro iso image to use and partition the usb stick.
1. Create a bootloader on the usb stick.
2. Copy the entire contents of an iso file to the usb stick.
3. Edit the bootloader and set "master boot record" to the usb stick.
4. Set up a Home Directory for the Data Partition.
5. Test things out.
We'll be doing most of this from the command line.
0 - GET STARTED
First you need to get a stock Live ISO, I used an OzOs LiveCD. Next you need a partition tool, I used gparted, you can use what ever you want. If you do not know how to partition something, Aubrey's
How To: Prepare a bootable OzOS USB stick for installation has some nice screen shots and explanations on using gparted. You also need a usb stick, make sure is at least a Gig in size.
Now boot to yur linux os and plug in yur usb stick. Do not mount it. If you have that auto-mount crap, unmount the usb stick.
Next set up some partitions. Set them up thus;
First Partition as FAT32 (mine is 3 gigs)
Second Partition, as ext3 (mine is 3.75 gigs) also add the label casper-rw. This is KEY. If the LiveCD you are using uses live instead of casper use "live-rw" as the label.
Third Partition, as ext3 (mine is 713 MB)
1 - ADD GRUB
Install the GRUB boot manager.
Now mount the 3rd partition,.copy & set yur linux grub to it. Now say it with me, as root from console type:
mkdir /tmp/livdcd
mount /dev/sdX3 /tmp/livecd
cp -R /boot/grub/* /tmp/livecd/
echo '(hd1) /dev/sdX' > /tmp/livecd/boot/grub/device.map
grub-install --root-directory=/tmp/livecd --no-floppy '(hd1)'
mind the sdx#
2 - INSTALLING THE FILE SYSTEM
You need to copy the system files from the ISO image you downloaded beforehand. To do this you need to mount the iso.
mkdir /tmp/iso
mount -o loop _name_of_the_iso_you_downloaded.iso_ /tmp/iso
Copy the ISO's file system to yur usb stick.
cp -a /tmp/iso/* /tmp/livecd/
3 - EDIT BOOT OPTIONS
Edit yur usb's /boot/grub/menu.lst file with the information from yur Live image's /syslinux/menu.cfg file.
At a minimun you should have;
title Live OzOs
kernel /casper/vmlinuz boot=live persistent
initrd /casper/initrd.img
boot
* - make sure to use the correct kernel location either
"live" or "casper"
You should also make an entry without "persistent" on the kernel line for booting a strictly "Live" session.
Now remove the Live file systems boot stuff.
rm -Rf /tmp/livecd/isolinux
4 - HOME DIRECTORY FOR DATA PARTITION
Now make the first partition ( the one that is fat32 & for sharing files with other Operating Systems ) be automatically mounted under live user's HOME directory every time the gui is started. This can be done with the following script, which is then added to the autostart section.
#!/bin/bash
# shared-disc.sh
# partition /home
PART=`mount | grep /home | awk '{print $1}' | sed 's/2/1/'`
[ -z "$PART" ] && exit 1
[ -d "$HOME/Documents" ] || mkdir $HOME/Documents
sudo mount $PART $HOME/Documents \
-o rw,noexec,nosuid,nodev,noatime,uid=999,utf8,shortname=lower
The following part of Section 4 - HOME DIRECTORY FOR DATA PARTITION has not been fully tested.
Make this file wherever you want, make it executable, and copy it to the appropriate place in the /tmp/livecd/ for auto-startup.
5 - NOW TEST IT OUT
Copy something to the usb stick's data partition.
mkdir /tmp/data
mount /dev/sdX1 /tmp/data
cp
mind the sdx#
Reboot yur computer.
Check the BIOS & if need be set it to boot from yur USB first.
Boot the Live option, use the one with "persistent".
Start the X-Window, if you've no Display Manager.
Check to see if
Change a few things as well as add an application or two.
Reboot. If everything is still there, it worked.
Credit goes to Aubrey, whom I openly plagiarized some stuff from.
Teague MacRoot

