[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: copying/cloning root partition



Stephen A. Witt wrote:
> I'm trying to figure out how to clone the root partition of a Debian Linux
> installation.

[I recently moved my Debian/Windows system from a 9 GB hard drive to a nice
new 30 GB hard drive. Here is a draft of a short tutorial based on my
(mis)-adventure. I welcome any technical, organizational, or grammatical
feedback.]

With hard drive price/GB continuing to drop, you may be thinking of
replacing that old 8.4 GB drive with a new 30 GB model. You probably do not,
however, want to reinstall Windows or Linux on the new hard drive. This
tutorial will attempt to walk you through moving your Windows 9x and/or
Linux system to a new hard drive using nothing but a couple of floppy disks.

Before we start, here is what you will need: 

1. 	Printout of current hard drive partitions (in Linux, run `fdisk -l
/dev/hda`, assuming you are replacing hda)

2.	Printout of `df -h`. This will show you how much free space you have
on each partition. This will help you determine how big the new partitions
on the new hard drive should be. (I am assuming that you have your Windows
partitions mounted; otherwise you will need to get the Windows information
from within Windows.)

2.	Printout of /etc/fstab file.

3.	Windows 95 or 98 Start Up floppy (you will not need cdrom support).

4.	One floppy with tomsrtbt on it. Tomsrtbt is a mini Linux
distribution that fits on one floppy. You can get it at:
http://www.toms.net/rb/. If you do not have tomsrtbt, you should get it. It has
saved me a couple of times.


If you are adding a hard with more than 1024 cylinders (about 9 GB, I
think), make sure that your /boot partition (or root partition if you do not
use a separate /boot partition) will be entirely below 1024 cylinders. If
the /boot partition (or root partition) will extend past 1024 cylinders,
then make sure that your choice of a boot-loader will work. For me, LILO
21.5-1 beta worked fine above 1024 cylinders.

Okay, now you can install that new hard drive. I installed the new drive as
primary master (aka /dev/hda) and changed the old drive to primary slave
(hdb). I have a cdrom on secondary master (hdc).

First, lets move Windows over to the new disk. (I have used this method for
Win95 and Win98; it may or may not work for other MS flavors.) 

Boot up with that Win9x Start Up floppy. At the dos prompt, run fdisk. If you
get a question about enabling large disk support, you probably want to
answer yes.

Now you need to create a primary dos partition. From the information I
printed out about my old hard drive, I knew that I had a 4 GB partition for
Win9x and was using 68% of the partition. On the new hard drive (which fdisk
identifies as disk 1), I created a 4.5 GB primary dos partition and marked
it active (bootable) since the old Windows partition was marked bootable.
Finally, display partition information and make sure that everything is the
way you want it to be. If all is well, you can exit fdisk.

Since this is Windows, it must be time to reboot. When the Win9x Start Up
floppy reboots, you will need to format the new Windows partition with
`fdisk c:` Once c: is formatted, you can take the Windows floppy out and
reboot with the tomsrtbt floppy.

Once you log into tomsrtbt, you will need to create two mount points where
you can mount the old and new Windows partitions. I did the following:

mkdir /mnt/old /mnt/new

I mounted the old partition with:

mount -t vfat /dev/hdb1 /mnt/old  (where hdb1 is the old windows partition)

I mounted the new partition with:

mount -t vfat /dev/hda1 /mnt/new (where hda1 is the new windows partition)

Change to the old windows directory:

cd /mnt/old

Now we are ready to copy the old partition to the new partition. Take your
pick as to how you copy the old to the new.

tar cf - . | (cd /mnt/new; tar xvf - )

or

cp -vaf . /mnt/new

or

find . | cpio -puvmdB /mnt/new

Assuming that there are no errors, all that is left to do is to umount
/mnt/old and /mnt/new, remove tomsrtbt floppy, and reboot. You should boot
right into Windows. If you cannot boot Windows, boot off the Windows9x Start
Up floppy and run `sys c:` at the dos prompt. Remove the floppy and reboot
your new Windows partition.

When Windows is up and running, you should probably run scandisk just to
make sure everything is OK. 

Now that you have Windows running, let's get Linux installed.

Boot tomsrtbt again.

We need to create partitions for our Linux system on the new hard drive:

fdisk /dev/hda

Looking at the partition scheme from your old hard drive and create as many
ext2 and swap partitions as you will need. The printout of `df -h` will give
you an idea of how large to make your partitions. For example, if your old
/home partition was 90% full, you should probably make the new /home
partition larger, especially if your new hard drive is significantly larger
than the old hard drive.

This next step is very important. Write down the locations and names of the
old and new partitions. You will need this information, and you do not want
to get the partitions mixed up. Here is my partition information:

hda2 = new swap		hdb2 = old swap
hda5 = new /home 	hdb3 = old /home 
hda6 = new /usr 	hdb5 = old /usr 
hda7 = new / 		hdb6 = old /

Note: All the new partitions should be on the primary master drive (hda), and all
the old partitions should be on the primary slave drive (hdb).

You then need to format the partitions. I did the following:

mkswap /dev/hda2 (for the swap partition)
mke2fs /dev/hda5 (for /home)
mke2fs /dev/hda6 (for /usr)
mke2fs /dev/hda7 ( for /)

Now we need to mount the old and new partitions and copy from old partition
to new partition. First we need to create mount points /mnt/old and
/mnt/new: 

mkdir /mnt/old /mnt/new

Now we can mount the old and new /home partitions, using the old and new
partition information that you wrote down earlier:

mount -t ext2 /dev/hdb3 /mnt/old
mount -t ext2 /dev/hda5 /mnt/new 

Type `mount` and double check that all is correctly mounted. If so, then:

cd /mnt/old

And choose one method:

tar cf - . | (cd /mnt/new; tar xvf - )

or

cp -vaf . /mnt/new 

or

find . | cpio -puvmdB /mnt/new

When you have successfully moved /home, then umount /mnt/old and /mnt/new,
mount the next pair of old and new partitions (in my case /usr). I
handled the root (/) partition last because we have to edit a couple of files after
copying the old root to the new root.

Since we are using tomsrtbt, we can use emacs or vi to edit files. Edit
/etc/fstab on the new root (/) partition (it should be mounted at /mnt/new)
and change the partition names to correspond to their new locations.

Next, edit /etc/lilo.conf to identify the new root partition. Now you need
to run lilo, but we need to run it with chroot. With the new root partition
mounted at /mnt/new, run this:

chroot /mnt/new lilo -v

Note: When I ran this, I got the dreaded 1024 cylinder error. I then went
back into /etc/lilo and added `linear` to the global options section.
Re-running `chroot /mnt/new lilo -v` gave me another error that suggested I
try lba32. I then removed `linear` and added `lba32` to /etc/lilo.conf. One
final `chroot /mnt/new lilo -v` worked.

Take tomsrtbt out and reboot. You should shortly be looking at a LILO:
prompt. If all went well, your old hard drive is now ready to be removed.

Credits: 

Thanks to Tom Oehser for tomsrtbt, "The most GNU/Linux on one floppy disk."
Additional thanks to Tom Oehser for recommending the `cp -vaf` method as the
one he would use with tomsrtbt.

The tar trick comes from pp. 193-194 of Running Linux, 3rd Edition, by
Welsh, Dalheimer & Kaufman.

-- 
David Raeker-Jordan
mailto:rkrjrdn@epix.net
Harrisburg, PA, USA



Reply to: