The Rub

Automatically Simple Since 2002

Simple FreeBSD Clone Script

27 January 2011

I wrote these to do a simple system clone using a USB disk. It’s pretty simple using dump and restore, but it does take a bit to get all of the commands and arguments correct.

To use, install the two scripts on a USB drive. Mount the USB drive on the source system, and run “”. Be sure to change the labels to match your configuration.

To restore, boot a FreeBSD DVD into Fixit mode, mount the USB drive to /mnt, and run Again, be sure to change the device labels to match your system. If your disks are different sizes, you’ll also have to modify the bsdlabel file that is generated by

Warning: Do not blindly run these scripts. They’re posted here for reference only, and will break your system if you do not understand how to use them.

#Filesystem       Size    Used   Avail Capacity  Mounted on
#/dev/mfid0s1a    496M    267M    190M    58%    /
#devfs            1.0K    1.0K      0B   100%    /dev
#/dev/mfid0s1e    9.7G    1.7G    7.2G    19%    /usr
#/dev/mfid0s1d    1.9G    102M    1.7G     6%    /var
#/dev/da0          45G    865M     41G     2%    /mnt

dump -0Lauf - /dev/mfid0s1a | gzip > slash.dump.gz
dump -0Lauf - /dev/mfid0s1d | gzip > slash.var.dump.gz
dump -0Lauf - /dev/mfid0s1e | gzip > slash.usr.dump.gz
bsdlabel mdif0s1 > mfid0s1.bsdlabel

set -o errexit

dd if=/dev/zero of=/dev/mfid0 count=4
fdisk -BI /dev/mfid0
bsdlabel -B -w mfid0s1
bsdlabel -R mfid0s1 mfid0s1.bsdlabel
newfs /dev/mfid0s1a
newfs -U /dev/mfid0s1d
newfs -U /dev/mfid0s1e

if [ ! -d tmp ]
    mkdir tmp
export TMPDIR

if [ ! -d root ]
    mkdir root
mount /dev/mfid0s1a root
gzcat slash.dump.gz | (cd root && restore -rf -)

if [ ! -d root/var ]
    mkdir root/var
mount /dev/mfid0s1d root/var
gzcat slash.var.dump.gz | (cd root/var && restore -rf -)

if [ ! -d root/usr ]
    mkdir root/usr
mount /dev/mfid0s1e root/usr
gzcat slash.usr.dump.gz | (cd root/usr && restore -rf -)