Monday, February 1, 2010

You might have worked with Linux for years and never added an additional disk to your system or perhaps you were too frustrated by Linux’s strange ways of dealing with disks to attempt it.

In either case, here’s your opportunity to work through the steps required in adding a new disk to your system.

The process, once you have your disk physically installed into the system, is simple.

Most of us install a new Linux system with a series of mouse clicks or taps on the keyboard without regard for how the disk setup takes place. Desktop users generally accept the default installation with little thought. But, what happens when you run out of space on a disk or filesystem?

Server system operators know the procedure well but perennial desktop jockeys might never have treaded the multiple disk waters.

Well, it’s time to dive in to the deep end.

Initial Setup
The first step is to install the new disk into your system. Find an open bay in your computer, set the drive’s jumpers, plug the drive into system power and into a controller cable. Boot up your system and watch your BIOS for the new drive. Login to your system and su to root or use sudo and issue the following commands.

I have two disks in the example system, /dev/sda (System SCSI disk) and /dev/hda (Empty IDE disk). The IDE disk is the new disk that we’ll use for this example.

Since you know the device name of the new disk (/dev/hda), it’s easy to configure it.

debian:~# fdisk /dev/hda
The number of cylinders for this disk is set to 10402.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):

You’re now in the fdisk (fixed disk) utility, where you’ll setup partitions on the new disk. For simplicity, we’ll create one single partition on this disk.

Please realize that you can split the disk into several partitions or “slices” as your needs dictate. It’s time to create that partition.

Begin by telling fdisk that you want to create a new partition and then provide the partition number that you want to create (1).

To use the entire disk, hit ENTER to select the default cylinder (1) and hit ENTER again to select the last cylinder for the end of the partition.

Write the changes to disk (w). Once you’ve written the changes to disk, fdisk closes and returns you to the system prompt.

Mounting the Disk
You’ve created the filesystem (ext3) on your new disk. You can’t “see” or use the disk yet until it’s mounted.

Mounting a disk means to make its contents available to the system and its users by providing a mount point on which the disk will reside.

To do this, you need to use an existing directory or create a new one onto which the disk will mount. Since this disk will provide space for backing up valuable files, create a directory named /backup.

Congratulations, you’ve installed a new hard drive into your system, setup the disk in fdisk, created a mount point, mounted the drive onto the mount point and you’re ready to start filling up the new space with backups. And, not a moment too soon as you can see.

Are we done here? Yes and no. We’re done as far as using this new disk for backups and moving off some non-essential files to free up some space.

What happens if you reboot the system? You wouldn’t see the new disk. You might think it disappeared or failed. It’s still there, just like you left it—in manual mount mode.

And, that’s OK, if you want the disk available to you on an occasional basis and would prefer to mount it only when needed. If you’d like to have it available on a persistent basis, you need to do a bit more work.

Creating a Persistent Mount
Danger, Will Robinson! You have to edit a system file (/etc/fstab) for this one but rather than bore you with vi the vi version of file editing, we’re going to cheat. The fstab file has the following format:

file system mount point type options dump pass

File system is /dev/hda1, mount point is /backup, type is ext3, options is defaults, dump is 0 and pass is 2.

I’ll save the explanations of these options for a future entry. To add that list of parameters to the /etc/fstab file, we’ll use the echo command.

debian:~# echo "/dev/hda1 /backup ext3 defaults 0 2" >> /etc/fstab

Now, your new disk will always mount automatically in read/write mode for you upon subsequent boot ups.

Certain aspects of Linux can challenge the saltiest (and most patient) among computer users. Adding new disks is a common sore point for users unfamiliar with the unusual methods used in Linux.

Remember to be careful when editing system files (files in the /etc directory) and using fdisk, since both can cause irreparable (at worst) or time-consuming damage to your system.