Upgrading HDDs with Linux

My major achievement last week at work was adding a new hard disk drive to one of my Linux servers This probably doesn't seem like such a major achievement to many people, but the way I've managed it in the past is to re-install the OS on the new drive and copy stuff across. The last time I tried to add a disk to an existing server I got it badly wrong and got nowhere fast. Of course, I've learned a lot since then...

I have an FTP server at work which runs RH9.0, the /home directory was mounted on an 8Gb SCSI drive though the rest of the system runs off a 20Gb IDE - of course, if I was building it again now, I'd have done it the other way around :) Anyway, the FTP server gets regular use and the /home partition filled up to 99% last week. Deleted a load of old files but that seemed like something of a temporary fix so ordered a new HDD from our suppliers.

I opened up the server and plugged the new disk in (this was something of a challenge in itself with 6 year old hardware, but not an interesting one) and restarted. This was the procedure I followed:

1. First of all, find out if the drive was even found - 'less /var/log/messages' and scroll through until you get through to the most recent boot. I found that /dev/hdb had been detected just fine.

2. Create some partitions - 'fdisk /dev/hdb', I added three primary partitions giving me hdb1, hdb2 and hdb3 (the big one).

3. Format the partitions - 'mke2fs -j /dev/hdb3', of course I could have used some other file system but ext3 seemed the path of least resistance with Red Hat.

4. Create a temporary mountpoint - 'mkdir /mnt/bdrive'

5. Edit /etc/fstab - adding '/dev/hdb3 /mnt/bdrive ext3 defaults 0 0' - not strictly necessary, but can make life easier.

6. Mount the target partition - 'mount /mnt/bdrive'.

7. Copy all the files - 'cp -a /home/* /mnt/bdrive/', the '-a' switch means all the files get their permissions preserved and symlinks get copied.

8. Wait a fair while...

9. Unmount the target partition - 'umount /mnt/bdrive'

9a. To be on the safe side, run a disk check - 'fsck.ext3 /dev/hdb3'

10. Unmount /home - 'umount /home', in my case I stopped a few services running which I knew dealt with files on this partition.

11. Edit /etc/fstab again - this time we need '/dev/hdb3 /home ext3 defaults 0 0', plus comment out the existing /home line or target it at a different mount point

12. Mount /home - 'mount /home' and restart any services, and all done!