Safety of your data on the disk: first, I assume that, to follow provided instruction on this article, you are using a USB stick which does not contain valuable data or you have already made backup. I also assume that you have downloaded or acquired the ISO of the OS you want to put on the USB stick. Second, most of the commands in this article requires root privilege. Please get a shell for root or use sudo
command.
Figure 1: USB Live Creation Tool Example, click here to enlarge image.
Tools on Windows
Following tools with GUI on Windows can create bootable linux media using USB Stick.
- Live USB Creator: it also has linux release: funny thing is, this also works with Cent OS and RHEL ISO release. You might need to use older versions for older releases of those OSs.
- UNetbootin: it supports most of the Linux/Unix OSs.
- BootFlash: especially used for puppy Linux
- WinImage: you can copy a DVD/CD or filesystem image using this tool
These are easy to use tools. Hence, we are going to skip to Linux options to provide details.
Using dd on Linux
One of the easiest procedure is to use dd command to copy the ISO into target device. It is trivial yet powerful. However, it rewrites partition table of the USB drive and it might add entries in the partition table in such a way that it might look messed up to you. But, it is not a problem. After experiments are done, to fix/cleanup partition table of a drive you can always follow the article: cleanup-corrupt-partition-table to get your USB Disk’s partition table back at original condition. Following command puts the ISO into the USB drive sdX.
# dd if=~/Downloads/Fedora-18-x86_64-Live-Desktop.iso of=/dev/sdX bs=8M
For example, if your usb device is sdc, sdX can be replaced with sdc. Don’t put sdc1 instead of sdc because dd requires the device id not the partition of a device.
# dd if=~/Downloads/Fedora-18-x86_64-Live-Desktop.iso of=/dev/sdb bs=8M
In this way, we can create bootable USB Device with any bootable ISO.
Using livecd-tools on Linux
Being developed primary with Fedora, livecd-tools is one of the most powerful tools for creating live USB Media. If you are using Fedora, RHEL, Cent-OS or any like minded OS this is the tool to go. Let’s first see how to install this tool. Then we’ll go on to see how to use it.
Installing livecd-tools on Fedora/Cent-OS
Easiest way to install this tool is to use yum,
# yum -y install livecd-tools
Installing livecd-tools on RHEL/Cent-OS
On RHEL, we have to enable EPEL repository. On RHEL 6 64 bit you have to apply following command,
# yum localinstall http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
On RHEL 6 32 bit apply following command,
# yum localinstall http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
Still applying yum command to install livecd-tools would fail though it was supposed to work,
# yum -y install livecd-tools
--> Processing Dependency: /sbin/extlinux for package: 1:livecd-tools-13.4.5-1.el6.x86_64
--> Finished Dependency Resolution
Error: Package: 1:livecd-tools-13.4.5-1.el6.x86_64 (epel)
Requires: /sbin/extlinux
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
The reason is that, in most cases, dependency to package: syslinux-extlinux is not met. This package is not available with RHEL. However, we can find this package (for example, in rpmfind.net) in many repositories.
Use the package according to your system architecture. For demonstration I am using RHEL 6.5 64 bit package.
# yum localinstall ftp://195.220.108.108/linux/centos/6.5/os/\
x86_64/Packages/syslinux-extlinux-4.02-8.el6.x86_64.rpm
Now, install livecd-tools using previous command, this time it will complete without error,
# yum -y install livecd-tools
If you encounter more dependency error please follow article: saoslab – creating local repository of RHEL and then, come back here again.
Creating Bootable USB media using livecd-tools
By default, your USB stick should have a primary partition with boot flag set. ‘parted print’ command outputs similar to following in that case (USB stick attached to our system is sdc),
# parted /dev/sdb print
Model: USB Disk (scsi)
Disk /dev/sdb: 8054MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 8053MB 8052MB primary boot
mkfs -T ext4 /dev/sdb1
e2label /dev/sdb1 RHEL_7S_x86_64
If boot flag is not set you can set it using following command (assuming usb device is sdc),
# parted /dev/sdb print toggle 1 boot
Now let’s create ext4 filesystem on the partition and give it a label,
# mkfs -T ext4 /dev/sdb1
mke2fs 1.42.12 (29-Aug-2014)
/dev/sdb1 contains a vfat file system labelled 'ESD-USB'
Proceed anyway? (y,n) y
Creating filesystem with 984944 4k blocks and 246512 inodes
Filesystem UUID: bf01a09b-e103-44de-b477-ee9b399f8ec2
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
# e2label /dev/sdb1 RHEL_7S_x86_64
livecd-tool can prepare a bootable USB stick when used following command (assuming downloaded iso is in Downloads directory and usb device is sdc),
# livecd-iso-to-disk --reset-mbr ~/Downloads/rhel-server-7.0-x86_64-dvd.iso /dev/sdb1
Verifying image...
/mnt/rhel-server-7.0-x86_64-dvd.iso: 14f3a6302e09a8fd9972c908a43a5e31
Fragment sums: a77a4a6ff19349fee89893a4fa6f3632b2cad759086938426fe67b9d2557
Fragment count: 20
Press [Esc] to abort check.
Checking: 100.0%
The media check is complete, the result is: PASS.
It is OK to use this media.
/Packages found, will copy source packages to target
Target filesystem (/dev/sdb1:) must be vfat, ext[234] or btrfs
[root@wireless ~]# mkfs -T ext4 /dev/sdb1
mke2fs 1.42.8 (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
491520 inodes, 1965824 blocks
98291 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2013265920
60 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
.....................................
.....................................
Packages/seahorse-nautilus-3.8.0-5.el7.x86_64.rpm
175,176 100% 285.12kB/s 0:00:00 (xfr#3582, to-chk=1044/4631)
.....................................
repodata/repomd.xml
4,182 100% 4.96kB/s 0:00:00 (xfr#4556, to-chk=0/4631)
Waiting for device to finish writing
Updating boot config file
Installing boot loader
/media/tgttmp.CPZBRa/syslinux is device /dev/sdb1
Target device is now set up with a Live image!
This gives us a bootable RHEL 7 USB Media. However, if we used Fedora, Cent-OS and similar ISO that would also work.
livecd-tools on RHEL/Cent-OS systems can be limited and does not support ext4. For example,
# livecd-iso-to-disk --reset-mbr ~/Downloads/Fedora-Live-Desktop-x86_64-20-1.iso /dev/sdb1
Verifying image...
/home/User/Downloads/Fedora-Live-Desktop-x86_64-20-1.iso: f8426bbbc374eb94d469175a3e9655f2
Fragment sums: e266b5eb16b33afe7ad21f695d8eb7d93a26753d5eb8a974a5bc41dcc621
Fragment count: 20
Press [Esc] to abort check.
Checking: 100.0%
The media check is complete, the result is: PASS.
It is OK to use this media.
USB filesystem must be vfat, ext[23]
Cleaning up to exit...
As a remedy to this problem, instead of creating ext4 in previous step, format using ext3 filesystem. Here’s the substitute for that command,
# mkfs -T ext3 /dev/sdb1
And then apply livecd-iso-to-disk command again which will succeed.
livecd-tools with fat32 filesystem
If you want fat32 filesystem instead of ext4 or ext3 you do not need to use mkfs command. Simply go ahead with following livecd command,
# livecd-iso-to-disk --format --msdos --reset-mbr ~/Downloads/Fedora-20-x86_64-Live-Desktop.iso /dev/sdb
Using livecd-tools to create UEFI bootable USB Stick
You need fat32 partition for EFI compatible bootable media. Directory structure changes too. Following command takes care of all of this,
# livecd-iso-to-disk --format --reset-mbr --efi /home/atiq/Fedora-Live-Cinnamon-x86_64-23-10.iso /dev/sdb
Verifying image...
/home/atiq/Fedora-Live-Cinnamon-x86_64-23-10.iso: c07fca53758161c44b8800ae316b0852
Fragment sums: d7537f39df6c45f11dfb119497a2d7f12b9a813735e31574c8d1545e46f9
Fragment count: 20
Supported ISO: no
Press [Esc] to abort check.
Checking: 100.0%
The media check is complete, the result is: PASS.
It is OK to use this media.
WARNING: THIS WILL DESTROY ANY DATA ON /dev/sdb!!!
Press Enter to continue or ctrl-c to abort
/dev/sdb: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success
Waiting for devices to settle...
mkfs.fat 3.0.27 (2014-11-12)
Copying live image to target device.
squashfs.img
1,178,566,656 100% 336.51MB/s 0:00:03 (xfr#1, to-chk=0/1)
osmin.img
12,288 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1)
Setting up /EFI/BOOT
Updating boot config file
Installing boot loader
Target device is now set up with a Live image!
The previous command restructures the partition table, formats and put files required for UEFI firmware. The filesystem on the usb disk looks like below,
# parted /dev/sdb print
Model: SCSI DISK (scsi)
Disk /dev/sdb: 4034MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 4032MB 4031MB fat32 EFI System Partition boot, legacy_boot, esp
Using livecd-tools to create Live USB Media with persistent storage
If the OS in ISO supports persistent storage then you can enable persistent storage depending on space available on the USB storage device. Following command prepares a Live USB Media with 1 GB persistent storage.
# livecd-iso-to-disk --overlay-size-mb 1024 --reset-mbr ~/Downloads/Fedora-Live-Desktop-x86_64-20-1.iso
Related Article
On this blog, Creating Bootable USB Key of Puppy Linux with ext4 Filesystem
References
Caution: livecd-iso-to-disk damages partition table if device is used instead of partition table i.e., /dev/sdb instead of /dev/sdb1, EFI enabled live cd for usb boot. At least once, I found that though partition (specifically a partition number) was provided in command line it affected the device partition table because of wrong command.