Duplicating the root partition

I keep two bootable partitions on my machines for several reasons:

I make both partitions primary partitions, the same size, and both below the 1024-cylinder boundary. All of these factors were required with earlier versions of LILO and BIOSs. Some of them may no longer be required, but I continue this way because it works, even if I move a drive to a different machine.

With most of my drives, this gives 4GB partitions, which (presently) is plenty for a root filesystem. Note that I have separate filesystems for /home, /usr/local, and /u. I use the latter for junk that doesn't need to be backed up.

Once that is done, here's how I duplicate the active filesystem to the reserve partition.

Prepare the duplicate partition

First, boot to single user mode. At the graphical boot screen, hit ^X (<Ctrl-X>) to get to a text-mode boot: prompt. Then enter "linux single". (This assumes that the current partition boot label is "linux".)

At the shell prompt, unmount the duplicate partition, if mounted.

Remake the filesystem.


mke2fs <dup_partition>
If the drive is not brand new, add the switch for bad-block checking.

mke2fs -c <dup_partition>
It will take quite a bit longer, but it's well worth it if there are bad spots on the drive.

After that, mount the partition again.

Copy the filesystem

Copy the currently active filesystem over to the duplicate.


find . -mount -depth | cpio -pdm <dup_partition>
That will take a while.

Make the necessary adjustments

Out of the box, partitions are given labels. Because labels for the root partition may not make sense after the switch is made, I recommend replacing the labels in /etc/fstab with partition device names, e.g. /dev/hda1 and /dev/hda2.

Modify the etc/fstab in the duplicate filesystem so that the duplicate filesystem will be mounted on root (/). You will also want an entry to mount the old (current) filesystem some place like /oldrh.

Then make sure you have a mount point (a directory) in the new partition to mount the old partition, as you set it up in fstab.

Modify etc/lilo.conf so that there is a boot "stanza" for the new partition and one for the old one. As an example, here is the lilo.conf for the old partition, prepared for the cutover:


boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
linear
default=linux
message=/boot/message

image=/boot/vmlinuz-2.4.9-31
	label=linux
	read-only
	root=/dev/hda1

image=/rh73/boot/vmlinuz-2.4.9-31
	label=newlinux
	read-only
	root=/dev/hda2

Here is the lilo.conf for the new partition:


boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
linear
default=linux
message=/boot/message

image=/boot/vmlinuz-2.4.9-31
	label=linux
	read-only
	root=/dev/hda2

image=/rh72/boot/vmlinuz-2.4.9-31
	label=oldlinux
	read-only
	root=/dev/hda1

Note the changes to the root line in the first stanza, and in the image, label, and root lines in the second stanza.

Now, run lilo to put the changes in the old lilo.conf into effect.

Try it out

Now, reboot to single user mode in the new partition. Remember to hit ^X (<Ctrl-X>) to get to a text-mode boot: prompt. Then enter (in my case), "newlinux single".

If everything comes up ok, then you are ready to put Disk 1 of the distribution into the CDROM drive (and a boot diskette in the diskette drive, if needed), and reboot for the upgrade.


Bob McClure <robertmcclure@earthlink.net>
Last modified: Thu Aug 15 16:28:53 2002