Jul 102012
 

OpenBSD edition. A script that will produce a copy of an original disk, will run installboot(8) on it and replace the disk UID in /etc/fstab with the clone’s UID. The purpose is to produce a copy of the current system disk ready to replace it by simply changing the boot device or replacing the original in case of failure.

Intended for live disks, an alternative to cloning a disk in OpenBSD using dd.

EXECUTING IT WITHOUT UNDERSTANDING WHAT IT DOES WILL LIKELY RESULT IN DATA LOSS, HAIR LOSS, TEETH LOSS AND POSSIBLE OTHER KINDS OF LOSS.

There are two failsafes built in, firstly it won’t do anything unless run with ‘yarly’ as the first parameter, second it will ask for confirmation warning that all data on the destination disk will be lost, unless run with ‘cron’ as the second parameter.

It’s not ready to run as-is, variables will need to be properly set before executing.

It will erase MBR and all partitioning data on DST_DISK and will copy the scheme from SRC_DISK over. My disks are the same size, DST_DISK can’t be of lower size than SRC_DISK, obviously, if it’s bigger some space will be left unused. After that it will run newfs on DST_DISK on all partitions of type 4.2BSD, everything else, like swap, will be left untouched. Each such partition will be mounted to DST_MOUNT and the data from the corresponding partition on SRC_DISK will be dumped over. If the current partition is the root partition and after dumping/restoring there’s /boot on it, the script will run installboot(8). If there’s an /etc/fstab file, it will replace all instances of SRC_DISK’s duid in it with DST_DISK’s. This should leave the disc ready to be booted with a working system on it.
Most commands the script runs are redirected to STDOUT, changing this variable to /dev/null will make the commands basically silent, but stderr is not redirected, which is probably a good thing.

It is entirely possible that something will go amiss with non-standard partitioning schemes, it does make a few assumptions, like /etc being part of / for example, or that the partitions to be backed up are already mounted.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)