How-to: Clone a hard drive using only free software

Cloning a hard drive is almost always the fastest and easiest way to migrate from one disk to another. There are several great programs out there that will do just that, the only problem is they're not free. Norton Ghost, Acronis MigrateEasy, and Partition Magic all have the required functionality to do this, but so does any bootable linux or *BSD distribution. Follow these easy steps and you'll be up and running in no time and still have a little cash left in your pocket.

Step One: Initial Configuration

The first thing we need to do is download a "Live" linux distribution. This can be any of a number such as Knoppix, Damn Small Linux, or Ubuntu. Take your pick, burn the iso, plug in both drives taking care to set the master/slave/cable select jumper to the proper setting (one master/one slave per cable). Boot your livecd and access a terminal (normally located under the system or accessories menus, also accessible by hitting ctrl+alt+f1).

Step Two: Collecting Information

Next we need to figure out how linux has decided to name our drives. There are a couple ways to do this-

Method A: dmesg | grep hd

user@host ~ $ dmesg | grep hd
Kernel command line: root=/dev/hda2
hda: WDC WD400BB-00DEA0, ATA DISK drive
hda: max request size: 128KiB
hda: 78204672 sectors (40040 MB) w/2048KiB Cache, CHS=38792/16/63
hda: cache flushes not supported
hda: hda1 hda2


for scsi or sata drives: dmesg | grep sd

user@host ~ $ dmesg|grep sd
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
SCSI device sda: 45322644 512-byte hdwr sectors (23205 MB)
sda: Write Protect is off
sda: Mode Sense: b9 00 10 08
SCSI device sda: drive cache: write through w/ FUA
SCSI device sda: 45322644 512-byte hdwr sectors (23205 MB)
sda: Write Protect is off
sda: Mode Sense: b9 00 10 08
SCSI device sda: drive cache: write through w/ FUA
sda: sda1 sda2 sda3 sda4
sd 1:0:0:0: Attached scsi disk sda
sd 1:0:0:0: Attached scsi generic sg1 type 0
EXT3 FS on sda2, internal journal
EXT3 FS on sda3, internal journal


Method B: ls /dev/[h,s]d*

user@host ~ $ ls /dev/[h,s]d*
/dev/hda /dev/hda2 /dev/sda1 /dev/sda3
/dev/hda1 /dev/sda /dev/sda2 /dev/sda4


It might take a little work but using that information and fdisk if necessary you should be able to figure out which drive is the source and which is the destination: sudo fdisk -l /dev/sda

user@host ~ $ sudo fdisk -l /dev/sda

Disk /dev/sda: 23.2 GB, 23205193728 bytes
255 heads, 63 sectors/track, 2821 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 125 1004031 82 Linux swap / Solaris
/dev/sda2 126 612 3911827+ 83 Linux
/dev/sda3 613 856 1959930 83 Linux
/dev/sda4 857 2821 15783862+ 83 Linux


Your drive might report NTFS or Fat32 in the "System" column if you are cloning a windows hard drive.

Step Three: Doing It!

In this example I am trying to clone sda which is a disk containing a linux installation. My destination is an IDE hard disk. I am cloning from a monstrous 23gb Seagate Elite SCSI drive to a 40gb Western Digital IDE drive. The new hard disk must be larger (to the megabyte, ie. a Hitachi 80gb drive is a little larger than a Seagate 80gb drive.) but then cloning should be as simple as: dd if=/dev/sda of=/dev/hda where /dev/sda is the source drive and /dev/hda is the destination

user@host ~ $ dd if=/dev/sda of=/dev/hda


Step Four: Enjoying your success

Now it should be a simple matter of removing the CD, unplugging the old hard disk (or setting the bios to boot from the new one) and hitting the power button. Enjoy.


Working?

I've heard one report of this method not working. I attribute it to user error, has anyone else had issues? Thanks -Bob

I don't know if that works

I don't know if that works but I can honestly say that if you are not a tech guru it seems awfully complicated. I found EzMigration www.arcoide.com/instant_migration.php and to tell you the truth the $30 bucks was well worth it! it was a one step drag and drop operation and the software took care of everything. I then had to expand my partition because my new hard drive was larger, but with their partition expander it was piece of cake. check out their demo video and see how easy it is. then decide for yourself if its worth your money, or if you want to spend all that time doing research and complicating yourself with the "free" method.

dd clone command

I tried to clone a fiery(printer controller) hard drive it has on it various partitions dos, nfts, linux, fat... but it didnt work, I tried ghost imagedrive, acronis, the thing is that something is wrong whit the masterbootrecord i get the LI error from LILO

dd clone command

abicholas,

This is most likely caused by the drive being named differently. If your printer controller isn't using the new libata drivers hda will be primary master, hdb primary slave, hdc secondary master, hdd secondary slave. if the location of the disk changed at all you would be unable to boot. You might also try booting a livecd and chrooting into the new drive and simply running "lilo" if you still have problems please let us know. I've also heard of a new open source cloning livecd named "clonezilla" though I've never used it and cannot vouch for its performance.

Easy

"Complicated?" I happened to have a Ubuntu disk already downloaded/burned, but even if I hadn't, this would have been a snap.

Literally 4 commands, as described above. The only additional thing I had to do was add "sudo" in front of the last command "sudo dd if=/dev/sda of=/dev/sdb" - to give it proper privileges. I'd say that 5 minutes of my time was worth $30.

Re: Easy?

Mikey, anything is easy if it is something you have trained yourself to do. Your 5 minutes does not count all the hours you have spent in front of a computer learning how to do all this crap. Ha!

Wow huge thanks for this

Wow huge thanks for this amazing tutorial. I was trying to figure out how to clone my hard drive without paying a cent but I have failed to do that. Actually I have found some programs but all of them were supporting only Windows but no Linux or Ubuntu at all. Thanks for the great tips on cloning hard drive on Linux without paying a cent. I think there are a lot of people who want to thank you for this post. I will be waiting for another great articles from you in the future.

Sincerely,

Matt Damson from azoft.com - custom software development

Edit (obrith) : Nice try spamming your link for better SEO, but i'll go ahead and leave this comment so people can see your company name and (hopefully) choose not to work with you.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.