Saturday, April 09, 2005

Adding a hard drive to the Debian box

Tonight I installed a new hard drive in my Debian 3.1 box, primarily so I could move the /var directory from it's old location in the root partition of the primary drive to a new, much larger, partition on the new drive.

While the Debian documentation has good information on partitioning and formatting hard drives, it had relatively little information on migrating system data from one drive to another. I found three good sites that helped me get through the process:

I didn't find any resources online that specifically walked me through how to move /var, so I integrated the pages' advice and gave it a go. Here's what I did (as with my prior Debian posts, if you're looking for help, remember that I'm a complete novice):
  1. I backed up all my critical data, including the entire /var directory, and then installed the new drive into the machine.
  2. I determined that the new drive was /dev/hdb (done by "cat /proc/partitions").
  3. I used "cfdisk /dev/hdb" to partition the drive and "mkfs /dev/hdb1" to format the new partition.
  4. I entered single-user mode by running "init 1" from the console.
  5. I mounted the new partition to /mnt/hdb1 (first creating the directory /mnt/hdb1, then using "mount /dev/hdb1 /mnt/hdb1").
  6. I copied everything in /var to the new drive, using "cp -pr * /mnt/hdb1" from the /var directory.
  7. After verifying that everything seemed to be OK, I added a line to /etc/fstab so the new drive would be mounted as /var. The line was "/dev/hdb1 /var ext2 defaults 1 2"
  8. I renamed /var to /var-old ("mv /var /var-old"), created a new, empty, /var directory, and then ran "mount -a" to mount the new drive based on the fstab line.
  9. I exited single user mode ("exit"), and that was it!

I was impressed with how relatively easy the entire process was; it took less than half an hour from start to finish, not including research time. Now that I've got the drive mounted, the transition from one hard drive to the other is completely seamless; /var looks and acts like any other directory, yet it's on a completely different physical drive.

Ah, the wonders of Linux.

No comments: