Sunday, September 10. 2006
Upgrade Hard Drive on Debian Linux (Sarge)
This weekend I decided to upgrade my Linux server (the same server running this weblog). The machine is a decommissioned corporate Compaq DeskPro EN - 1GHz Pentium III with a 20GB hard drive. When I first installed Debian 3.1 (Sarge) I installed it on the original hard drive. I ran it that way for over two years and finally decided to replace the hard drive with a 300GB one. After doing some Googling on the subject, it seemed like this might not be too hard. Then, this is Linux after all and even the simplest tasks can balloon in complexity depending on the hardware you're working with. As I worked through the task it seemed a little tough but, in retrospect, it really wasn't that problematic. Here's what I did...
- I shutdown the machine and installed the new hard drive into the box. I set the jumper to "slave" and replaced the "single" drive cable with a "double" drive cable (it came with the new hard drive), attached that cable and a free power cable, then started up the machine.
- The Compaq BIOS saw the hard drive, automatically reconfigured itself, and asked if I wanted to save the new configuration. I did, and then step into the BIOS configurator (F-10). I'd read that I'd have to tell the BIOS the geometry of the drive so I did some research on the model of hard drive, found the logical cylinders, sectors and heads and looked for a place to enter the information. I couldn't find one and unfortunately the Compaq BIOS could only "see" 137GB of the drive (the problem is explained in depth here) anyway. I thought this might be an issue but not for Linux! Turns out that this wasn't a problem at all. I just needed the BIOS to "see" the drive and that was already working.
- I let Linux boot, switched to the root user (sudo su) and checked /dev to see if the new drive was there.
# ls -l /dev | grep hd ¬It was there and was labeled hdb. Next I launched fdisk to partition and format the new drive. I decided to keep my present partition setup which is one partition for the system, one for the swap drive and one for /home. Since I had a whole lot of space to work with, I made the System partition 137GB (just for the hell of it, not because of the BIOS issue
), the Swap partition 5GB and the Home partition took the rest of the drive. Again, at first I thought I needed to tell fdisk about the geometry of the drive but, as it turned out I didn't and the default values that fdisk provided worked fine. I made sure that the System and Home partitions had IDs of 83 and the Swap partition had an ID of 82. (see the fdisk help for details on using setting partition IDs, etc...). Finally I checked /dev again to see if the partitions were there.
# ls -l /dev | grep hd ¬The System partition is hdb1, the Swap partition is hdb2, and the Home partition is hdb3. - With the partitions created, I formated them using mkfs for the System and Home partitions and mkswap for the Swap partition.
# mkfs -t ext3 /dev/hdb1 ¬
# mkfs -t ext3 /dev/hdb3 ¬
# mkswap /dev/hdb2 ¬ - Now I created a mount point for the new drive.
# mkdir /new-drive ¬The I mounted the System partition of the new drive.
# mount /dev/hdb1 /new-drive ¬After that I created a mount point for /home.
# mkdir /new-drive/home ¬And then mounted my new Home partition there.
# mount /dev/hdb3 /new-drive/home ¬ - Now was a simple matter of copying everything from the old drive to the new drive. I switched to single-user mode as a safety precaution first.
# telinit 1 ¬After the copying finished, I made new directories for /proc and /sys.
# cp -a /bin /boot /dev /etc \ ¬
> /home /initrd /lib /new-drive ¬
# cp -a /media /mnt /opt /root \ ¬
> /sbin /svr /tmp /usr /var /new-drive ¬
# mkdir /new-drive/proc /new-drive/sys ¬I had almost 40GB on the old drive so the copying took a little time to complete. I went and had a chat with my Mom while cp did its thing. - The bulk of the work was done but as a paranoid server admin I wanted to make sure I got everything right so I checked the new top-level directory structure against the old one.
# ls -l / > ls-old.txt ¬I decided not to recreate the initrd.img and vmlinuz symlinks at the root level. Everything else looked fine though so my paranois was satisfied.
# ls -l /new-drive > ls-new.txt ¬
# diff -c0 ls-old.txt ls-new.txt ¬ - At this point I needed to install grub (my boot loader) into the master boot record (MBR) on the new hard drive. I'd read that this can be a pain in the ass to do and I'd seen a half-dozen or so methods to get it done. After reading them all, I realized an easier way to accomplish it. To install grub to the MBR I added "(hd1) /dev/hdb" to the /boot/grub/device.map file. Then I copied that file to the same place on the new drive (because I wasn't really sure which device.map file grub would use for its setup).
# nano -wz /boot/grub/device.map ¬Then I ran grub to install grub on the new drive.
(hd0) /dev/hda
# Added a temp device for new hd
(hd1) /dev/hdb
# cp /boot/grub/device.map / ¬
# /new-drive/boot/grub/device.map ¬
# grub ¬Then I used nano to remove the new entry from /boot/grub/device.map and copied it to the same place on the new drive again.
grub> root (hd1,0) ¬
grub> setup (hd1) ¬
grub> quit ¬ - Lastly I double checked my /etc/fstab file to be sure it would reflect the new drive setup properly when the machine was rebooted with the new drive as the master.
# cat /etc/fstab ¬Everything looked good so I shutdown the machine.
# shutdown -h now ¬ - At this point I disconnected the original drive and reset the jumper on the new drive to "master." I re-attached the new drive to the bus and started up the machine again. The Compaq BIOS recognized the absence of the original drive, reconfigured the BIOS and I accepted the new configuration. grub ran and continued to boot into Linux. Happy penguin!

- Just to make sure everything was "happy happy go"
I checked the free space on the new drive.
# df -h / /home ¬Looks like I have a whole bunch more space on my little server! Definitely "happy happy go!"
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 129G 3.8G 119G 4% /
/dev/hda3 142G 69M 135G 1% /home
Trackbacks
Trackback specific URI for this entry
No Trackbacks



