From Fedora Project Wiki

m (shorter named anchor (test))
m (Made 'How to Partition' more readable)
Line 61: Line 61:


<pre>  
<pre>  
Command (m for help): d
Command (m for help): '''d'''
Selected partition 1
Selected partition 1


Command (m for help): n
Command (m for help): '''n'''
Command action
Command action
e  extended
e  extended
p  primary partition (1-4)
p  primary partition (1-4)
p
'''p'''
Partition number (1-4): 1
Partition number (1-4): '''1'''
First cylinder (1-960, default 1):
First cylinder (1-960, default 1): '''↵'''
Using default value 1
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-960, default 960):
Last cylinder or +size or +sizeM or +sizeK (1-960, default 960): '''↵'''
Using default value 960
Using default value 960


Command (m for help): t
Command (m for help): '''t'''
Selected partition 1
Selected partition 1
Hex code (type L to list codes): 6
Hex code (type L to list codes): '''6'''
Changed system type of partition 1 to 6 (FAT16)
Changed system type of partition 1 to 6 (FAT16)


Command (m for help): a
Command (m for help): '''a'''
Partition number (1-4): 1
Partition number (1-4): '''1'''


Command (m for help): w
Command (m for help): '''w'''
The partition table has been altered!
The partition table has been altered!



Revision as of 17:35, 1 November 2009

This how to explains how to create and use Live USB media. A Live USB key lets you boot any USB-bootable computer into a Fedora operating system environment without writing to that computer's hard disk. The Live USB key can feature an area to store changes to the system, called a persistent overlay. It can also have a separate area to store user account information and data such as documents and downloaded files, with optional encryption for security and peace of mind. Essentially, you can carry your computer with you in your pocket, booting it on nearly any system you find yourself using.

Creating Live CD ISO image
A Live USB system is created from the same ISO image file that is used to create Live CD/DVD media. You can download ISO images for the official Fedora release from the Fedora download site. Consult How to create and use a Live CD for more information on creating your own customized ISO image file.
Command formats
Lines beginning with "$" indicate commands you should type (do not include the $; this represents the command line prompt); subsequent lines represent typical output. You will need to run some commands as root.

System Requirements

  • A working computer running Fedora or Windows. If you are using other Linux distributions, consider using UNetbootin. UNetbootin is available in the Fedora repository as well
  • A USB flash drive, also known as a USB stick, thumb drive, pen drive, or jump drive, with 1 GB or more of storage space, on a vfat file system (standard for almost all off-the-shelf USB media)

Ability to boot from USB media

Though most modern ones can, not all computers can boot from USB media, due to different BIOS settings and system capabilities. If your computer cannot do so, this procedure will not be useful. If you are not sure and don't mind downloading and installing an image on your USB drive (possibly wiping it of data), the only risk is wasting some time.

If your USB stick is not in working order, this procedure may fail. Watch for error messages during the process.

Some flash drives may not be bootable by default, even if your hardware is capable of doing so. You may need to mark the partition bootable or you may just need to reformat the flash drive. See "Errors and Solutions" below for more information.

Check the size of your USB device

Many USB sticks indicate the size on the packaging or the outside of the device.

If you don't know the size of the device, or want to check it for data, you should be able to auto-mount the USB device by inserting it into a USB port. You can check the contents and size using the graphical file manager. In Linux, you can also use the command line:

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
143G   14G  122G  10% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                1009M     0 1009M   0% /dev/shm
/dev/sdb1             3.9G  4.0K  3.9G   1% /media/usbdisk

USB drives are usually mounted in /media. In this case, the device is /dev/sdb1 and has a 3.9GB capacity, and is almost empty.

Take note of "/dev/sdb1" or equivalent; you will be specifying the device name if you use the command line method.

Update your Operating System

If you are running Fedora 9 or 10, be sure to install the latest operating system updates to fix a bug that will render Fedora 11 LiveUSB sticks unbootable. You can use a graphical update tool, or run "yum update" as root.

How to Partition

CAUTION
This will erase all data on the USB drive! Please read the instructions below carefully.

If the drive has not been partitioned properly (or if you are unsure), use fdisk to repartition it.

It is also possible to do a non-destructive installation of a LiveUSB image, if you have sufficient empty space. (See "How to install non-destructively" below.)

