In this recipe, we will learn how to create a USB installation media on Windows or OS X. Nowadays, more and more server systems, desktop PCs, and laptops get shipped without any optical drive. Installing a new operating system, such as CentOS Linux using USB devices gets essential for them as no other installation option is available, as there is no other way to boot the installation media. Also, installing CentOS using USB media can be considerably faster than using the CD/DVD approach.
Before we begin, it is assumed that you have followed the previous recipe in which you were shown how to download a minimal CentOS image and confirm the checksum of the relevant image files. It is also assumed that all the downloads (including the downloaded ISO file) are stored on Windows in your C:Users<username>Downloads
folder or if using a OS X system, in the /Users/<username>/Downloads
folder. Next, you will need a free USB device which can be discovered by your operating system, with enough total space, and which is empty or with data on it that can be discarded. The total space of the USB device needed for preparing as an installation media for CentOS 7 for the minimal version must be roughly 700 megabyte. If you are working on a Windows computer, you will need a working Internet connection to download additional software. On OS X, you need an administrator user account.
To begin this recipe, start up your Windows or OS X operating system, then connect a free USB device with enough capacity, and wait until it gets discovered by File Manager under Windows or Finder under OS X.
dd
. Visit http://www.chrysocome.net/dd in your favorite browser. Now download the latest dd-XX.zip
file you can find there, with XX
being the latest stable version number. For example, dd-0.5.zip
.Downloads
folder using File Manager. Here you will find the dd-05.zip
file. Right-click on it and click on Extract All, and extract the dd.exe
file without creating any subdirectory.cd downloads dd.exe --list
cd ~/Downloads diskutil list
removable media
section. Below that, you should find a line starting with Mounting on
and then a drive letter, for example, .e:
. This cryptic written drive letter is the most important part we need in the next step, so please write it down./dev/disk<number>
, where number
is a unique identifier of the disk. The disks are numbered, starting with zero (0
). Disk 0
is likely to be the OS X recovery disk, and disk 1
is likely to be your main OS X installation. To identify your USB device, try to compare the NAME
, TYPE
, and SIZE
columns to the specifications of your USB stick. If you have identified the device name, write it down, for example, /dev/disk3
.\.e:
(change this as required and be careful what you type – this can create tremendous data loss). Also, substitute XXXX
with the correct iso
file version number in the next command:dd.exe if=CentOS-7-x86_64-Minimal-XXXX.iso of=\.e: bs=1M
XXXX
and disk3
with the correct version number and the correct USB device path):sudo diskutil unmountDisk /dev/disk3 sudo dd if=./CentOS-7-x86_64-Minimal-XXXX.iso of=/dev/disk3 bs=1m
dd
program finishes, there will be some output statistics on how long it took and how much data has been transferred during the copy process. On OS X, ignore any warning messages about the disk not being readable.So what have we learned from this experience?
The purpose of this recipe was to introduce you to the concept of creating an exact copy of a CentOS installation ISO file on a USB device, using the dd
command-line program. The dd
program is a Unix based tool which can be used to copy bits from a source to a destination file. This means that the source gets read bit by bit and written to a destination without considering the content or file allocation; it just involves reading and writing pure raw data. It expects two file name based arguments: input file (if
) and output file (of
). We will use the CentOS image file as our input filename to clone it exactly 1:1
to the USB device, which is accessible through its device file as our output file parameter. The bs
parameter defines the block size, which is the amount of data to be copied at once. Be careful, it is an absolute expert tool and overwrites any existing data on your target while copying data on it without further confirmation or any safety checks. So at least double-check the device drive letters of your target USB device and never confuse them! For example, if you have a second hard disk installed at D:
and your USB device at E:
(on OS X, at /dev/disk2
and /dev/disk3
respectively) and you confuse the drive letter E:
with D:
(or /dev/disk3
with /dev/disk2
), your second hard disk would be erased with little to no chances of recovering any lost data. So handle with care! If you're in doubt of the correct output file device, never start the dd
program!
In conclusion, it is fair to say that there are other far more convenient solutions available for creating a USB installation media for CentOS 7 than the dd
command, such as the Fedora Live USB Creator. But the purpose of this recipe was not only to create a ready-to-use CentOS USB installer but also to get you used to the dd
command. It's a common Linux command that every CentOS system administrator should know how to use. It can be used for a broad variety of daily tasks. For example, for securely erasing hard disks, benchmarking network speed, or creating random binary files.