Automatically Simple Since 2002
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 “dump_all.sh”. 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 restore_all.sh. 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 dump_all.sh.
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.
dump_all.sh:
#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
restore_all.sh:
#!/bin/sh
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 ]
then
mkdir tmp
fi
TMPDIR=/mnt/tmp
export TMPDIR
if [ ! -d root ]
then
mkdir root
fi
mount /dev/mfid0s1a root
gzcat slash.dump.gz | (cd root && restore -rf -)
if [ ! -d root/var ]
then
mkdir root/var
fi
mount /dev/mfid0s1d root/var
gzcat slash.var.dump.gz | (cd root/var && restore -rf -)
if [ ! -d root/usr ]
then
mkdir root/usr
fi
mount /dev/mfid0s1e root/usr
gzcat slash.usr.dump.gz | (cd root/usr && restore -rf -)