The fdisk command must be run as root. Include only the drive name in the command, not the partition number. Be sure to select the correct disk, or you may erase important data! Check the output of "df -h" if you are unsure. For example, if your partition will be /dev/sdb1, do:

$ /sbin/fdisk /dev/sdb

If you don't have fdisk installed, run "yum install util-linux-ng" as root.

The following session output from fdisk shows the responses to give to the prompts. The line starting Last cylinder ... refers to the size of the flash drive, so may be different than in the example.

 
Command (m for help): '''d'''
Selected partition 1

Command (m for help): '''n'''
Command action
e   extended
p   primary partition (1-4)
'''p'''
Partition number (1-4): '''1'''
First cylinder (1-960, default 1): '''↵'''
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-960, default 960): '''↵'''
Using default value 960

Command (m for help): '''t'''
Selected partition 1
Hex code (type L to list codes): '''6'''
Changed system type of partition 1 to 6 (FAT16)

Command (m for help): '''a'''
Partition number (1-4): '''1'''

Command (m for help): '''w'''
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

How to Format

CAUTION
This will erase all data on the USB drive! Please read the instructions below carefully.

If your USB media has sufficient free space on a vfat file system already, you do not need to perform this step.

To finish, the partition must be formatted with an actual file system using mkdosfs as the root user. Unmount the device before using mkdosfs. In the below example, /dev/USBPARTITIONNAME might be, for example, /dev/sdb1. Be sure to select the correct partition; formatting destroys all data on it!

$ umount /dev/USBPARTITIONNAME
$ /sbin/mkdosfs -F 16 -n usbdisk /dev/USBPARTITIONNAME

If you don't have mkdosfs installed, run "yum install dosfstools" as root.

How to install non-destructively

Skip the repartitioning and formatting step above, and simply continue with the below steps. Please keep in mind you should have at least 1GB free. It is highly recommended to make a backup copy of the data on the USB drive before proceeding in case something goes wrong.

From a Downloaded Image

Download an ISO

(If you are using liveusb-creator - the "Graphical" method below, with a "supported" Fedora release, you can skip this step. The program will download the ISO for you.)

You can use BitTorrent or your web browser to download a bootable image, or ISO, which you will install on your USB drive. Quick links:

You are looking for a file with "Live" in the name, usually of the form "F<version>-<architecture>-Live.iso". For example, "F10-i686-Live.iso" is the Fedora 10 release for 32-bit Pentium Pro and compatible CPUs. "F11-Alpha-x86_64-Live.iso" is the alpha pre-release version of Fedora 11 for 64-bit Intel-compatible CPUs. Be sure to choose the right file for your architecture. (32-bit releases will generally run on 64-bit hardware, but will not be optimized.)

These instructions will also work for Custom Spins of Fedora Live ISO images, including those you make yourself with Revisor (a graphical tool), or LiveCD Creator (command-line tool used by Revisor). (Pungi is a command-line tool you can use to create installable ISOs, but not Live ISOs.)

If you use a LiveUSB with data persistence, you can use the "yum update" method described below to get the latest daily Rawhide RPMs (mostly for testers and not everyday use) except for the kernel. See Releases/Rawhide for more information about daily builds.

Graphical Method - Windows or Linux

Fedora LiveUSB sticks can be created in Windows and Linux using the liveusb-creator.

For Windows using the following steps:


If you are using Linux, you can use Add/Remove Programs and search for liveusb-creator or on the command line:

$ su -c "yum install liveusb-creator"
Creating pre-release LiveUSB using Fedora 10
Creating a LiveUSB of Fedora 11 pre-releases requires the latest version of syslinux, which is currently available in Rawhide and in the latest Windows liveusb-creator.

Users of Fedora 10 and below should upgrade to the latest syslinux package using this command:

$su -c "yum --enablerepo=rawhide update syslinux"

To start, run "liveusb-creator" on the command line, or on the GNOME menu, go to "Applications -> System Tools -> liveusb-creator".

Command Line Method - Linux only

In the following examples, replace "/path/to/ISO" with e.g. F10-Live-i686.iso or the full path to the ISO you downloaded, e.g. /tmp/F10-Live-i686.iso.

