Monday, January 30, 2012

FreeBSD - Backup and restore FreeBSD using Fixit CD

Since FreeSBIE have not been updated since year 2007, its kernel recognizing new hardware starts to worry me as it is based on FreeBSD 6.2 and it is going to reach EoL (end of life) by end of this year, 2010. Is time to experiment on new way restoring backup.

The FreeBSD installation process does mentioned about "Fixit" CD booting. After meddling around with it, it's actually referring to another bootable CD which its label name consits of "livefs" (Live File System). It's also known as "disk 2" prior to FreeBSD 7.
e.g.
Installation disc -- > 8.0-RELEASE-i386-disc1.iso
Live File systems disc --> 8.0-RELEASE-i386-livefs.iso

Do take note that the dump/restore instruction from the previous post "Freebsd – Backup & restore for disaster recovery" is still valid. This post is served as a "update" as it won't be using FreeSBIE, rather, it will using the livefs to start the restoration of the partition(s).

Without further ado, here's the instruction :

A quick note, after experimenting with a few backup compress method, below are the summary of my findings :
dump and compress using bzip2 (not so good as bzip is the slowest)
dump -0auLf - /dev/ad0s1a | bzip2 > root_partition.bzip2
dump and compress using gzip (good choice as gzip perform faster than bzip2 and the compression is fairly good)
dump -0auLf - /dev/ad0s1a | gzip > root_partition.gzip
plain dump without compression (fast if target disk can write fast enough)
dump -0auLf root_partition.dump /dev/ad0s1a

My preferred compress method will be using gzip as it's compression ratio is good with fair compressing time taken. In this case, the backup of the partition(s) is done with the command :
dump -0auLf - /dev/ad0s1a | gzip > root_partition.gzip


This is the updated version of how to use Live File System CD to start the restoration process :
Partition & Label the disks
Boot the Installation disc (disc 1)
At the "sysinstall Main Menu", go to "Configure --> Fdisk" and perform the following :
Partition the disk as desire.
Next, type "w" to write changes to disk.
BEWARE:this step will wipe all the contents of the hard disk.
Choose "Label" to label the partitions created in the previous step. Perform the following (similar to previous steps) :
Label the partition as desire.
After labeling the partition, note down the partition label. e.g.
ad0s1a --> "/" or root partition

ad0s2b --> swap partition
Move the up/down keys to highlight the "Disk:" and NOT the partition ("ad0s1a").
Next, type "w" to write changes to disk.
Start the Fixit CD
At the main menu, go to "Fixit --> CDROM/DVD"
At the message "Please insert a FreeBSD live filesystem CD/DVD and press return" message, change the installation disc in the drive to Livefs disc (aka disc2).
Then press enter to continue.
Restore the backup
Use the command "mount" to confirm the partitions are mounted accordingly. "/" or root partition should be mounted as /mnt
Create the external mount point & temporary directory. In this scenario, the backup file is stored in a FAT32 formatted USB external hard disk. The temporary directory is for later use with gzip command.
mkdir /tmp/usb /mnt/writable_tmp
Mount the external USB hard disk :
mount_msdosfs /dev/da0s1 /tmp/usb

*** using the usual command to mount USB hard disk "mount -t msdosfs /dev/da0s1 /tmp/usb" will get an error. See below caveats.
The temporary directory environment variable originally points to a read only directory. This result in "restore" command complaining about having not enough disk space to restore.
Re-point it to a writable disk, use the below command :
export TMPDIR=/tmp/writable_tmp/
Start the restoration process :
cd /mnt
gzcat /tmp/usb/root_partition.gzip | restore -rvf -
Repeat the previous step for the rest of the partitions until all partitions are restored.

CAVEATS :
When executing the command :
mount -t msdosfs /dev/da0s1 /tmp/usb

An error return :
mount: exec mount_msdosfs not found in /sbin:/usr/sbin: No such file or directory

For some reason, mount_msdosfs is in /mnt2/sbin/ but "mount" cannot find it.
Solution 1 :
Replace the "mount" command with equivalent "mount_msdosfs". Execute it without the need to specify parameter "-t msdosfs"
e.g.
mount_msdosfs /dev/da0s1 /tmp/usb

Solution 2
Soft link the command "mount_msdosfs" to the same directory where mount resides :
cd /sbin;ln -s /mnt2/sbin/mount_msdosfs mount_msdosfs

then mount it again with the usual command.

Nemaste !!!

Reference:
http://scratching.psybermonkey.net/2010/01/freebsd-backup-and-restore-freebsd.html

No comments: