Just recently, I assisted a good friend of mine with a harddrive failure. He had two drives in his machine hda and hdb. hda was his primary drive, and hdb was a file storage drive. Unfortunately, hda was dying, so we needed to swap it out. This can be tricky, so after completing this, I wrote a how-to for myself in case this comes up again.
The first thing we did was put a new drive in on the secondary IDE. You may need to adjust the jumpers so it will be cable select or slave depending on your situation. You’ll know this is working if you boot your box and you have a /dev/hdc device.
The next step was to format it. We chose a very simple partition setup for the new primary drive, basically four partitions, you may need to adjust this to suite your needs. Below is what we did.
Just recently, I assisted a good friend of mine with a harddrive failure. He had two drives in his machine hda and hdb. hda was his primary drive, and hdb was a file storage drive. Unfortunately, hda was dying, so we needed to swap it out. This can be tricky, so after completing this, I wrote a how-to for myself in case this comes up again.
The first thing we did was put a new drive in on the secondary IDE. You may need to adjust the jumpers so it will be cable select or slave depending on your situation. You’ll know this is working if you boot your box and you have a /dev/hdc device.
The next step was to format it. We chose a very simple partition setup for the new primary drive, basically four partitions, you may need to adjust this to suite your needs. Below is what we did.
cfdisk /dev/hdc
/dev/hdc1 /boot = 150MB
/dev/hdc2 swap = 1GB
/dev/hdc3 /tmp = 250MB
/dev/hdc4 / = *
After your partitions are made, we need to make the filesystems. We went with ext3 for the /boot partition and reiserfs for the rest (except swap obviously)
mkreiserfs /dev/hdc3
mkreiserfs /dev/hdc4
mkswap /dev/hdc2
mke2fs -j /dev/hdc1
Make mount points on current primary /mnt drive
cd /mnt
mkdir boot root tmp
Copy files from current primary drive to new drive while perserving permissions withrsync
rsync -auv --delete --exclude=/tmp --exclude=/files --exlude=/sys
--exclude=/dev --exclude=/proc / /mnt/root/.
mount /boot
rsync -auv --delete /boot /mnt/.
rsync -auv --delete /tmp /mnt/.
Mount bind root so we can copy /dev
mkdir /mnt/test
mouunt -o bind / /mnt/test
rsync -auv --delete /mnt/test/dev /mnt/root/.
Make mount points in the new drive for /proc and /sys
cd /mnt/root
mkdir proc sys
chmod 555 proc
Make sure /etc/fstab is correct in new drive
cd /mnt/root/etc
vi fstab
Setup grub
grub
> root (hd2,0) ## or wherever the new drive is
> setup (hd2)
> quit
This will install grub in MBR
Make sure grub know where the kernel is with root= value in grub.conf. Make sure you’re editing, /mnt/boot/grub/grub.conf
root=/dev/hda4
Shut off the machine. Remove the current /dev/hda drive, and put the /dev/hdc drive in it’s place. May need to jumper it to be master. Restart the machine, if you see grub, you’re looking good. Next, you’ll need to pass the kernel load, file system mounts and services start.