Here's how I make a drive clone using partimage on
system rescue cd or the knoppix cd.
1. Setup the operating systems and boot loader
2. Put a formatted partition on a second drive. Make the scripts executable with the command:
chmod +x save and chmod +x restore. Copy these scripts the the second drive. For example: /dev/hdb1
3. Boot up with system rescue cd and run the command:
mount /dev/hdb1 /mnt/images -t ext3
4. Run the
save script with the command:
./save /dev/hda
5. After you have saved the images, remove the
master drive ( the one which has the operating system on it )
6. Install a new master drive
/dev/hda Note: make sure it is detected properly in the bios.
7. Run the
restore script with the command:
./restore /dev/hda
here is the save script
Code:
#!/bin/bash
##### This saves the MBR / Partition Table
##### and all partitions using partimage
##### example: ./save /dev/hda
##############################################
# Ensure that root is running the script.
#
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo
echo "You must be root to run this!"
echo
exit 1
fi
##############################################
usage()
{
echo "Usage: $0 /dev/hd#"
exit 1;
}
test "$1" || usage
if ! [ -e $1 ]; then
echo "$1 does not exist. Exiting."
exit 1
fi
if [ -e $1 ]; then
#Save the MBR with partition table
mbrfile=`echo -e $1 | awk -F"/" '{print $3}'`;
dd if=$1 of=/mnt/images/mbr_$mbrfile bs=512 count=1
clear
for i in `/sbin/sfdisk -l $1 | \
grep -e "^[/dev]" | awk '{print $1}'`;
do
a=`/sbin/sfdisk -s $i 2> /dev/null`
test=$(($a + 0))
stuff=`echo -e $i | sed -e 's/.\{8\}//'`;
check=`sfdisk -c $1 $stuff`
if [ $check != 5 -a $check != 82 -a $test != 0 ];then
part=`echo -e $i | awk -F"/" '{print $3}'`;
#Save the partitions
#use this method for GUI progress
partimage save -c -b -d -z0 -f3 $i /mnt/images/$part
#use this method for command line progress
#partimage save -B=foo -c -b -d -z0 -f3 $i /mnt/images/$part
clear
fi
done
echo
else
exit 1
fi
clear
echo "The save operation is complete"
echo "The images have been saved in /mnt/images/"
echo
exit 0
Here is the restore script
Code:
#!/bin/bash
##### This retores the MBR / Partition Table
##### and all partitions using partimage
##### example: ./restore /dev/hda
##############################################
# Ensure that root is running the script.
#
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo
echo "You must be root to run this!"
echo
exit 1
fi
##############################################
usage()
{
echo "Usage: $0 /dev/hd#"
exit 1;
}
test "$1" || usage
if ! [ -e $1 ]; then
echo "$1 does not exist. Exiting."
exit 1
fi
if [ -e $1 ]; then
clear
echo
echo "********************************************************************"
echo " Caution!!! This program will erase your hard drive"
echo
echo -n " Do you want to proceed (Y/N)?"
read answer
if test "$answer" != "Y" -a "$answer" != "y";
then exit 0;
fi
#
clear
mbrfile=`echo -e $1 | awk -F"/" '{print $3}'`;
#Erase the old boot sector
dd if=/dev/zero of=$1 bs=512 count=1
#Restore the MBR with partition table
dd if=/mnt/images/mbr_$mbrfile of=$1 bs=512 count=1
clear
for i in `/sbin/sfdisk -l $1 | \
grep -e "^[/dev]" | awk '{print $1}'`;
do
a=`/sbin/sfdisk -s $i 2> /dev/null`
test=$(($a + 0))
stuff=`echo -e $i | sed -e 's/.\{8\}//'`;
check=`sfdisk -c $1 $stuff`
if [ $check = 82 ];then
#setup the swap partition
/sbin/mkswap $i
elif [ $check != 5 -a $check != 82 -a $test != 0 ];then
part=`echo -e $i | awk -F"/" '{print $3}'`;
#Restore the partitions
#use this method for GUI progress
partimage restore -b -f3 $i /mnt/images/$part.000
#use this method for command line progress
#partimage restore -B=foo -b -f3 $i /mnt/images/$part.000
clear
fi
done
echo
else
exit 1
fi
clear
echo "The restore operation is complete"
echo "The partitions have been restored from /mnt/images/"
echo
exit 0