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.
![]() | 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. |
![]() | 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. |
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.
The following list gives an overview of all steps for creating a bootable USB stick:
Determine the name of your USB device (see the section called “Getting Your USB Device Name”).
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”.
Create a bootable partition on the device. This is explained in the section called “Making the USB Stick Bootable”.
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”.
Copy all the data required to boot a Linux system to the USB stick as described in the section called “Copying Necessary Data”.
Optionally create a home partition on the USB stick for storing personal data. Find directions in the section called “Creating an Optional Home Partition”.
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:
Open a shell and become root
.
Run:
tail -f /var/log/message
Plug in your USB stick. You will notice some messages showing in your shell.
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.
Before your USB stick is bootable, you must install a master boot record (MBR). Do the following:
Check your SUSE Linux version:
For versions greater than or equal to 10.2 proceed with Step 2.
For versions older than 10.2, you need syslinux version >= 3.31:
Download http://download.opensuse.org/distribution/10.2/repo/src-oss/suse/src/syslinux-3.31-16.src.rpm.
Open a shell and become root
.
Install the source RPM package:
rpm -ihv syslinux-3.31-16.src.rpm
Unpack the source tar file:
cd /usr/src/packages/BUILD tar xjvf /usr/src/packages/SOURCES/syslinux-3.31.tar.bz2
Copy the MBR:
cp -vi mbr.bin /usr/share/syslinux/
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.
After you have overwritten the master boot record (MBR), you have to make your USB stick bootable. Do the following:
Open a shell and become root
.
Stop the HAL daemon to keep it from mounting the USB stick automatically:
rchal stop
Create a new partition:
Run fdisk with the correct USB device name:
fdisk /dev/sda
Press N.
Choose a primary partition by pressing P.
Choose the partition number by entering 1.
Determine the size of your partition. In general, you can use the complete size of your USB stick.
Modify the created partition:
Press T to change the type of your partition.
Choose the partition number by entering 1.
Modify the type of the first partition by pressing E (W95 FAT 16 LBA.)
Make the first partition active, by entering A followed by 1.
Check and write your changes:
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)
Check your changes from your last step. If everything is correct, write your modifications by entering W.
Format the first partition:
mkdosfs /dev/sda1
After these steps, your USB stick is marked as bootable.
With this step, make the USB stick really bootable with syslinux, which is a Linux boot loader. Do the following:
Open a shell and become root
.
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.
Install the boot loader:
syslinux /dev/sda1
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.
Start the HAL daemon:
rchal start
Congratulations. Your USB stick is now fully bootable.
FIXME
After this step, the USB stick contains the data needed to boot a Linux system.
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:
Open a shell and become root
.
Downsize the first partition:
Run:
parted /dev/sda
You get the following output:
... Using /dev/sda (parted)
Type resize followed by partition number 1.
Leave the start as it is: just hit Enter.
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.
Enter quit to leave parted.
Create a new second partition:
Run:
fdisk /dev/sda
Create a new partition by entering N.
Select a primary partition by entering P.
Select the partition number by entering 2.
Choose the appropriate size for your partition. In general, you can use the default values and just hit Enter.
Save your changes with W.
Format and configure the second partition:
Create a file system on the second partition:
mkfs.ext3 /dev/sda2
Disable the automatic file system check, if desired:
tune2fs -c 0 /dev/sda2
Mount the second partition:
mount /dev/sda2 /mnt
Create your home directory:
mkdir /mnt/home
After this step, you can access a home partition on your USB stick.
Q: | I got the error |
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. |
Everything about syslinux, the boot loader.
GNU GRUB is another boot loader for Linux. This is not described in this recipe.