How-To: Clone Your Linux Hard Drive

Hard disks all share one common trait: Sooner or later, they die.

InformationWeek Staff, Contributor

September 26, 2005

6 Min Read

Main Partition Restore

The main partition is where the Linux applications and user data usually go. To get started:

cd /mnt/cdrom
cp dar_static /etc/

Next, highlight and copy the base name of the dar backup:



is the base name one gives dar to identify the backup set. See the dar command line below to show how it is used in this context. Note: To start a restore, dar must inspect the first and the last files in the backup set. Next, insert the first disk of the backup set if it isn't already in the drive.

mount /mnt/cdrom
/etc/dar_static -x /mnt/cdrom/2005-08-13__data -b -w 

You should see the following response:

[root@localhost /]# /etc/dar_static -x /mnt/cdrom/2005-08-13__data -b -w
Reading config file: /root/.darrc
The last file of the set is not present in /mnt/cdrom , please provide it. [return = OK | esc = cancel]

Hit control-Z to suspend dar:

umount /mnt/cdrom

Eject first disk, put in the LAST disk of the backup set:

mount /mmt/cdrom

Hit ENTER a second time. The dar program expects it and will respond with:


/mnt/cdrom/2005-08-13__data.1.dar is required for further operation, please provide the file. [return = OK | esc = cancel]

Enter control-Z:

umount /mnt/cdrom

Reinsert the first disk.

mount /mnt/cdrom


Note that fg is the “resume suspended operation” command.

Hit ENTER a second time. Wait until dar demands a file that isn't in the first DVD-R (prompt similar to above). Then enter control-Z.

umount /mnt/cdrom

Now, insert the next disk.

mount /mnt/cdrom

Hit ENTER a second time. Then repeat the process from control-Z to "hit ENTER a second time" process until your backup set is complete. Don't be surprised if your current working desktop changes in the process; the file icons that were on your desktop before (that aren't part of the FC2 installation) will be deposited on the default desktop during installation. Once you see a display similar to the following, the root prompt will reappear in a minute or two.

 575964 file(s) restored
 0 file(s) not restored (not saved in archive)
 0 file(s) ignored (excluded by filters)
 0 file(s) less recent than the one on filesystem
 0 file(s) failed to restore (filesystem error)
 0 file(s) deleted

 Total number of file considered: 575964

Once the root prompt reappears, you’re done! Go ahead and reboot, and your regular Desktop should reappear.

Backup Scripts

The general nature of the following scripts are discussed in the “Ingredients” section above. The scripts themselves are internally documented in the # lines.

Modified rsync drive-to-drive backup script:

Note: Before running the script, create the following directories in /mnt/ as follows:

cd mnt
mkdir temp
mkdir temp1

Note: The script will blow up if the directories are not added.

=============== cut



echo "Mounting backup drive."

mount -t ext3 /dev/hdd2 /mnt/linux_backup

#change ext3 to match the backup drive filesystem

#if not ext3

#change /dev/hdd2 to match your actual backup drive

#and/or partition assignment if different

#change /mnt/linux_backup to match your actual mount

#point (directory)

#if your boot drive is not /dev/hdb1, change script accordingly.

#delete or comment out mount line above if backup drive

#permanently mounted.

echo "Executing incremental backup script"

echo "Backing up /bin"

rsync -aHv --delete-after --

progress /bin/ /mnt/linux_backup/bin/

echo "Backing up /etc"

rsync -aHv --delete-after --

progress /etc/ /mnt/linux_backup/etc/

echo "Backing up /home"

rsync -aHv --delete-after --

progress /home/ /mnt/linux_backup/home/

echo "Backing up /lib"

rsync -aHv --delete-after --

progress /lib/ /mnt/linux_backup/lib/

echo "Backing up /misc"

rsync -aHv --delete-after --

progress /misc/ /mnt/linux_backup/misc/

echo "Backing up /opt"

rsync -aHv --delete-after --

progress /opt/ /mnt/linux_backup/opt/

echo "Backing up /root"

rsync -aHv --delete-after --

progress /root/ /mnt/linux_backup/root/

echo "Backing up /sbin"

rsync -aHv --delete-after --

progress /sbin/ /mnt/linux_backup/sbin/

echo "Backing up /usr"

rsync -aHv --exclude *.dar --delete-after --

progress /usr/ /mnt/linux_backup/usr/

echo "Backing up /var"

rsync -aHv --delete-after --

progress /var/ /mnt/linux_backup/var/

#e2fsck /dev/hdb2

#the -c, (--checksum) option provides better security, but takes

#several times as much time to run - recommended if the mirror drive

#is your ONLY backup or if you don't have a lot to back up.

#see rsync man file for more information (type man rsync from the

#command line

echo "mounting /boot partition"

mount -t ext3 /dev/hdb1 /mnt/temp

mount -t ext3 /dev/hdd1 /mnt/temp1

echo "backing up /boot partition"

rsync -aHv --delete-after --

progress /mnt/temp/* /mnt/temp1

umount /dev/hdb1

umount /dev/hdd1

echo "backup complete"

=============== paste

Next, here's the modified dar backup script:

=============== cut



#if your boot drive is not /dev/hdb1, change script accordingly.

echo "Executing archival backup script"

echo "mounting /boot partition"

mount -t ext3 /dev/hdb1 /mnt/temp

zip -ry /usr/local/backups/ /mnt/temp/*

umount /dev/hdb1

echo "unmounting /boot partition"

cd /usr/local/backups

dar -z5 -s 1450M -D -R / -c `date \

-I`__data -Z "*.gz" -Z "*.bz2" -Z "*.zip" -Z "*.png" -P tmp \

-P dev -P proc -P mnt -P sys -P selinux \

-P usr/local/backups -P home/alizard/.opera/cache4

=============== paste

It’s a good idea to save supplemental restore information and a copy of the backup program with every backup.

Once you have put these supplemental files in the K3b (or the DVD burner of your choice) Project files, they’ll be automatically included in future backup sets. These files don’t take up much room on a DVD: Each full disk will include three 1400-MB dar backup files, leaving about 100 megs left over. If files are duplicated, there’s less chance of a DVD defect making the file you need unusable.

Below is a list of files to put on every disk in the backup set as well as the dar backup archive files themselves:

  • (use only if you need it) dar_static (the backup program) The dar README file found along with the TUTORIAL in /usr/src/redhat/BUILD/dar-2.1.2/doc. If it isn’t in that location, use locate dar to find these files. The dar tutorial backup_readme.txt A copy of this article (for reference purposes).

Now, following is the content of the backup_readme.txt file included in the above list. Cut and paste it into a text editor, and put it somewhere convenient so you can find it when you put together your DVD backup files:

=============== cut

Note: the /dev/hdb1 /boot partition files are backed up in mnt/temp inside

Make sure the boot sector is on the hdb MBR.

/etc/dar_static -x /mnt/cdrom/2005-08-13__data -b –w

When dar calls for more disks, stop with control-z, change DVDs, restart with fg [ENTER][ENTER]

=============== paste

Congratulations, you now have the tool kit you need to protect your customer’s data on Linux workstations in case of an emergency. Let's hope you never need it!

A. Lizard is an Internet consultant in the San Francisco Bay Area. He has been writing for technology magazines and Web sites since 1987.

Never Miss a Beat: Get a snapshot of the issues affecting the IT industry straight to your inbox.

You May Also Like

More Insights