Roll-Your-Own Automated System Restore Discs

by ternarybit

Before we get started, a note on security.

If such a restore disc were to fall into unauthorized hands, your entire setup is compromised.  I strongly urge you to either encrypt your entire partition, or store all sensitive data in encrypted containers (but you do that anyway, right?).  Now, let's get started...

What you will need:

Note:  I have had problems with the 3.00.XX script, but get the ISO anyway to use the newer kernel (see below).

Prepare the Partition for Imaging

Note:  PING supports most filesystems, but not EXT4 yet.  Delete any chaff before imaging, to shrink the overall image size.  Here are some tips:

Reboot several times to double-check that everything works fine.  This is very important on NTFS partitions, since a dirty flag will annoy PING.

Create the System Restore Image

Boot PING and follow the prompts.

I like to get a shell so that I can review the log at /tmp/x.log.

Be sure to press "Space" to select items from multiple options.  Don't use spaces in your image name.

gzip gives the best mix of compression to speed and bzip2 will give you best compression for a heavy speed penalty.

The image size will almost always be considerably less than the amount of used space on your partition(s).  I usually see a 30-50% compression ratio with gzip, and blank sectors are always skipped when using partimage (but not zsplit, so don't use it).

Customize PING

Inside your image's directory (named whatever you typed for image name above) you should find a file called: bios

Delete this unless you want your BIOS settings reset when you run your restore discs.

Now let's extract PING to start meddling:

# mount -o loop -t iso9660 /path/to/PING-2.01.iso /mnt/loop0
$ mkdir /tmp/ext && cp /mnt/loop0/* /tmp/ext
# umount /mnt/loop0
$ cd /tmp/ext && gzip -d initrd.gz
# mount -o loop initrd /mnt/loop0
$ mkdir /tmp/rootfs && cd /tmp/rootfs
$ tar xvfj /mnt/loop0/rootfs.tar.bz2

If we consider /tmp/ext our root, the file we need to edit first is etc/ping.conf.

Uncomment line 89 (After_Completion=Reboot), line 159 (AUTO=Y) to suppress PING prompts, and line 176 (Restore_Only=Y).

The PING script is located in two places: opt/PING/rc.ping and etc/rc.d/rc.ping.

Edit the splash screen (line 333-343) as you see fit.

At this point, merely pressing the "Enter" key would start an irreversible procedure that destroys the existing partition(s).

For my family, and others, I like more of a confirmation.

Add: Type 'yes' to continue, or anything else to quit.

And add this below line 345:

my $Grab = <STDIN>;
unless($Grab =~/yes/i)
{
  print "Your system will now reboot. Please remove your disc.\n";
  system("eject /dev/$CD_Dev");
  sleep(7);
  system("shutdown -r now");
}

Also, I like to add a confirmation message and a similar eject/sleep/reboot command after restore.

Go to line 4609 and add something like this:

if($After_Completion =~/reboot/i)
{
  system(clear);
  print "\n\nSystem restore completed successfully! Your computer will now restart. Please remove your disc.\n";
  system("eject /dev/$CD_Dev");
  sleep(7);
  system("shutdown -r now");
}

Once satisfied, copy: etc/rc.d/rc.ping to opt/PING/rc.ping

Now let's repack:

$ tar cvf - * | bzip2 -9 - > /mnt/loop/rootfs.tar.bz2
# umount /mnt/loop0
$ tar -9 /tmp/ext/initrd

Copy everything except boot.catalog from /tmp/ext (initrd.gz, kernel, isolinux.bin) into your image directory.

Consider using the newest kernel from the 3.00.XX ISO.  Create a file in the image directory called isolinux.cfg and add this to it:

DEFAULT rescue
PROMPT 0
LABEL rescue
KERNEL kernel
APPEND vga=normal devfs=nomount pxe ramdisk_size=33000 load_ramdisk=1
init=/linuxrc prompt_ramdisk=0 initrd=initrd.gz root=/dev/ram0 rw noapic
lba

Note that the APPEND line is all one line.

Finally, cd to the image directory and create a bootable ISO:

$ genisoimage -r -b isolinux.bin -boot-info-table -no-emul-boot-boot-load-size 4 -l RESTORE -o ../restore_disc.iso .

Remember the trailing period.

If your image exceeds the capacity of one disc, create multiple directories, split the *.xxx image files into them (up to the capacity of the discs), and add a blank file called MULTI to every directory except the last one.

Then copy the boot files (initrd.gz, etc.) to the first directory, make that ISO as described above, and make the other discs with:

$ genisoimage -r -l RESTORE_X -o ../disc_x.iso .

Roast, test, and enjoy!

Final Thoughts

Greets: JC, pronix, dad, CST, James V.

Return to $2600 Index