How to mirror the FreeBSD OS on two disks
lordofhyphens at gmail.com
Thu Jul 12 14:21:59 UTC 2012
On 07/12/2012 05:47 AM, Mike Clarke wrote:
> On Wednesday 11 July 2012 16:20:41 Joseph Lenox wrote:
>> What about a ZFS root? Just make sure both disks are in the BIOS/EFT
>> boot order.
>> Something else we noticed on our site is that backup of a system
>> snapshot can be quickly restored using just a live CD (do up to step 5,
>> then replace steps 6-7 with a zfs receive of the desired snapshot).
> Since the system is to be restored from the snapshot then I suppose most of
> steps 8 to 12 wouldn't be needed either. But what about step 5 before the
> zpool export zroot
> zpool import -o cachefile=/var/tmp/zpool.cache zroot
> And then step 10 after running zfs receive
> cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache
> Are these steps needed when restoring from a snapshot?
I believe preserving the zpool cache is important, but I haven't tested
not doing so. Logically, the zroot is still new, and the restore from
snapshot would still populate the cachefile (which would default to
writing in the live CD's /var/tmp, not the target system's /var/tmp.
Here's my suggested instructions, adapted from
http://www.aisecure.net/2012/01/16/rootzfs/ and my own experimentation,
for restoring from a snapshot. It can also be used to clone a system
configuration from one system to another (very convenient). This is for
single-drive, just set up a mirror in the initial steps if you are going
1. Boot from a FreeBSD9 installation DVD or memstick and choose "Live CD".
2. Create the necessary partitions on the disk(s) and add ZFS aware
gpart create -s gpt ada0
gpart add -b 34 -s 94 -t freebsd-boot ada0
gpart add -t freebsd-zfs -l disk0 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
3. Align the Disks for 4K and create the pool.
gnop create -S 4096 /dev/gpt/disk0
zpool create -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot /dev/gpt/disk0.nop
zpool export zroot
gnop destroy /dev/gpt/disk0.nop
zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot
4. Set the bootfs property on zroot.
zpool set bootfs=zroot zroot
5. Mount the memory stick containing the snapshot. Most memory sticks
are formatted fat32 or ntfs, and the LiveCD will at least read ntfs.
mount -t ntfs /da0s1 /media/
* This assumes that the memory stick is NTFS formatted and it ends
up as da0 in the system.
6. Receive snapshot.
gunzip -dc /media/snapshot_name.gz | zfs receive -vF zroot
* snapshot_name.gz is a placeholder for the actual name of the
file on the media. I've assumed that the snapshot is gzip'd,
otherwise cat the snapshot file.
7. Copy zpool.cache (very important!!!)
cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache
8. If this is a clone of another system, edit pre-existing rc.conf and
rc.local.conf files to suit new network configuration.
* Specifically, the hostname and the IP need to change if the new
system is on the network.
* Remember to set the correct boot drive in new system BIOS.
--Joseph Lenox, BS, MS
I'm an engineer. I solve problems.
More information about the freebsd-questions