[CLUE-Tech] best way to copy hdd

ockers at ockers.net ockers at ockers.net
Thu Feb 8 22:20:34 MST 2001


Hi Jeff,

> Greetings.
> 
> I would like to copy one hard drive to another.  What is the best way to do 
> this?  Basically, I am replacing a smaller drive with a larger one and using 
> the smaller one in another system.  I want my current system transferred to 
> the bigger drive and have everything work correctly.
> 
> Suggestions and experiences are appreciated.

I do this all the time.  This procedure is also useful for cloning systems if 
you've arrived at a useful "distribution" and want to make lots and lots of 
copies of it, like I used to do with the "Jim Ockers Linux distribution."  Here 
is what you need to do:

0. Get both drives installed on your system, making a careful note of which one 
is hda/sda and so forth.  (Wouldn't want to toast the partition table on the 
drive that has all your data on it.  Or reformat it.)

1. partition the new drive the way you want it, being careful not to 
repartition the old drive.  As usual, try to make your /boot partition (or 
whatever partition your boot kernel lives in) be inside the first 1023 
cylinders of the drive.  Then, make your filesystems & swap partitions (mke2fs, 
mkswap) on the new drive, being careful not to reformat your old drive of 
course.  Watch your typing carefully when you are telling fdisk or mke2fs what 
to do; a mistake can be catastrophic...

Don't forget to make the /boot partition "active" so the BIOS knows to boot 
from it later on.

2. mount the new drive in a temporary directory.  Make subdirectories (mount 
points) for the other partitions that the new drive will be using, and mount 
them in the subdirectories.  I.e., suppose your partition table is:

/dev/sda1 /boot
/dev/sda2 swap
/dev/sda3 /usr
/dev/sda4 /home
/dev/sda5 /
or whatever.  Mount /dev/sda5 in /mnt, then make directories /mnt/home /mnt/usr 
/mnt/boot and mount the appropriate partitions under /mnt just as if it was the 
new system.  You want all of the partitions mounted when you start to copy data 
to the new drive.

3. make subdirectories (mount points) under /mnt for the directories you are 
not going to copy, such as /proc , /mnt of course, and perhaps /tmp.

4. cd to the root directory.  Run the following command:

( cd / ; tar cf - enumerate all files and directories you want tarred being 
sure to exclude the proc and mnt directories ) | ( cd /mnt ; tar -xvlpsf - )

This will start a tar process running in / writing the tarchive to stdout, and 
it will start a tar process running in /mnt reading the tarchive from stdin.  
The -xvlpsf options will preserve your file ownership/permissions correctly.

On my Dell (Red Hat) server, I might type (for example):

( cd / ; tar cf - .automount Backup.sh bin boot dell dev etc home lib misc opt 
root sbin tftpboot tmp usr usr2 var ) | ( cd /mnt/newdrive ; tar -xvlpsf - )

This may take a while.

5. edit the /mnt/etc/fstab and /mnt/etc/lilo.conf to reflect the new partition 
scheme and boot scheme of the new drive, so that the changes will take effect 
when you boot from the new drive.

6. if you have changed partition layouts (i.e., the root filesystem on the old 
drive was /dev/hda1 and now it's /dev/hda5), make yourself a boot disk that 
will mount root on the new drive's root partition.  Red Hat provides a 
mkbootdisk command but if you've changed partition layouts you will need to 
edit the lilo.conf on the boot disk and re-run lilo on the boot disk.  Or, you 
can pass the root device as a kernel command-line option, i.e., linux 
root=/dev/hda4

7. umount the /mnt directory tree & shut down.  Remove the old drive, install 
the new drive in the same logical spot that the old drive was in.  I.e., if the 
old drive was IDE primary master, the new drive should take its place as IDE 
primary master.

8. boot from your boot disk.  Hopefully the kernel will mount the right device 
as the root filesystem & your system will start up normally.

9. run /sbin/lilo (since you edited the lilo.conf in step 5 above, it should be 
correct) to write the boot sector to the new drive.  Reboot from the hard disk 
this time to make sure it starts up properly without needing the boot floppy.

That's it!  My directions probably make it look harder than it is.

Hope this helps.

Jim (ockers at ockers.net)


---------------------------------------------
This message was sent using Endymion MailMan.
http://www.endymion.com/products/mailman/





More information about the clue-tech mailing list