Replace /dev/USBPARTITIONNAME with the appropriate partition name. For example, /dev/sdb1 in the example above ("Check the size of your USB drive"). Be careful to specify the correct device, or you may lose important data!

Check livecd-tools

Make sure the livecd-tools RPM is installed.

$ rpm -q livecd-tools

You will see the name of the RPM and a version number if it is installed, and no output if it is not installed.

If "livecd-tools" is not installed, install it using yum.

$ su -c "yum install livecd-tools"

Run livecd-iso-to-disk script

Make sure that the USB drive is not mounted before executing the following, and give the root password when prompted.

$ su -c "livecd-iso-to-disk /path/to/ISO /dev/USBPARTITIONNAME"
Password:
Copying live image to USB stick
Updating boot config file
Installing boot loader
USB stick set up as live image!

Data Persistence

Data persistence means that your files and settings will remain peristent even after you reboot your live system. Persistence is supported from Fedora 9 (beta) onwards. The primary usage of this feature is booting a USB stick with your live image as well as the persistent changes.

Use liveusb-creator, a graphical utility to do this easily. Liveusb-creator is available in the Fedora repository and for Windows users as well.

If you prefer the command line, you can run the following command:

$ livecd-iso-to-disk --overlay-size-mb 512 /path/to/ISO /dev/USBPARTITIONNAME

where 512 is the desired size (in megabytes) of the overlay. The livecd-iso-to-disk shell script won't accept an overlay size value greater than 2047. You can find the livecd-iso-to-disk shell script in the LiveOS directory at the top-level of the CD image. Note that you'll need to have space on your USB stick for the live image plus your overlay plus any other data you want on the stick.

Direct Copy

Starting with Fedora 12 Beta, .iso files can also be written directly to USB sticks using "dd" or similar tools. Please note this will overwrite any data on the targeted partition, and will also not create storage to support data persistence.

From a running Live CD/DVD

If you are already running a live CD or DVD and want to convert that into a bootable USB stick, run the following command:

$ livecd-iso-to-disk /dev/live /dev/USBDEVICENAME

How to Boot a Live USB Drive

  • Power off the computer.
  • Plug the USB drive into a USB port.
  • Remove all other portable media, such as CD, DVD, or floppy disks.
  • Power on the computer.
  • If the computer is configured to automatically boot off of the USB drive, you will see a screen that says "Automatic boot in 10 seconds..." with a countdown.
  • If the computer starts to boot off the hard drive, you'll need to manually configure it to boot off the USB drive.
    • Wait for a safe point to reboot safely.
    • As the machine starts to reboot, watch carefully for instructions on what key to press (usually a function key or Escape) to enter the boot device selection menu, or "BIOS setup". Press and hold that key. If you miss the window of opportunity (often only a few seconds) then reboot and try again.
    • Use the BIOS setup menu to put your USB drive first in the boot sequence. It might be listed as a hard drive rather than a removable drive. Each hardware manufacturer has a slightly different method for doing so. Use caution! Your computer could become unbootable or lose functionality if you change any other settings. Though these settings can be put back, you'll need to remember what you changed in order to do so.
    • Save the changes, exit, and the computer should boot the Live USB drive.

How to Make a bootable USB Drive to Install Fedora 11 instead of using a physical DVD

Why would I want to make a usbkey installer from the DVD instead of the LiveCD?

If you are installing to a netbook, or otherwise do not have an optical drive (or burner, or media), and you want the extra flexibility of using the regular DVD installer instead of the Live image, then this method will give a useful install medium. You are then free to customize package selection, choose which filesystem you prefer for your rootfs (ext3 OR ext4, btrfs, etc), and rescue mode is available.

Preparing the usbkey

The easiest setup method is to install and use unetbootin, since Fedora's own liveusb-creator and livecd-tools' livecd-iso-to-disk.sh (except for an unofficial patched version) currently do not support putting the DVD installer on USB.

The manual setup method follows:

Firstly download the iso file Fedora-11-i386-DVD.iso from a Fedora mirror. Then loop mount the iso on a local mount point such as /mnt/tmp

# mount -o loop /path-to-iso/Fedora-11-i386-DVD.iso /mnt/tmp

