RECIPE

Cloning a Linux Hard Drive

How to set up a hard drive for mirror for bare-metal restore purposes—accurately and efficiently

TechBuilder logo By A. Lizard, ChannelWeb
8:39 AM EDT Mon. Sep. 26, 2005
Page 1 of 3
Most system builders know all too well the headaches involved in recovering a crashed hard drive. The bottom line is, there really are only three kinds of hard drives:

  • Hard drives that have failed.
  • Hard drives that will fail.
  • Hard drives that were retired in the course of a computer upgrade before failure.

In this TechBuilder Recipe, I’ll show you how to set up a hard drive mirror clone--as opposed to a new drive mirror (or what’s known as a “bare metal restore”)--for Linux-based systems.

You don't have to be a Linux expert to get these procedures to work. I've tried to keep them simple and specific. Follow them exactly, and you should be able to save yourself days, even weeks, of work. Fixing it yourself can also spare you from the expense of hiring a specialized hard-drive recovery shop, some of which charge thousands of dollars for their services.

In an earlier TechBuilder Recipe, Backing Up Linux Workstations Without Tears, I detailed the process of creating a new drive mirror and set up a backup system drive mirror and DVD-R archives. But that procedure took nearly a week of experimenting to get exactly right. The procedures in this Recipe will enable you to skip that painful experimentation period and get right to drive cloning.

With a hard-drive mirror in place, recovery from a drive crash is as simple as unbolting a hard drive from a mobile rack and replacing the failed hard drive along with it. The whole process should take only 15 minutes. Remember, the completeness of a disk recovery always depends on how recent your last backup is.

For this Recipe, most of the processes will be executed within a terminal at the command line. What you see in monospace type will refer to either the processes or programs, or the files or prompts you will actually see (or enter) within a terminal in monospace font itself. Specific command-line instructions can be cut and pasted directly from the article into a terminal window. This reduces the odds of a system builder making a mess by incorrectly entering a command-line switch.

Ingredients

For the process of setting up any hard drive mirror, you'll need a mobile rack. I've been using Newegg’s SANMAX PMD-96I, and it’s worked very well. This particular mobile hard-drive rack uses a standard PCB pin-socket connector.

By contrast, most lower-cost mobile racks use the Centronics parallel connector. I have recommended the Centronics connector in the past, mainly because it’s inexpensive. Unfortunately, the Centronics parallel connector is intended for relatively low-speed data transfer (megabyte/second range), such as those seen from a computer to a parallel printer. While that’s fine for a parallel printer, it's definitely not fine for the data-transfer requirements of modern, high-speed IDE drives. This problem is exacerbated if there’s any significant wear generated on the Centronics connector. On the Newegg rack, the DIN PCB pin-socket connector accurately transfers data at full IDE bus speed, drastically reducing error rates.

Also, if you have the usual flat-ribbon IDE cables installed, consider replacing them with round cables with shielding. The price is of round cables is now comparable to that for flat ones, and the round cables do a better job of handling high-speed drive data transfers. They’re also easier to work with inside the computer case.

You'll also need either a working drive to copy or a full archival image backup set on DVD-R.

My earlier Linux backup Recipe included three scripts: a dd drive-cloning script; rsync backup script (intended to provide a simple differential backup taking a few minutes to run); and dar script, which creates “compressed-like” files suitable for archiving to a DVD-R backup set. Unfortunately, while the dd script worked well at first, it has since started giving me increasing problems. Finally, it became unusable. As there is no replacement dd script in my earlier Recipe, instead, use the rsync_backup.sh script below for direct drive-to-drive copies.

Setting Up a Drive Mirror in 12 Steps

To set up a mirror which should clone any drive in workable condition:

  1. Add the
    rsync_backup.sh
    script in the last section of the article to /usr/local/bin. Again, see my earlier TechBuilder Recipe, Backing Up Linux Workstations Without Tears, for details.

  2. Unplug the main hard drive. Plug the mirror drive you plan to clone to in its place. If you have other drives in this system, unplug them as well. Don't give the OS installer a chance to put the boot sector on the wrong drive. You may have to change the BIOS setting pointing at the boot drive if you remove drives.

  3. Do a minimal installation of Fedora Core 2 (or whatever your base Linux OS is). Be certain that the boot sector setup in the automated HD setup during the installation is pointing to the correct Master Boot Record (MBR) location.

  4. Plug the main drive back in. Plug the mirror drive in, too. (Note: My own is on /dev/hdd; however, if yours isn’t, change the
    sh rsync_backup.sh
    script accordingly. The instructions are within the internal script comments.) If you’ve unplugged other drives in the system, plug them back in now as well.

  5. Do an rsync backup from your main drive to your new one using the rsync_backup script in this article. rsync is superior to cp in this case because it does a differential backup with error checking, and is also superior to dd because it transfers complete files, not bits or disk errors. The command is
    sh rsync_backup.sh
    .

  6. Add these directories to /mnt/:

    /mnt/temp 
    /mnt/temp1
    

    While these aren’t actually necessary from the standpoint of cloning a drive with an unmodified boot sector, the script won’t run correctly without them. Instead, it will crash when it tries to use the directories.

    If you have not changed the boot setup, skip ahead to Step 9 and unplug the main HD.

  7. Mount the boot partition of the main drive to /mnt/temp, and mount the boot partition of the backup drive to /mnt/temp1.

  8. Copy the files from /mnt/temp to /mnt/temp1, overwriting the files in temp1, including the grub subdirectory.If you need either or both of the empty /mnt/windows and /mnt/floppy directories, but don't see them in the mirror drive, make the extra drive mounting directories at this time.

  9. Unplug the main HD. Plug the mirror drive in its place.

  10. Reboot from the mirror drive. At this point, there should be no significant difference between the drive mirror and the original drive. If the drive boots as usual and gets to the usual Desktop, then the mirror is ready. Try an app or two (I suggest OpenOffice) to see if you can open a document. If you're running Win4Lin, open it and run a Windows program. If it runs, the mirror is ready.

  11. Unplug the mirror drive and replace it in your mobile rack. Then plug the main drive back in as usual. If you prefer, you can simply leave the mirror drive where it is, and put the original main drive into the mobile rack.

  12. If you are running the new drive as your main one, now is a good time to run the e2fsck drive-checking program on the old main drive you’re using as a backup. You no longer need to be concerned about the consequences of repairing drive errors that e2fsck has warned you about (for example, that you might render data permanently inaccessible). Any files that do get trashed in the course of fixing drive errors by e2fsck will be rewritten completely and correctly the next time you back up via rsync script.

Below, you’ll find the modified rsync and dar scripts for you to cut and paste, which will automatically mount and back up the boot partition. Be aware that the very first boot-up on a new drive will be slower than you’re probably used to, and it might even hang for a minute or two. This does not indicate a problem unless the boot sequence completely shuts down instead of resuming.

Also, if you do have a boot sector modified from the default, run the modified rsync backup script specified in the first item in the list as instructed below as soon as possible. That way, the boot sector information will exist in the backup for you to copy.


RATE THIS ARTICLE Worse 1 2 3 4 5 Better
CHANNELWEB MARKETSPACE >> (Sponsored Links)
Channelweb : Promofinder
FEATURED PROMOTIONS
Undelete 2009 - Server Edition includes 10 FREE Client Licenses
New Release! UNDELETE 2009 Real-Time Protection. Real-Time Recovery. Protect files the Windows recycle bin and backup sys...
RELATED STORIES >>
>> More On Whitebox (notebook, desktop, server)/Custom Systems:
ADVERTISEMENT




CHANNEL SERVICES >>