How to Create a Bootable FreeBSD Image to a USB Disk Using dd Command

The dd utility can be used to create a bootable USB Disk, the dd command copies standard input to standard output. Input data is read and written in 512-byte blocks. If the input reading is short, the input from many readings is aggregated to form an output block. Once complete, dd displays the number of complete input and output blocks and a portion of the input record truncated to the output.

In Unix commands, the dd utility is often called a disk/data duplicator, this allows us to copy raw data from one source to another. The dd utility is widely used in Unix tasks such as:
  1. Can work with tape backup.
  2. Convert between systems that use different byte orders.
  3. Backing up the boot sector.
  4. Reads data from an inaccessible or corrupted file system.
To create a bootable USB, we generally use GUI applications such as Linux Live USB Creator and other applications available for Linux, FreeBSD, and Windows. A bootable USB is required whenever there is a need for installation of a new operating system or if we want to run the operating system directly.

In Unix-like operating systems, dd is a command line utility used to convert and copy files. It is a powerful tool that can be used for various purposes like backing up and restoring disks, converting data formats, converting file cases, etc. The best thing is that it comes pre-installed with many Linux distributions.

In this article, we will discuss how to create a bootable USB disk using the dd utility on a FreeBSD system.

1. View USB Disk List

Before creating a bootable USB disk, look at the USB Disk list, so that we don't create the wrong bootable disk. Type the following command to view the USB Disk.

root@ns2:~ # dmesg
da0: <JetFlash Transcend 16GB 1100> Removable Direct Access SPC-4 SCSI device
da0: Serial Number 17TYRSE65DEAAUTI
da0: 40.000MB/s transfers
da0: 15056MB (30834688 512 byte sectors)
da0: quirks=0x12<NO_6_BYTE,NO_RC16>

The dmesg command reads a USB Flash Drive named "da0" FreeBSD stores the USB Disk data in the /dev/da0 folder Transcend brand size 16GB. To read the characteristics of the Transcend Flash Disk, use the diskinfo script.

root@ns2:/dev # diskinfo -v da0
512 # sectorsize
15787360256 # mediasize in bytes (15G)
30834688 # mediasize in sectors
0 # stripesize
0 # stripeoffset
1919 # Cylinders according to firmware.
255 # Heads according to firmware.
63 # Sectors according to firmware.
JetFlash Transcend 16GB # Disk descr.
17TYRSE65DEAAUTI # Disk ident.
umass-sim0 # Attachment
No # TRIM/UNMAP support
Unknown # Rotation rate in RPM
Not_Zoned # Zone Mode

FreeBSD considers USB devices to be viewed as SCSI devices, the camcontrol script can be used to view a list of USB Stick Disk device information, use the script below.

root@ns2:/dev # camcontrol devlist
<ST3120813AS 3.AAD> at scbus1 target 0 lun 0 (pass0,ada0)
<JetFlash Transcend 16GB 1100> at scbus6 target 0 lun 0 (da0,pass1)

Or you can also use the geom command.

root@ns2:/dev # geom disk list
Geom name: ada0
1. Name: ada0
Mediasize: 120034123776 (112G)
Sectorsize: 512
Mode: r2w2e3
descr: ST3120813AS
ident: 5LS10CHW
rotationrate: unknown
fwsectors: 63
fwheads: 16

Geom name: da0
1. Name: da0
Mediasize: 15787360256 (15G)
Sectorsize: 512
Mode: r0w0e0
descr: JetFlash Transcend 16GB
lunid: 2020030102060804
rotationrate: unknown
fwsectors: 63
fwheads: 255

2. Format USB Disk

Before formatting the USB disk, first look at the USB disk partition with the gpart command.

root@ns2:/dev # gpart show da0
=> 3 30834683 da0 GPT (15G)
3 26 1 freebsd-boot (13K)
29 51 - free - (26K)
80 4096 2 efi (2.0M)
4176 30830510 - free - (15G)
In the display above da0 is a USB disk drive and is formatted with the efi system file. To format a USB disk, we will provide several options.

a. Format With FAT32
For Windows systems, it only reads the FAT32 system file format, so that the file contents of our USB disk can be read on Windows, the format used is FAT32, the following is an example of the FAT32 format.

root@ns2:~ # gpart destroy -F /dev/da0
da0 destroyed
root@ns2:~ # gpart create -s mbr /dev/da0
da0 created
root@ns2:~ # gpart add -t fat32 /dev/da0
da0s1 added
root@ns2:~ # newfs_msdos -L FILES -F 32 /dev/da0s1
/dev/da0s1: 30827008 sectors in 481672 FAT32 clusters (32768 bytes/cluster)
BytesPerSec=512 SecPerClust=64 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=30834625 FATsecs=3764 RootCluster=2 FSInfo=1 Backup=2
Now let's look at the partition of the USB disk, whether it uses the FAT32 system.