Now plug in the usbkey and then copy the main iso file as well as the images directory from the /mnt/tmp/ directory to the root directory of the usbkey.

# cp /path-to-iso/Fedora-11-i386-DVD.iso /media/usbdisk/
# cp -r /mnt/tmp/images /media/usbdisk/

Next download the boot.iso file from a rawhide mirror from the development/i386/os/images/ directory on the mirror and store it on your computer's hard drive.

From your running F11 system (including an F11 livecd) make sure you have the livecd-tools package installed by doing:

yum install livecd-tools

Use the "mount" command to find where the usbkey is (e.g. /dev/sdb1) or look at /var/log/messages to find where the key was mounted. Next umount the usbkey either from the desktop icon or using the umount command - but keep a note of where the usbkey is e.g. /dev/sdb1

Now as root run:

# livecd-iso-to-disk path-to/boot.iso /dev/sdb1

If the key is not bootable then refer to the information below to make it bootable otherwise this command will fail.

Now you should have a bootable usbkey which will run an F11 install. When you boot the key select a hard drive install and select the drive as /dev/sdb1 (or your usbkey drive) and the path should be /

The remainder of the install should be the same as for using a DVD in an optical drive, but when you select options make sure that you select your disk partitioning carefully if you are doing custom partitioning and also make sure that the bootloader is installed on the correct drive (by default it will be installed on the usbkey so you will need to change it to the master boot record on the hard drive.

Errors and Solutions

liveusb-creator problems

Partition isn't marked bootable!

If you get the following message, you need to mark the partition bootable.

$ livecd-iso-to-disk Fedora-<release>-Live-i686.iso /dev/sdb1
Partition isn't marked bootable!
You can mark the partition as bootable with 
    $ /sbin/parted /dev/sdb
    (parted) toggle N boot
    (parted) quit
Cleaning up to exit...

To mark the partition bootable,

$ parted /dev/sdb
GNU Parted 1.8.6
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: Imation Flash Drive (scsi)
Disk /dev/sdb: 1062MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  1062MB  1062MB  primary  fat16             

(parted) toggle 1 boot
(parted) print                                                    
Model: Imation Flash Drive (scsi)
Disk /dev/sdb: 1062MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  1062MB  1062MB  primary  fat16        boot 

(parted) quit                                                             
Information: Don't forget to update /etc/fstab, if necessary.             

Partition need a filesystem label!

If you get the following message, you need to label the partition.

$ livecd-iso-to-disk Fedora-<release>-Live-i686.iso /dev/sdb1
Need to have a filesystem label or UUID for your USB device
Label can be set with /sbin/dosfslabel
Cleaning up to exit...

To label the partition.

$ dosfslabel /dev/sdb1 usbdisk

Partition has different physical/logical endings!

If you get the following message, you may need to reformat the flash drive.

$ fdisk -l /dev/sdb

Disk /dev/sdb: 2029 MB, 2029518848 bytes
129 heads, 32 sectors/track, 960 cylinders
Units = cylinders of 4128 * 512 = 2113536 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         961     1981936    6  FAT16
Partition 1 has different physical/logical endings:
phys=(967, 128, 32) logical=(960, 31, 32)

MBR appears to be blank!

If your test boot reports a corrupted boot sector, or you get the following message, you need to install MBR.

$ livecd-iso-to-disk Fedora-<release>-Live-i686.iso /dev/sdb1
MBR appears to be blank.
You can add an MBR to this device with
Cleaning up to exit...


To install MBR,

$ cat /usr/lib/syslinux/mbr.bin > /dev/sdb


SYSLINUX Boot Error!

If you were using the script on previous Red Hat or Fedora Release and getting following error message,

SYSLINUX 3.xx ... EBIOS Load error - Boot error

You may need to upgrade your syslinux to 3.50 or higher from Peter Anvin's SYSLINUX .

Testing Live Image on USB

You can test your Live Image on USB using QEMU as shown in the screenshot on right.

File:FedoraLiveCD USBHowTo usb flash with qemu.png

For example, if your USB flash drive is on /dev/sdb1, you could type following command:

$ umount /dev/sdb1
$ qemu -hda /dev/sdb -m 256 -vga std

See also

Red Hat Magazine | I am Fedora, and so can you!

References