Prepare a bootable OzOS USB stick for installation
Aubrey's picture

This is actually a generic guide to preparing a bootable USB stick for the installation of Linux distros 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 will need to find another tutorial - like this one.

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 check out some of the other methods at sites such as Pendrive Linux or even investigate downloadable utilities like UNetbootin before you dive in.

The method covered here is based largely on the tutorial by mick8985 on the Ubuntu Forums and it is plagiarized here with his permission. Thanks Mick!

Do note that this is not the method to use if you are looking to create a "persistent" usb distro - ie one that can save changes to settings or installed packages. This is solely about the type of bootable usb drive you use to install a distro onto the hard drive of a computer (for example, one that does not have a CD/DVD drive). See here for a tutorial on creating a persistent bootable usb.

Overview

We are going to make our bootable usb stick by doing the following steps:

1. Prepare - we'll get our materials together and work out which distro iso image we need.

2. Create a bootable ext2 partition on our usb stick using gparted.

3. Copy the entire contents of an iso file on our hard disk to the new partition.

4. Add a bootloader and a "master boot record" to the usb partition and change the name of one configuration file.

We'll be doing most of this with readily available graphical tools but experienced Linux users will know that there are command line tools that can achieve the same result. Feel free to "drop to the cli" if you know what you are doing.

WARNING: We will be using some very powerful (ie potentially destructive) tools with root admin privileges. Please be careful!

Part 1: Prepare

