Important

Netgate is offering COVID-19 aid for pfSense software users, learn more.

Writing an Installation Image to Flash Media

Flash Media includes USB drives, Compact Flash cards, and SD cards.

Decompress the Image

The most common indication that a file is compressed is its extension, if the filename ends in .gz, .bz2, .zip, or similar then it is likely compressed. If so, decompress it using an appropriate utility:

Using 7-Zip

  1. Right click the downloaded img.gz file.

  2. Click 7-zip.

  3. Click Extract Here.

    ../_images/imgwriter_01_extract.png

Use the gunzip command line utility to decompress the image:

gunzip /path/to/file

Use the gzip command line utility to decompress the image:

gzip -d /path/to/file

Use the gzip command line utility to decompress the image:

gzip -d /path/to/file

Connect the Flash Drive to the Workstation

Start by connecting the drive to the workstation where the downloaded image resides.

Locate the device name that the system designates for the drive:

The drive will be named after a single uppercase letter, e.g. D. Use Explorer or examine the system control panel and look at the available disks for one matching the drive.

The device name may look like /dev/diskX where X is a decimal digit. Run diskutil list from a command prompt or use the GUI tool Disk Utility.

Note

If the disk is named diskX then the device to pass to the writing utility is actually rdiskX which is must faster for these types of low-level operations.

The device name may look like /dev/sdX where X is a lowercase letter. Look for messages about the drive attaching in the system log files or by running dmesg.

Note

Also make sure the located name refers to the device itself rather than a partition on the device. For example, /dev/sdb1 is the first partition on the disk, so it would be writing to a partition on the device and the drive may not end up being bootable. In that case use /dev/sdb instead so the entire disk is written.

The device name may look like /dev/daX where X is a decimal digit. Look for messages about the drive attaching in the system log files or by running dmesg.

Cleaning The Target Disk

Optionally, but recommended, is to get a fresh start and wipe all of the partitions from the disk, as sometimes the target drive already has a partition and cannot be written to properly. This can be done a few different ways:

Warning

By choosing the wrong destination one of the system hard disks could be erased. Check and recheck the disk selection before writing an image.

The Disk Management interface in Windows is one way to delete the partitions from a disk but often it has the operation disabled. The simplest and most reliable method is to use diskpart.

  1. Start a command prompt as Administrator.

    ../_images/admin_cmd_prompt.png
  2. Run diskpart.

  3. Type list disk to show the disks connected to the system. One of them will be the target USB flash drive.

  4. Type select disk *n* where n is the disk number of the target USB flash drive from the list in the previous command output.

  5. Type clean to remove the partitions from the disk.

The full diskpart session can be seen here:

../_images/imgwriter_02_clean_target_disk.png

Warning

By choosing the wrong destination one of the system hard disks could be erased. Check and recheck the disk selection before writing an image.

The dd command is by far the easiest way to erase the disk’s partition table:

$ sudo dd if=/dev/zero of=/dev/sdz bs=1M count=1

Write the Image

Now it is time to write the image to the flash drive. The exact procedure varies by Operating System.

Warning

The operations in this section will completely overwrite any existing content on the flash drive so be sure that any files previously stored on the drive are backed up elsewhere.

In order to write an image to a drive from a Windows workstation, it is recommended to use a GUI tool such as Etcher. You can also use Rufus or Win32 Disk Imager as listed below.

Using Rufus

Rufus is a simple but powerful utility that helps format and create bootable USB flash drives, such as USB keys/pendrives, memory sticks.

  1. Download Memstick pfSense image.

  2. Extract the .img file from the .gz archive first.

  3. Select your USB under Device.

  4. Under Create bootable disk using click on the CD-ROM icon.

  5. Select the extracted .img file that you downloaded.

  6. Click Start and wait for image to be copied to USB.

Using Win32 Disk Imager

Win32 Disk Imager is a Free and easy-to-use program to write disk images in Windows. It also only lists removable drives in its GUI which prevents accidentally overwriting a permanent disk.

  1. Start Win32 Disk Imager, and ensure it is running as Administrator.

  2. Click the folder icon (1).

  3. Navigate to the location of the downloaded image file.

  4. Select the image file.

  5. Choose the target drive (2).

  6. Click Write (3).

    ../_images/imgwriter_03_select_image.png
  7. Wait for the image to finish writing, and a Write Successful dialog will appear.

Warning

The operations in this section will completely overwrite any existing content on the flash drive so be sure that any files previously stored on the drive are backed up elsewhere.

Write the image to the drive using the dd command. It takes this general form:

diskutil unmountDisk <usb_disk_device_name>
dd if=<image_file_name> of=<usb_disk_device_name>
diskutil eject <usb_disk_device_name>

For example:

diskutil unmountDisk /dev/rdisk3
sudo dd if=file1.img of=/dev/rdisk3 bs=4m
diskutil eject /dev/rdisk3

The bs=X is optional and tells dd to perform reads and writes on 4 MB blocks of data at a time. The default block size used by dd is 512 bytes. Specifying a larger block size can significantly increase the writing speed which will result in faster image writing.

Warning

The operations in this section will completely overwrite any existing content on the flash drive so be sure that any files previously stored on the drive are backed up elsewhere.

Write the image to the drive using the dd command from a shell logged in as a user with sudo access or the root user directly. It takes this general form:

sudo dd if=<image_file_name> of=<usb_disk_device_name>

For example:

sudo dd if=file1.img of=/dev/sdb bs=4M

The bs=X is optional and tells dd to perform reads and writes on 4 MB blocks of data at a time. The default block size used by dd is 512 bytes. Specifying a larger block size can significantly increase the writing speed which will result in faster image writing.

If a warning is printed about “trailing garbage” is may be safely ignored, as it is from the file’s digital signature.

Warning

The operations in this section will completely overwrite any existing content on the flash drive so be sure that any files previously stored on the drive are backed up elsewhere.

Write the image to the drive using the dd command. It takes this general form:

dd if=<image_file_name> of=<usb_disk_device_name>

For example:

sudo dd if=file1.img of=/dev/da1 bs=4m

The bs=X is optional and tells dd to perform reads and writes on 4 MB blocks of data at a time. The default block size used by dd is 512 bytes. Specifying a larger block size can significantly increase the writing speed which will result in faster image writing.

If a warning is printed about “trailing garbage” is may be safely ignored, as it is from the file’s digital signature.