OpenBSD 5.1 and earlier | Cloning a disk the easy way

#!/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

#echo “$DISKLABEL $SRC > $LABEL”
$DISKLABEL $SRC > $LABEL

#echo “$FDISK -yi $TAR”
$FDISK -i $TAR

#echo “$DISKLABEL -R $TAR $LABEL”
$DISKLABEL -R $TAR $LABEL

#echo “$UMOUNT $MNT”
$UMOUNT $MNT

mount | grep "$SRC" | (
while read LINE; do
DEVICE=${LINE%%\ *}
ID=${DEVICE#\/dev\/$SRC*}
PATH=${LINE%\ type*}; PATH=${PATH##*\ }
SLICE="${TAR}$ID"
# echo "$SLICE is $PATH"

#echo "$NEWFS -q $SLICE"
$NEWFS -q $SLICE

#echo "$MOUNT /dev/$SLICE $MNT"
$MOUNT /dev/$SLICE $MNT

#echo "($DUMP -0f – $PATH )|(cd $MNT; $RESTORE -rf -)"
($DUMP -0f – $PATH )|(cd $MNT; $RESTORE -rf -)

#echo "$UMOUNT $MNT"
$UMOUNT $MNT;
done $MNT/etc/fstab
cat /etc/fstab > $MNT/etc/fstab

#echo “cp /usr/mdec/boot $MNT/boot”
cp /usr/mdec/boot $MNT/boot

#echo “/usr/mdec/installboot -v $MNT/boot /usr/mdec/biosboot $TAR”
/usr/mdec/installboot -v $MNT/boot /usr/mdec/biosboot $TAR

#echo “$UMOUNT $MNT”
$UMOUNT $MNT

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