From Fedora Project Wiki

(→‎How to reformat flash drive: fix fdisk RPM and path, add ample warnings for destructive operations, distinguish partitioning from formatting, use indirect device name for safety)
Line 211: Line 211:
=== How to reformat flash drive ===
=== How to reformat flash drive ===


Use <code>fdisk</code> to reformat the flash drive.  If the drive is not new, a reformat is recommended.  The <code>fdisk</code> command must be run as root or using the <code>sudo</code> application.
'''''CAUTION: This will erase all data on the USB drive!'''''
 
If the drive has not been partitioned properly (or if you are unsure), use <code>fdisk</code> to repartition it.  If the drive is not new, a repartition and reformat is recommended.  The <code>fdisk</code> 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:


<pre>
<pre>
$ su -c 'fdisk /dev/sdb'
$ /sbin/fdisk /dev/sdb
</pre>
</pre>


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


The following session output from <code>fdisk</code> shows the responses to give to the prompts.  The line starting <code>Last cylinder ...</code> refers to the size of the flash drive, so may be different than in the example.
The following session output from <code>fdisk</code> shows the responses to give to the prompts.  The line starting <code>Last cylinder ...</code> refers to the size of the flash drive, so may be different than in the example.
Line 255: Line 257:
</pre>
</pre>


To finish, the partition must be initialized with an actual file system using <code>mkdosfs</code> as the root user.  Unmount the device before using <code>mkdosfs</code>.
To finish, the partition must be formatted with an actual file system using <code>mkdosfs</code> as the root user.  Unmount the device before using <code>mkdosfs</code>. 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!'''''


<pre>
<pre>
$ umount /dev/sdb1
$ umount /dev/sdb1
$ su -c '/sbin/mkdosfs -F 16 -n usbdisk /dev/sdb1'
$ /sbin/mkdosfs -F 16 -n usbdisk /dev/USBPARTITIONNAME
</pre>
</pre>



Revision as of 19:31, 7 March 2009

This how to explains how to create and use a Live USB drive.

Note: 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
  • A USB Flash Drive with 1 GB or more of storage space (also known as a USB Storage Stick, USB Thumb Drive, or Jump Drive)

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 an 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.

From a Downloaded Image

Download an ISO

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>-Live-<architecture>.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 also work for Custom Spins of Fedora Live ISO images, including those you make yourself with Pungi, LiveCD Creator, or Revisor.

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. 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.

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"

If you encounter any issues using this method, please create a ticket against the liveusb-creator.

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

Errors and Solutions

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

How to reformat flash drive

CAUTION: This will erase all data on the USB drive!

If the drive has not been partitioned properly (or if you are unsure), use fdisk to repartition it. If the drive is not new, a repartition and reformat is recommended. 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.

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/sdb1
$ /sbin/mkdosfs -F 16 -n usbdisk /dev/USBPARTITIONNAME

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

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.

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 -std-vga

See also

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

References