Moving Linux to a new hard disk

Standard

I recently obtained a 120 GB hard disk and wanted to move my existing Red Hat Linux 8.0 partitions to the new disk. Here are the steps I used to move the data to the new disk:

It is a good idea to have a boot floppy made for your system. It make the recovery after all the copying so much easier:

mkbootdisk -v –device /dev/fd0 2.4.18-14

1. Connect the new hard disk as the IDE Primary Slave. You may have to change the jumper settings on the IDE Primary Master when you connect a Primary Slave. (NOTE: I connected the new drive in the position of where the old drive was, so I can easily do the bootloader creating => grub-install or lilo)

2. Boot a Red Hat Linux installation CD into Rescue Mode by typing linux rescue.

3. Use fdisk to create partitions on the new hard disk.

My old hard disk had the following file systems:

/dev/hda1    /boot    100 Megabytes
/dev/hda2    swap    512 Megabytes
/dev/hda3    / (root)    Remainder of disk space

My new hard disk appears to Linux as /dev/hdf. I used fdisk to partition the new hard disk similar to that of the old hard disk.

4. Create the ext3 and swap file systems on the new hard disk.

mkfs.ext3 /dev/hdf1
mkfs.ext3 /dev/hdf3
mkswap /dev/hdf2

5. Mount the /boot and / (root) slices from both disks.

mkdir /old/boot
mkdir /old/root
mount /dev/hda1 /old/boot
mount /dev/hda3 /old/root

mkdir /new/boot
mkdir /new/root
mount /dev/hdf1 /new/boot
mount /dev/hdf3 /new/root

6. Copy the file systems from the old disk to the new disk.

cd /old/boot
tar cvf – . | tar xvf – -C /new/boot
cd /old/root
tar cvf – . | tar xvf – -C /new/root

7A. At this point you can connect your new harddrive to the primary master position and reboot for the boot floppy you made in the beginning

Then run either:

For GRUB (under RedHat):
grub-install /dev/hda

or for LILO:
lilo -v

If you have no boot floppy read on:

7B. Red Hat Linux uses file system labels in /etc/fstab. You will either have to edit the new /etc/fstab or (what I chose) use the e2label command to create file system labels on the new hard disk partitions.

e2label /dev/hdf1 /boot
e2label /dev/hdf3 /

8A. Edit the lilo boot loader configuration on the new hard disk. If you are experienced with the grub boot loader, you may want to use it instead of lilo.

umount /dev/hdf1
chroot /new/root
mount /dev/hdf1 /boot


vi /etc/lilo.conf

Add:

boot = /dev/hda
delay = 40
compact
vga = normal
root = /dev/hda3
read-only
image = /boot/vmlinuz-2.4.18-14
        label = Linux

Run lilo -v to make the changes take effect.

8B grub

umount /dev/hdf1
chroot /new/root
mount /dev/hdf1 /boot


/sbin/grub-install /dev/hda

exit

If your original disk is EXT3 remember to do:

tune2fs -j /dev/hdXXX

for all your partitions except for the swap partition (that is /dev/hdf1 and /dev/hdf3 in this example)

exit

This will reboot your system and it should boot without any hickups.


Disclaimer:
By reading and/or using the information within this web page you agree to hold the author, publisher and all related entities harmless from any claim directly or indirectly related to the information given or the use of any part of the information on this web site. Use at own risk. No responsibility taken.