Creating a Bootable USB Stick

Thomas Schraitle

Needs proofreading

$Revision: 156 $

$Date: 2007-01-22 21:06:14 +0100 (Mo, 22 Jan 2007) $

You want to create an USB stick from which you can boot. This can be used as a rescue system or to store additional data that you can carry with you.

[Warning]Wrong Device Name Can Destroy Your System

Using the wrong device name leads to failure booting your system or data loss. Always check twice before entering and executing these commands.

[Warning]Preliminary Version: Use It at Your Own Risk

The description in this recipe is a draft. It is not finished. It has not been checked or edited in any way. If you want to contribute to it, please go to http://developer.novell.com/wiki/index.php/Lessons_for_Lizards.

Requirements

You need the following:

  • A USB stick. Most should work, but some users reported that it does not work for every USB stick.

  • The device name of your USB stick.

  • A BIOS that supports booting from a USB device.

  • root permissions for this procedure.

Procedure

The following list gives an overview of all steps for creating a bootable USB stick:

  1. Determine the name of your USB device (see the section called “Getting Your USB Device Name”).

  2. Install a master boot record (MBR) on your USB stick as described in the section called “Overwriting the Master Boot Record on Your USB Stick”.

  3. Create a bootable partition on the device. This is explained in the section called “Making the USB Stick Bootable”.

  4. Install a boot loader on the USB stick so it is able to boot. Refer to the section called “Creating a Bootable USB Stick with syslinux”.

  5. Copy all the data required to boot a Linux system to the USB stick as described in the section called “Copying Necessary Data”.

  6. Optionally create a home partition on the USB stick for storing personal data. Find directions in the section called “Creating an Optional Home Partition”.

Getting Your USB Device Name

Before you start, you must know the device name of your USB stick. A wrong name can destroy your system and your data. Do the following:

  1. Open a shell and become root.

  2. Run:

    tail -f /var/log/message
  3. Plug in your USB stick. You will notice some messages showing in your shell.

  4. Look for the following entry:

    Dec 16 11:46:00 erde kernel: usb-storage: device scan complete
    Dec 16 11:46:00 erde kernel: SCSI device sda: 3987968 512-byte hdwr sectors (2042 MB)

    The important information is emphasized: In this case, the USB device name is /dev/sda but it may differ your system, depending which devices do you have.

After these steps, you know the correct USB device name. Use it in the following steps.

Overwriting the Master Boot Record on Your USB Stick

Before your USB stick is bootable, you must install a master boot record (MBR). Do the following:

  1. Check your SUSE Linux version:

  2. Write the MBR to your USB stick:

    dd if=/usr/share/syslinux/mbr.bin of=/dev/sda bs=512 count=1

After these steps, you have a master boot record on your USB stick.

Making the USB Stick Bootable

After you have overwritten the master boot record (MBR), you have to make your USB stick bootable. Do the following:

  1. Open a shell and become root.

  2. Stop the HAL daemon to keep it from mounting the USB stick automatically:

    rchal stop
  3. Create a new partition:

    1. Run fdisk with the correct USB device name:

      fdisk /dev/sda
    2. Press N.

    3. Choose a primary partition by pressing P.

    4. Choose the partition number by entering 1.

    5. Determine the size of your partition. In general, you can use the complete size of your USB stick.

  4. Modify the created partition:

    1. Press T to change the type of your partition.

    2. Choose the partition number by entering 1.

    3. Modify the type of the first partition by pressing E (W95 FAT 16 LBA.)

    4. Make the first partition active, by entering A followed by 1.

  5. Check and write your changes:

    1. Print your changes by entering P. It looks like the following output:

      Disk /dev/sda: 2041 MB, 2041839616 bytes
      63 heads, 62 sectors/track, 1020 cylinders
      Units = cylinders of 3906 * 512 = 1999872 bytes
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sda1   *           1        1020     1992029    e  W95 FAT16 (LBA)
    2. Check your changes from your last step. If everything is correct, write your modifications by entering W.

  6. Format the first partition:

    mkdosfs /dev/sda1

After these steps, your USB stick is marked as bootable.

Creating a Bootable USB Stick with syslinux

With this step, make the USB stick really bootable with syslinux, which is a Linux boot loader. Do the following:

  1. Open a shell and become root.

  2. Check your USB stick with fdisk -l /dev/sda. Of particular importance is the active partition, marked with a *. See Step 5.a for sample output.

  3. Install the boot loader:

    syslinux /dev/sda1
  4. Boot from your USB stick. If it works, you should see something like this:

    SYSLINUX 3.xx YYYY-MM-DD EBIOS Copyright (C) 1994-YYYY H. Peter Anvin
    Could not find kernal image: linux
    boot :

    The version 3.xx and date YYYY-MM-DD depends on the syslinux used.

  5. Start the HAL daemon:

    rchal start

Congratulations. Your USB stick is now fully bootable.

Copying Necessary Data

FIXME

After this step, the USB stick contains the data needed to boot a Linux system.

Creating an Optional Home Partition

This step is optional. Sometimes it is useful to have an additional partition to store personal data. To create a second partition, use the following procedure:

  1. Open a shell and become root.

  2. Downsize the first partition:

    1. Run:

      parted /dev/sda

      You get the following output:

      ...
      Using /dev/sda
      (parted)
    2. Type resize followed by partition number 1.

    3. Leave the start as it is: just hit Enter.

    4. Decide how much space you need for your home partition. For example, if you have a 2 GByte stick, you could use 1 GByte for your boot system and the rest for your home partition. In this case, enter 1000MB and press Enter.

    5. Enter quit to leave parted.

  3. Create a new second partition:

    1. Run:

      fdisk /dev/sda
    2. Create a new partition by entering N.

    3. Select a primary partition by entering P.

    4. Select the partition number by entering 2.

    5. Choose the appropriate size for your partition. In general, you can use the default values and just hit Enter.

    6. Save your changes with W.

  4. Format and configure the second partition:

    1. Create a file system on the second partition:

      mkfs.ext3 /dev/sda2
    2. Disable the automatic file system check, if desired:

      tune2fs -c 0 /dev/sda2
    3. Mount the second partition:

      mount /dev/sda2 /mnt
    4. Create your home directory:

      mkdir /mnt/home

After this step, you can access a home partition on your USB stick.

Troubleshooting

Q:

I got the error Cluster sizes larger than 16 K not supported

A:

Try to use a more recent version of syslinux. Version 3.11 and higher is reported to work.

Q:

The USB stick does not boot

A:

Try to repeat the section called “Creating a Bootable USB Stick with syslinux”. If that does not work either, you should also try to format the stick under Windows.

For More Information

http://syslinux.zytor.com/

Everything about syslinux, the boot loader.

http://www.gnu.org/software/grub/grub.en.html

GNU GRUB is another boot loader for Linux. This is not described in this recipe.