Upgrading the hard drive in a Linux box
I had a Fedora Core 1 Linux box with a 6GB hard drive and it was getting full.
I bought a 120GB disk to replace the 6GB and used the steps below to move
everything from the old disk to the new one.
- Download and create a GRUB floppy disk. Get this
GRUB boot disk, unzip
it, and use 'dd if=grubfd.img of=/dev/fd0H1440', substituting the image file and your
1440kb floppy device in dev, to create a bootable GRUB disk. You'll need this later on.
In theory, the GRUB on the Knoppix disk should be sufficient, but when I used that,
the new disk wouldn't boot. Using the GRUB floppy to install the boot loader did
work, so use that.
- Install the new drive as hda, move old drive to hdc. In my case,
hdb was the CDROM drive, and when we get to installing GRUB, the new disk has
to be the primary disk, so that means the old drive must become hdc during the upgrade
process.
- Boot knoppix. I entered 'knoppix 3' at the boot prompt to make knoppix go to
runlevel 3 and skip all the graphical stuff since it isn't necessary for this and would
just waste time.
- Run fdisk to put partitions on the new disk in the same order as on the old
disk. Look at the /etc/fstab file from the old disk to get the order of the partitions.
They obviously won't be the same size as on the old disk, but their order should be the same
so that booting will work properly. In this case, hda1 was /boot, hda2 was /, and hda3 was
swap. Fedora/Red Hat likes to use LVM by default, but I'm not sure how one would handle
that in this situation, which is why I don't usually use LVM. Don't forget to set the
partition type to 82 for the swap.
- Run mkfs.ext3 on /dev/hda1 and /dev/hda2. After creating the partitions in the
previous step, create file systems on the new partitions.
- Mount the partitions from the old & new disk. Knoppix automatically created
most mountpoints under /mnt in my case, although I did have to add a /mnt/hda2 mountpoint.
Then, 'mount /mnt/hda1', 'mount mnt/hda2', 'mount /mnt/hdc1', and 'mount /mnt/hdc2'.
- Copy everything from the old partitions to the new, preserving ownership, etc.
- cp -ax /mnt/hdc1/* /mnt/hda1/
- cp -ax /mnt/hdc2/* /mnt/hda2/
- Write labels on the new partitions. In the /etc/fstab file on /mnt/hdc1, in
the device name column for / and /boot, there were not /dev/hda2 and /dev/hda1 respectively;
rather, it referenced the label for each partition. You could change the device name in the
/etc/fstab file on /mnt/hda2, but since the idea is to make the configuration identical to
that of the old disk, it makes more sense to label the partitions. (There are legitimate
reasons for using the partition, but I can't recall what they are.) Use the e2label to write
labels on the new partitions:
- e2label /dev/hda1 /boot
- e2label /dev/hda2 /
See the man page on e2label for why labels are so great.
- Designate /dev/hda3 as a swap partition. Run 'mkswap /dev/hda3'.
- Reboot system, booting with the GRUB floppy disk. Now use the GRUB floppy to
install the boot loader. At the GRUB prompt enter:
And you're done! You should be able to shutdown the system, remove the old hard drive,
remove the GRUB floppy disk, and boot with the new disk.
01/01/2006