Preparing installation media at the FreeBSD command line

Preparing FreeBSD installation media from the command line in FreeBSD may sound like an intimidating task, but it is easier than you might think.

The first step toward installing a new operating system is preparing your installation media. There are numerous ways to do so, of course. Examples include using a network booting technology such as PXE, buying installation media from a vendor like Microsoft or FreeBSD Mall, and making your own bootable, portable installation media, such as optical (CD or DVD) and USB flash media.

By far, the most common way people get started using an open source operating system for the first time is by creating an installation CD (or, these days, increasingly often a DVD) using whatever optical media burning software they manage to get on their MS Windows systems that will create bootable disks. As many people have found out the hard way, XP was not designed with creating bootable CDs in mind; Nero, Roxio, and a small handful of less-known third party alternatives have filled that gap. Their point-and-click GUI interfaces are not always very clear in the way they present what is needed to make a bootable CD from an ISO image, but eventually people muddle through and end up creating their first installer CD.

Maybe the first open source OS they try out suits them well. Maybe they try half a dozen before they settle on something they like. Sometimes, they might even just encounter something utterly foreign to them on the first try, and give up in favor of familiarity.

Open source Unix-like operating systems offer a number of options for burning bootable CDs as well. There is typically a default tool with much the same functionality and style of GUI as you would find on one of those third-party MS Windows tools, delivered with the default install of one's first open source OS. For people who feel most comfortable with such GUI tools, this can be a great help. On the other hand, for those who like to run servers without GUIs and keep even their laptop and desktop Unix-like systems somewhat minimal, such tools are not much use.

If your Unix-like system of choice ends up being FreeBSD, and you want to be able to create an installer without using GUI tools, the process is probably much simpler than you would expect. The first step, of course, is getting an installer image. Assuming you are planning to use a CD, the most common installation media for OS installations that have not gotten too out-of-hand bloated by inclusion of everything under the sun, you will want to get the CD installer ISO from the Getting FreeBSD page.

Find the release you want, choose your preferred system architecture, and click on the ISO link for that architecture. The most common cases as of this writing will be the i386 architecture, which covers modern 32 bit Intel compatible x86 systems, and the amd64 architecture, which covers the common 64 bit Intel compatible x86 architectures. The currently applicable installer ISOs are those that end with -bootonly.iso or -disc1.iso. Either is suitable for installation of the system primarily from FTP servers, to get the most up-to-date installation for your release version.

Using the i386 architecture installer for FreeBSD 8.1-RELEASE as an example, burning a bootable installation CD using most optical media burners requires only a single simple command, using a program that is part of the FreeBSD base system:

burncd -f /dev/acd0 data FreeBSD-8.1-RELEASE-i386-bootonly.iso fixate

The -f option allows you to specify the optical drive used for burning a CD, in this example /dev/acd0. That is the most common device file for a primary optical media burner on FreeBSD systems, but if your system differs the device file name should obviously be changed to suit.

The data command sets the write mode for the burncd utility to write data tracks to the recordable CD.

The fixate command "fixates" the CD so that a table of contents is generated and burned to the disk, allowing the CD's contents to be read on a standard optical drive.

Unfortunately, optical drives take up space, and the increasing trend toward miniaturization in laptops makes a CD -- or any other optical disk technology for that matter -- a less convenient form of installation media than it once was. These days, however, even the smallest netbooks and thinnest Apple computers have USB ports. Even smartphones have USB ports, though they use an uncommon physical port form factor. Some might use an external USB optical drive to install an operating system, but all too often such devices cannot be used to boot from an optical media installer. Whether it would work is a bit of a crapshoot, and in any case we do not all have external USB optical drives, which can cost a pretty penny sometimes.

Meanwhile, a USB flash drive of about four gigabytes' capacity is probably on sale for something like two dollars at a store near you, and almost every general purpose consumer computing device can boot from USB flash media. You can get an installer media image for USB flash media in the same place you can get the CD image by selecting the filename that ends with -memstick.img instead of a standard optical media ISO file. Making your flash media storage device into bootable installation media is just as simple as doing the same with a recordable CD.

Just to be perfectly clear, as with the CD, you should not mount your USB flash media device before copying your installer image to it.

Once again using an i386 architecture installer for FreeBSD 8.1-RELEASE as an example, only a single simple command is needed, using a program that is part of the FreeBSD base system. First, though, you will want to make sure you know what USB device file to use as the target of the installer image write operation. You can do so by checking the output of dmesg, which should show output that ends with something like the following if you only just plugged in the USB flash storage device:

da0 at umass-sim0 bus 0 target 0 lun 0

da0: <Kingston DataTraveler 2.0 PMAP> Removable Direct Access SCSI-0 device

da0: 40.000MB/s transfers

da0: 962MB (1970176 512 byte sectors: 64H 32S/T 962C)

GEOM: da0: geometry does not match label (255h,63s != 64h,32s).

GEOM: da0: media size does not match label.

ugen4.2: <Kingston> at usbus4 (disconnected)

umass0: at uhub4, port 5, addr 2 (disconnected)

(da0:umass-sim0:0:0:0): lost device

(da0:umass-sim0:0:0:0): removing device entry

Based on this, you can see that the device identifier you need is da0, so you can use the dd command to write your installer image to the correct USB device:

dd if=FreeBSD-8.1-RELEASE-i386-memstick.img of=/dev/da0 bs=10240 conv=sync

The if= operand is used to specify the input file.

The of= operand is used to specify the output file, in this case, the USB device file /dev/da0.

The bs= operand is used to specify input and output block size -- basically, the size of the chunks of data read from the input file and written to the output file.

The conv= operand is used to specify a symbol indicating what kind of data format handling should be performed by dd.

The sync value for conv= tells dd to, quoted from the dd manpage:

Pad every input block to the input buffer size.  Spaces

are used for pad bytes if a block oriented conversion

value is specified, otherwise NUL bytes are used.

With your installation media in hand, plug it into the computer, change the boot device order for the computer in its BIOS settings, and fire it up. Voila: you have a FreeBSD installer for your computer.