Before you begin:

  • You should make sure that the "target" machine can in fact boot from a usb drive - check the bios settings to see if usb is an option in the boot order.
  • Check to ensure that the distro you going to put on the USB drive is compatible with the target machine. This advice is particularly relevant to whether you choose a 64bit or 32bit version of your chosen distro and also whether the build you select will actually run on the processor of the target machine. For example, if you are making the usb stick to boot on an Intel Atom processor, the iso image will need to contain Linux kernel 2.6.26 or later. Similarly, if the machine has a Power PC processor, you will need the iso image built for that processor.
  • Make sure you have the .iso image of the distro you want to put on the stick - download it or transfer it to your computer - you will not need an actual CD or DVD - this tutorial works with the iso image on your hard drive.
  • The USB stick you choose should be big enough to contain the iso image - 700Mb or larger is usual for "modern" Linux distros. You will be partitioning the usb device if you follow this "How-To", so any data on the stick will be erased. If, for any reason, you want the stick for other purposes, the image can be erased and overwritten but you can't get your original data back.
  • To complete this How-To you will need a couple of packages that may not be installed on your computer (gparted and syslinux). If you are online there's no problem but, if not, you will need to get them onto the machine you are using to prepare the usb stick.

    Part 2: Create and format a partition on the USB stick

    We will use gparted - the graphical partitioner. If it is not already installed on your machine, you can get it through your package manager (eg Synaptic), from the command line (eg apt-get) or from a website such as apt:foo (direct link to gparted on apt:foo)

    Using the command line in an Ubuntu-based distro you would open a terminal and type (or copy/paste):

    :~$ sudo apt-get install gparted

    once installed, plug your usb drive in and, in the terminal window, type:

    :~$ sudo gparted

    The most important thing with gparted is to work on the correct device. By default it will probably have your main hard drive in the main window. DO NOT WORK ON THAT DRIVE! Use the drop-down list box in the top right corner to select your usb drive.

    If, like me, you have a couple of hard drives and a few usb drives hanging off your rig you will see a fairly long list here. The usb stick you have just plugged in will probably be the last one on the list (/dev/sdf in my case) and, if you haven't previously formatted it, it will appear as a single partition (mine is /dev/sdf1) in VFAT (FAT32) format. Double check that it is the size that it should be. Do not proceed unless you are sure you have the "right" drive.

    You cannot reformat a mounted drive so right-click on the picture of the (single) partition and select "unmount"

    If you are using a usb stick of more than 1Gb, you will probably want to resize the (soon to be) bootable partition. I'm using a 4Gb drive here so I resized the existing partition to 800Mb, which is large enough for OzOS and most Ubuntu-based distros. Right-click on the partition again and select "Resize/Move". A window appears letting you resize by dragging the right edge of the partition to a new location.



    In my case (with a 4Gb stick), I formatted the rest of the drive as a fat32 partition. That way, I can still use the stick to store other files that will be available to both Linux and Windows machines. To create a new partition in the now empty space, right-click in the grayed out space and select "New".

    The first partition needs to be formatted as an "ext2" drive - right-click> "Format To" >ext2

    I did the same with my second partition but selected "fat32".

    Double check the display of your new partitions and, if correct, select "Apply" from the menu bar.

    Don't worry if you get an error after one of the new partitions is mounted! With "automounting" of usb drives, the first of your partitions to be reformatted by gparted will trigger the mounting of the whole device, preventing the reformatting of the second partition. Simply click out of the stalled partitioning dialog, unmount the remaining partition (right-click>unmount) and select "apply" again.

    Once you have your new partition/s formatted, and the new ext2 partition is mounted (has the key symbol), you need to set it as "bootable". Right-click the ext2 partition, select "Manage Flags" and check "boot". Close the dialog and exit gparted.

    Part 3: Copy the contents of your iso file on the hard disk to the new bootable usb partition.

    In this part of the tutorial, we will mount your iso image to a normal directory and copy all the contents of that directory to the bootable partition on the usb stick.

    Open your preferred filemanager (I'm using thunar here).

    In your home drive, create a new directory/folder and call it "iso" (neither the location nor the name really matter, but that's how we'll refer to them here).

    It will make life easier if you also copy or move your iso file to your home directory. Close your file manager when you have finished.

    An iso file is a "special" file system. To mount it in the new iso directory, open a terminal and type/copy the following command:

    :~$ sudo mount oz-os-0.5-livecd-i386.iso ./iso/ -t iso9660 -o ro,loop=/dev/loop0

    Use the name of the iso file you are actually using rather than "oz-os-0.5-livecd-i386.iso".

    We will now copy the contents of /iso to the usb stick. You need root privileges for this bit so open your filemanager as root, eg:

    :~$ gksu thunar

    (substitute your own filemanager for "thunar" - eg "sudo nautilus" or "sudo konquerer")

    Navigate to your /home directory (filesystem>home>yourname) and open the /iso directory.

    Make sure hidden files are visible (View>Hidden files or Ctrl+H in thunar).

    Open your usb bootable partition in another filemanager window (If the usb drive isn't mounted, just unplug it and plug it back in)

    Select all the files and directories in the /iso directory (including the hidden /.disk directory) and drag/drop the lot to the open usb directory. It may take a minute to copy all the files.

    At this stage, make a note of the mount point of the bootable usb partition (mine is "/media/disk-2" in this example).

    Part 4: Add a bootloader and a "master boot record" and tidy up.

    We are almost done. We now have to add a "bootloader" that will work with an ext2 filesystem (rather than the syslinux one of the original iso file).

    We will use "extlinux", which is actually part of the syslinux package. You probably don't have the syslinux package installed, so get it now:

    :~$ sudo apt-get install syslinux

    (or get it from the "System" section of apt:foo)

    Unlike LILO which installs entirely to the MBR (master boot record), extlinux is like Grub and installs itself to the file system. We need to install it into the /isolinux directory on the usb stick. This is where you need to know the mount point of the bootable usb stick partition. I will use:

    :~$ sudo extlinux --install /media/disk-2/isolinux

    But you may need to replace "media/disk-2" with your own mount point.

    extlinux and isolinux are part of the syslinux family and speak the same language, ie their configuration files are the same, but just have a different name, the livecd uses isolinux because it uses the iso9660 filesystem. We're using ext2 so we use extlinux and rename the config file to match.

    Open up your USB drive in your filemanager and in /isolinux rename isolinux.cfg to extlinux.conf

    or, at the command line

    :~$ sudo mv /media/disk-2/isolinux/isolinux.cfg /media/disk-2/isolinux/extlinux.conf

    Again, change "media/disk-2" (both occurrences) if you need to.

    Lastly, we create a master boot record on the usb disk.

    :~$ sudo dd if=/usr/lib/syslinux/mbr.bin of=/dev/*YOUR USB DRIVE*

    (where *YOUR USB DRIVE* should be replaced with the path of your usb drive eg sda or sdb, but NOT an actual partition eg. sda1 or sdb1). In our example, mine is "sdf". This command gives a few lines of output.

    You now have a bootable usb stick of your favorite distro!

    Let me repeat that:

    You now have a bootable usb stick of your favorite distro!

    When you do boot a computer from this stick you will not get its "standard" boot menu. Instead, there will be an image, a bit of information and a command prompt that just says:

    :~$ boot

    Hit enter and everything should then proceed normally. If you need special boot parameters, this prompt is where to put them.

    Good luck and have fun.

    Aubrey