Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Hack Gentoo CD, backup/restore partition
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
chaonis
n00b
n00b


Joined: 05 Apr 2005
Posts: 36

PostPosted: Wed Feb 01, 2006 12:38 am    Post subject: Hack Gentoo CD, backup/restore partition Reply with quote

This HOWTO is used for serving the future me and whoever found it useful.
It is based on https://forums.gentoo.org/viewtopic.php?t=21327

Purpose
From time to time, windows users wanted me to reinstall their corrupted OS due to virus attack, over-stuffed software, spyware, addons, etc. to gain the performance back. Finally I decide to create a recovery CD, much like those CDs come with the brand-name PCs, for them to use so that they can do it themselves, if desired. Also, I don't want to spend too much time hacking the boot-cd and would like to have a linux cd always available wherever I go :D

So I decide to hack the Gentoo's minimum installation CD, adding the partimage utility plus custom partition image onto it.

Requirements
  • Gentoo minimum installation CD 2005.1;
  • partimage 0.6.4;
  • a linux box network reachable by the PC being backup.

Note that the linux box's kernel must support squashfs, loopback device and has myisofs installed, and of course, has enough disk space for the backuped disk image.

Procedure
1. Reinstall the PC and configure it to the way you like.
example:
  • install WinXP Home and all required drivers;
  • register WinXP; update WinXP;
  • install firefox, thunderbird, skype, picasa, winamp, open-office;
  • install antivirus program and update virus definition file;
  • register all prorams so that next you don't have to do it again - this is usually done by opening the program;
  • clean up all traces: clean up internet cache, history, temp files, do disk clean-up, etc.;
  • partition defragment;
  • shutdown the PC.

2. Setup the network linux box for receiving the image file.
If firewall is not used on the linux box, all you need to do is run the daemon program (no root required):
Code:
./partimaged

If firewall is used, you need to either open the default port or use different port for partimaged.
The following will give you some help:
Code:
./partimaged --help"

3. Prepare for image backup
  • Boot the PC into linux mode. You can use Gentoo minimum installation boot CD or any other CDs
    After the boot, hopefully your PC's network card is recognized and your PC is connected to the network. Otherwise, you need to get the network up and running by yourself and modify the boot script later on when you are constructing the new boot image. There are plenty of HOWTOs online that can help, if you need one.
  • Do a wget to download the partimage from its homesite.
  • Extract partimage from the package

4. Backup the image.
You can either do it in graphic mode or batch mode. Here I use batch mode:
Code:
./partimage -b -z1 -V4400000 -f0 -o save /dev/sda2 xphome_fresh.gz"

To understand the parameters, you can type:
Code:
./partimage --help"

In short:
    -b for batch mode;
    -z1 for gzip compression;
    -V4100000 to create the image(s) that fits in a DVD-R (change to 667000 for CDR);
    -f0 to exit program after done;
    -o to overwrite the existing image file on the linux box;
    save to backup image
    /dev/sda2 is the partition to backup (second primary partition on the SATA drive);
    xphome_fresh.gz is the name of the image file; change to whatever you like.

After the image is backed up to the linux box, you need to backup the master boot record and the partition table as well:
5. Backup MBR and partition table
for MBR:
Code:
dd if=/dev/sda of=xphome.mbr.bin bs=512 count=1

for partition table:
Code:
sfdisk -d /dev/sda > xphome.partition.table

after done, transfer these two files to the linux box:
Code:
scp xphome.mbr.bin <network>:<location>
scp xphome.partition.table <network>:<location>

Change <network> to the linux box's name and <location> to the actual location you want to store the files.
Now we can move to the linux box to post-process the backup files:
6. Extract Gentoo minimum CD
get the install-x86-minimal-2005.1-r1.iso and mount it:
Code:
mkdir xphome
cd xphome
wget [i]<internet location>[/i]/install-x86-minimal-2005.1-r1.iso
mkdir loop0
mount install-x86-minimal-2005.1-r1.iso loop0 -o loop
mkdir iso
cd loop0
find | cpio -pdm ../iso
cd ..
umount loop0
mount iso/livecd.squashfs loop0 -o loop
mkdir squash
cd loop0
find | cpio -pdm ../squash
cd ..
umount loop0

Up to this point, you will have two folders containing information for the boot CD:
  • iso\ contains the files will be seen in /mnt/cdrom after boot from the to-be-created boot CD;
  • squash\ contains the files for the boot system.

We first copy the backup image files to the iso\ folder:
Code:
cd iso
mkdir WinXPHome
cp /path/to/xphome_fresh.gz.* WinXPHome/
cp /path/to/xphome.mbr.bin WinXPHome/
cp /path/to/xphome.partition.table WinXPHome/
cd WinXPHome
md5sum -b * > xphome.md5
cd ../..

md5sum is to guarantee there is no corruption on the backup files when we use them.
Now we need to add the partimage program to the boot CD:
Code:
cd squash
cp /path/to/partimage usr/bin/

In order to automate the recovery process, I creates the following script in the root folder, called restore:
Code:
cd root
vi restore


Quote:
#!/bin/sh
cd /mnt/cdrom/WinXPHome
md5sum -c xphome.md5 && \
dd if=xphome.mbr.bin of=/dev/sda && \
sfdisk /dev/sda < xphome.partition.table && \
partimage -b -f1 restore /dev/sda2 xphome_fresh.gz.000

and make the script execuable:
Code:
chmod 700 restore
cd ../..

What the script does is do a md5sum check on the backup files; if all goes well, restore MBR, restore partition table, restore partition image. After all done and no error, the PC will shut itself down (-f1 option). Or it will break at the error point.
Once all set, we can now reconstruct the boot CD:
7. Creating boot image
First reconstructing the squashfs and vertify the contents:
Code:
mksquashfs squash/ new.squashfs
mount new.squashfs loop0 -t squashfs -o loop
ls loop0/root/
ls loop0/usr/bin/
umount loop0

then replace original squashfs by the new one:
Code:
cp new.squashfs iso/livecd.squashfs

Now it is a good time to check if your new image is going to fit into the media (DVD-R or CDR):
Code:
du iso -s

If all goes well, reconstruct the image:
Code:
cd iso
mkisofs -no-emul-boot -boot-load-size 4 -boot-info-table -r -b isolinux/isolinux.bin -c isolinux/boot.cat -o ../newgentoo.iso .
cd ..

Pay attention to the "." to the end of the "mkisofs" line.
Now burn the newgentoo.iso to the media by the mean you can handle :D
8. Explain to the end user
When the restore time comes, ask them to:
  • boot the CD/DVD you just created
  • wait until the root prompt shows up;
  • type
    Code:
    ./restore

  • wait until the system shut itself down;
  • enjoy the freshly new XP;

If anything goes wrong, it is your time to go solve the problem and make them think they cannot live without you :D
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum