Adding Another Hard Drive

From LQWiki
(Redirected from Adding Another Hard Disk)
Jump to navigation Jump to search

Introduction

Sometimes you need to add a secondary harddisk, some time after installing Linux. One sensible decision could be to provide its space to the home directories of users. This can be done by making /home a mount point for your your secondary drive.

The following instructions must be performed as root user so log in as root:

ssh -X root@localhost

How many drives does a Linux machine have?

Linux mounts drives "invisibly", that is, no drive identifier is needed to access files on the drive. Rather, the drive is "mounted" over an existing directory in the filesystem. Only one drive can be mounted on "/", at the top of the filesystem hierarchy. All other drives are mounted over directories which exist already on some other drive.

To see which drives are mounted where, and how much free space is still available on each drive, use the command df.

What to do after installing a brand new drive?

Assuming you got all the jumper setting right, and plugged in all the correct cables, your Linux system will boot and pretty much ignore your brand new hard drive until you:

  • format the drive
  • put a filesystem on it
  • show Linux where it should mount and use it

Odds are really good you'll want to use FDISK to format the hard drive, and mkfs.ext3 to put the filesystem on it. Here's a reference for more information about these steps: http://www.faqs.org/docs/Linux-mini/Hard-Disk-Upgrade.html#PARTITION

Assuming you want to use the drive as a /home drive there's an important few final steps to take to place the drive in service on the machine.

/home differs from other mount points on Linux because there's almost guaranteed to be some data you WANT already down in there; specifically, all of the per-user files for all of the system's users. You'll most probably want to start your new /home drive out with a verbatim COPY of all that /home directory data.

You can get an "instant backup" of your current /home directory by simply NOT DELETING the original files (on the "parent" drive) - mounting the new /home drive right over the existing /home directory will protect those files pretty effectively as well. Then if the /home drive dies, you'll still have that backup in there. It'll become instantly usable (and used!) when/if the new /home drive fails to work someday.

The dirty details

OK so I decided to add a /home drive to my Ubuntu Linux box. Here are the commands I ran for that. They're not very pretty.

First I formatted the drive and put a filesystem on it.

$ fdisk /dev/hdb
[...]

$ mkfs.ext3 /dev/hdb1
[...]

Yuck. Don't ask me why Linux still needs a different device name for the second step. I think the "1" is for the first partition on the drive? It seems pretty arcane and inappropriate to have to specify things this way.

Now comes the fun part - we temporarily mount the drive elsewhere, recursively copy the /home filesystem onto the drive, then mount it as /home, then make sure the new drive gets properly re-mounted every time we reboot.

NOTE: You'll probably want to exit all applications - most write preference data in your /home/your-name-here directory area. It's best to copy the data when there's nothing changing anything down in the /home area.

$ mount /dev/hdb1 /mnt/disk
$ cp -vax /home/* /mnt/disk
$ umount /dev/hdb1

Once that's done, we have to tell the system to use the /home drive when it boots up. For some reason this part of Linux has yet to be simplified, so we currently have to add the following totally incomprehensible line to /etc/fstab to achieve this.

$ cat >> /etc/fstab << HERE
/dev/hdb1 /home ext3 defaults,errors=remount-rw 0 1
HERE

Lastly, you don't have to reboot to use the /home drive right away - we can dynamically bring the drive online:

$ mount -a

Wrap-up

Having a /home drive yields significant benefits:

  • Performance improvements from separating program file IO (on the system drive) from data file IO (on the /home drive)
  • /home is a prime candidate for the occasional backup to CD-RW, a DVD, or similar media.
  • It is a good feeling to know your new /home drive can be mounted and used productively on just about any Linux machine anywhere.