root@ns2:~ # gpart show da0
=> 63 30834625 da0 MBR (15G)
63 30834625 1 fat32 (15G
In the gpat show command above, our USB disk has been partitioned with FAT32 system files, if our USB disk contains files, automatically when opened in Windows it will immediately read the contents of the files on the USB disk.

b. Format With UFS
Next, we will format the USB Disk with the UFS file system.

root@ns2:~ # gpart destroy -F /dev/da0
da0 destroyed
root@ns2:~ # gpart create -s gpt da0
da0 created
root@ns2:~ # gpart add -t freebsd-boot -s 512k da0
da0p1 added
root@ns2:~ # gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0
partcode written to da0p1
bootcode written to da0
root@ns2:~ # gpart add -t freebsd-ufs -b 1M -s 7G da0
da0p2 added
root@ns2:~ # gpart add -t freebsd-swap da0
da0p3 added
root@ns2:~ # newfs -U /dev/da0p2
/dev/da0p2: 7168.0MB (14680064 sectors) block size 32768, fragment size 4096
using 12 cylinder groups of 625.22MB, 20007 blks, 80128 inodes.
with soft updates
super-block backups (for fsck_ffs -b #) at:
192, 1280640, 2561088, 3841536, 5121984, 6402432, 7682880, 8963328, 10243776, 11524224, 12804672, 14085120
Check whether the USB disk is partitioned with UFS system files, use the gpart show script.

root@ns2:~ # gpart show da0
=> 40 30834608 da0 GPT (15G)
40 1024 1 freebsd-boot (512K)
1064 984 - free - (492K)
2048 14680064 2 freebsd-ufs (7.0G)
14682112 16152536 3 freebsd-swap (7.7G)
The gpart show script shows that our USB disk has been partitioned with UFS system files.

b. Format With EFI
Next, we will format the USB Disk with the UFS file system. Follow these steps.

root@ns2:~ # gpart destroy -F /dev/da0
da0 destroyed
root@ns2:~ # gpart create -s gpt /dev/da0
da0 created
root@ns2:~ # gpart add -t efi -l efiboot -a 4k -s 100M /dev/da0
da0p1 added
root@ns2:~ # newfs_msdos -F 16 -c 1 /dev/da0p1
newfs_msdos: warning: FAT type limits file system to 66069 sectors
/dev/da0p1: 65524 sectors in 65524 FAT16 clusters (512 bytes/cluster)
BytesPerSec=512 SecPerClust=1 ResSectors=1 FATs=2 RootDirEnts=512 Media=0xf0 FATsecs=256 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=66069
root@ns2:~ # mount -t msdosfs /dev/da0p1 /mnt
root@ns2:~ # mkdir -p /mnt/EFI/BOOT
root@ns2:~ # cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
root@ns2:~ # umount /mnt
root@ns2:~ #
Check partition

root@ns2:~ # gpart show da0
=> 40 30834608 da0 GPT (15G)
40 204800 1 efi (100M)
204840 30629808 - free - (15G)

3. Download FreeBSD img File

The next step is to download the FreeBSD master file. In this step, try to make sure the FreeBSD file has the extension "img", because if it has the extension "iso" the dd command will not be able to create a bootable USB disk. You can download the FreeBSD file from Windows, then when finished we transfer it to the FreeBSD computer with WINSCP.

If you want to download FreeBSD files directly from the FreeBSD system, you can use the wget or lynx command. In this case, an example will be given of downloading the FreeBSD.img file using the wget command.

root@ns2:~ # cd /tmp
root@ns2:/tmp # wget
--2023-07-04 12:42:17--
Resolving (, 2404:a8:3ff::15:0
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1280627200 (1.2G) [application/octet-stream]
Saving to: ‘FreeBSD-13.2-RELEASE-amd64-memstick.img’

FreeBSD-13.2-RELEASE-amd64-memstick.img 2%[=> ] 29.63M 4.83MB/s eta 3m 17s
Wait until the download process is complete, when it is finished the file FreeBSD-13.2-RELEASE-amd64-memstick.img will be saved in the /tmp folder. Next, we create a bootable USB disk. Follow the commands below to create a Bootable USB Flash Disk.

root@ns2:~ # cd /tmp
root@ns2:/tmp # dd if=FreeBSD-13.2-RELEASE-amd64-memstick.img of=/dev/da0 bs=1M conv=sync status=progress
26214400 bytes (26 MB, 25 MiB) transferred 1.055s, 25 MB/s
31+0 records in
31+0 records out
32505856 bytes transferred in 1.522773 secs (21346492 bytes/sec)
When you have finished creating the Bootable USB Disk, install it on the FreeBSD computer. Insert the Falsh Disk Drive in the USB slot, turn on the computer and enter the BIOS. In the bios menu, select boot or the first boot is directed to the Flash Disk, then save the bios changes. The computer will automatically read the Flash Disk Drive, follow the instructions in the FreeBSD installation process, if you are still confused about how to install FreeBSD, you can read the article that reviews FreeBSD installation.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post