FreeBSD Bootable USB Backup: Step-by-Step Guide
In this article
You can turn a USB drive into a bootable backup of your FreeBSD system by creating a bootable memstick image and then copying your data onto it, or by using a tool like dd to clone your existing installation. This gives you a rescue environment and a portable copy of your system that can boot on most hardware. Before you start, you need a USB drive (at least 8 GB for a full backup), the FreeBSD installation image or a working FreeBSD system, and basic familiarity with the command line.
What You'll Need
- A USB flash drive (8 GB or larger recommended; all data on it will be erased).
- A FreeBSD installation ISO or memstick image (download from the official FreeBSD site).
- A working FreeBSD system to prepare the drive (or another Unix-like system with
dd). - Root or sudo access on the system you are using.
- Optional: a second USB drive if you want to keep the installer separate from your backup data.
Step-by-Step
- Identify the USB drive device name. Plug in the USB drive and run
dmesg | tailorcamcontrol devlistto see the new device. On FreeBSD, USB drives typically appear as/dev/da0,/dev/da1, etc. Confirm withgeom disk list. Make absolutely sure you have the right device; using the wrong one will destroy data. - Unmount any mounted partitions on the USB drive. Run
umount /dev/da0s1(adjust to your actual partition). If the drive is not mounted, skip this. - Write the FreeBSD memstick image to the USB drive. Download the
.imgfile (e.g.,FreeBSD-14.0-RELEASE-amd64-memstick.img) and useddto write it:dd if=FreeBSD-14.0-RELEASE-amd64-memstick.img of=/dev/da0 bs=1m conv=sync. This makes the drive bootable with the FreeBSD installer. Wait for it to complete. - Boot from the USB drive to verify it works. Reboot your computer and enter the boot menu (often F12, F10, or Esc during POST) to select the USB drive. If the FreeBSD installer starts, the drive is bootable. You can exit the installer without making changes.
- Create a backup of your system onto the USB drive. You have two options:
- Option A: Clone your entire disk. Boot from the USB installer, choose the "Shell" option, and use
ddto copy your system disk to the USB drive. For example, if your system disk is/dev/ada0and the USB drive is/dev/da0, rundd if=/dev/ada0 of=/dev/da0 bs=1m. This creates an exact copy, but the USB drive must be at least as large as your system disk. - Option B: Copy files manually. Mount your system disk and the USB drive, then use
rsyncorcp -ato copy the entire root filesystem. For example:mount /dev/ada0p2 /mnt(your root partition),mount /dev/da0s1 /media(USB drive), thenrsync -aHAX /mnt/ /media/. This requires the USB drive to have a filesystem (e.g., UFS or ZFS) and enough space. You will also need to make the USB drive bootable separately, which is more complex; Option A is simpler for a bootable backup.
- Option A: Clone your entire disk. Boot from the USB installer, choose the "Shell" option, and use
- Make the USB drive bootable (if not already). If you used Option A, the cloned drive is already bootable. If you used Option B, you need to install a boot loader. Boot from the FreeBSD installer, enter the shell, and run
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 /dev/da0(for GPT) orboot0cfg -B /dev/da0(for MBR). Then ensure the boot partition is marked active. - Test the bootable backup. Reboot your computer with the USB drive attached and select it from the boot menu. The system should start from the USB drive. Log in and verify that your files and settings are present.
- Label the drive and store it safely. Use a permanent marker or a label to note the date and contents. Keep the drive in a dry, cool place. Periodically update the backup by repeating the cloning process.
Common Mistakes
- Writing to the wrong device. Always double-check the device name with
camcontrol devlistorgeom disk listbefore runningdd. Overwriting your system disk is irreversible. - Using a USB drive that is too small. A full clone requires a drive at least as large as the source disk. Check sizes with
diskinfo -v /dev/da0. - Forgetting to unmount. If the USB drive is mounted,
ddmay fail or produce a corrupted image. Unmount all partitions first. - Not testing the bootable drive. Always boot from the USB drive to confirm it works before relying on it.
- Assuming the backup is bootable after a file copy. Copying files does not make a drive bootable; you must install a boot loader and set up partitions correctly.
Tips
- Use a high-quality USB 3.0 drive for faster write speeds and better reliability.
- Keep a second USB drive with the FreeBSD installer for rescue purposes.
- Label your backup with the date and FreeBSD version.
- Consider using
ddwithstatus=progress(if available) to monitor progress. - For regular backups, consider a script that automates the cloning process.
- Store the USB drive in a static-free bag and avoid physical shock.
Troubleshooting
- The USB drive does not appear in
camcontrol devlist. Try a different USB port, check the drive is properly inserted, and rundmesgto see if it was detected. Some drives may need to be reformatted. ddfails with "Operation not permitted". Ensure you are root and that the drive is not mounted.- The system does not boot from the USB drive. Check the boot order in your BIOS/UEFI settings. Ensure the drive is bootable (try booting the installer image first). If you cloned a disk, the boot loader may need to be reinstalled.
- Boot fails with "No bootable device". The boot loader may not be installed correctly. Re-run the bootcode installation steps from the installer shell.
- The backup is missing files. If you used
rsync, ensure you used the correct flags (-aHAX) and that you copied from the root of the filesystem. Check for errors in the output. - The USB drive is not recognized after cloning. The partition table may be corrupted. Re-create the partition table and try again.
Frequently Asked Questions
Can I use any USB drive for a bootable backup?
Most USB flash drives work, but you need one at least as large as your system disk for a full clone. USB 2.0 drives are slower but functional.
Do I need to format the USB drive before cloning?
No, dd overwrites the entire drive, including the partition table. Formatting is not necessary.
Will the bootable backup work on a different computer?
It may work if the hardware is similar, but drivers for different hardware (e.g., storage controllers) might cause boot issues. It is best used on the same or very similar hardware.
How often should I update the backup?
Update it whenever you make significant changes to your system, or on a regular schedule (e.g., monthly). Keep in mind that cloning takes time.
Can I use a USB hard drive instead of a flash drive?
Yes, USB hard drives work the same way and offer more capacity and speed. Just ensure it is recognized as a da device.
Is it possible to make a bootable backup without cloning the entire disk?
Yes, you can create a minimal FreeBSD installation on the USB drive and then copy your data and configuration files. This is more complex but uses less space. However, for a true bootable backup, cloning is the simplest method.