Joined: 05 Apr 2005
|Posted: Wed Feb 01, 2006 12:38 am Post subject: Hack Gentoo CD, backup/restore partition
|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
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
So I decide to hack the Gentoo's minimum installation CD, adding the partimage utility plus custom partition image onto it.
- 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.
1. Reinstall the PC and configure it to the way you like.
- 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):
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:
|./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:
|./partimage -b -z1 -V4400000 -f0 -o save /dev/sda2 xphome_fresh.gz" |
To understand the parameters, you can type:
|./partimage --help" |
-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
|dd if=/dev/sda of=xphome.mbr.bin bs=512 count=1 |
for partition table:
|sfdisk -d /dev/sda > xphome.partition.table |
after done, transfer these two files to the linux box:
|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:
wget [i]<internet location>[/i]/install-x86-minimal-2005.1-r1.iso
mount install-x86-minimal-2005.1-r1.iso loop0 -o loop
find | cpio -pdm ../iso
mount iso/livecd.squashfs loop0 -o loop
find | cpio -pdm ../squash
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:
cp /path/to/xphome_fresh.gz.* WinXPHome/
cp /path/to/xphome.mbr.bin WinXPHome/
cp /path/to/xphome.partition.table WinXPHome/
md5sum -b * > xphome.md5
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:
cp /path/to/partimage usr/bin/
In order to automate the recovery process, I creates the following script in the root folder, called restore:
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:
|chmod 700 restore
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:
|mksquashfs squash/ new.squashfs
mount new.squashfs loop0 -t squashfs -o loop
then replace original squashfs by the new one:
|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):
If all goes well, reconstruct the image:
mkisofs -no-emul-boot -boot-load-size 4 -boot-info-table -r -b isolinux/isolinux.bin -c isolinux/boot.cat -o ../newgentoo.iso .
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
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;
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
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