OpenBSD 5.5 and later | cloning a disk the easy way


ATTENTION! Your default kernel always uses the root device per default from which he origins. This is hardcoded. You can change this at boot time using the boot -a (man boot) command at the boot prompt. It is NOT possible to script this (even using the /etc/boot.conf). This is not really a problem, if your master disk fails, the kernel switches to the next available root device. But if you switch the master/clone disks after cloning in their machine slots, it will boot from the cloned (the 'new' master), but will use the still existing old master disk (the 'new' clone) as root device. That's a little bit confusing. Hint: If your master disk crashes, reclone it from the slave and put it into the first slot and let them run as the master.

#!/bin/sh

DISKLABEL=$(which disklabel)
FDISK=$(which fdisk)
DUMP=$(which dump)
RESTORE=$(which restore)
NEWFS=$(which newfs)
MOUNT=$(which mount)
UMOUNT=$(which umount)
DUMP=$(which dump)
RESTORE=$(which restore)

MNT=”/mnt”
LABEL=”/tmp/label”

if [ $# -lt 2 ]; then
echo “usage: do_clone.sh FROM TO”
echo “example: do_clone.sh wd0 wd1”
exit
fi

SRC=$1
$DISKLABEL $SRC > /dev/null || exit

TAR=$2
$DISKLABEL $TAR > /dev/null || exit

$DISKLABEL $SRC > $LABEL

$FDISK -yi $TAR

$DISKLABEL -R $TAR $LABEL

$UMOUNT $MNT

cat $LABEL | grep ‘ # /’ | (
while read LINE; do
#echo “$LINE”
ID=${LINE%%\:*}
PATH=”/${LINE#*\/}”
SLICE=”${TAR}$ID”
echo “$SLICE is $PATH”
$NEWFS -q $SLICE
$MOUNT /dev/$SLICE $MNT
($DUMP -0f – $PATH )|(cd $MNT; $RESTORE -rf -)
$UMOUNT $MNT;
done $MNT/etc/fstab

cp /usr/mdec/boot $MNT/boot

$UMOUNT $MNT

$(which installboot) -v /dev/${TAR}a /usr/mdec/biosboot

exit

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s