HOWTO: Add Drives to Your Linux/cPanel server

Today I'm going to be explaining how to add additional hard drives to a Linux/cPanel server. Before I get into that, I'll give everyone a little background information on myself. I've been working in the webhosting field for quite a long time now doing everything from answering phones, building servers, and taking out the trash. My very first job for a now defunct hosting company was back in 2000. We ran Sun Cobalt RaQ server appliances and a few cPanel v3 servers. After my days were up at my first employer, I continued to do systems administration work for various companies and individuals, both on site and remotely. In late 2006 I was hired by another local dedicated hosting company located in Arlington Heights, IL. My job was to build servers, and pretty much take care of them. During this time I was able to really fine tune my skills with Linux and cPanel. Fast forward to today, and here I am down at SingleHop doing the exact same thing, looking after servers. I usually try to spend my off time doing something relaxing, hanging out with friends, stuff that keeps me pretty far away from the computer.

Okay, so. Your reading this to figure out how to add another hard drive to your cPanel system running some version of Linux. For my purposes here we'll assume we're all using CentOS 5.2. First things first, before anything is added/removed from your server, it's a pretty good idea to take a full backup of everything and save it locally! In the past few years of doing this I've learned that it pays to keep backups.

Once your backup process has been completed and your new hard drive is added we should be all ready to go right? Wrong. We'll first need to format/partition the drive and then mount it.

Note: Hard drives are identified by interface. IDE hard drives are prefixed with "hd" and SCSI/serial drives are prefixed with "sd." You can use letters a-h for IDE disks, and letters a-p for SCSI/serial drives. Some distros do have their own special letter schema's, but are usually well documented if they are.

We're going to assume we're installing a new serial ATA hard drive into our system, and it's hooked to the second SATA port, thus making our drive "sdb." First things first log into your server as the root user. Once you've done that enter the following as root:

Code:
# fdisk /dev/sdb

This brings up how many cylinders are on your hard disk, and of course opens up the fdisk program that will allow us to partition our new hard disk.

The next step is to simply enter a "p" to show the partition table. This is useful to see what partitions are already setup on the disk, if any.. The output will look something like this:

Code:
Command (m for help): p

Disk /dev/sdb: 50.0 GB, 50019202560 bytes
255 heads, 63 sectors/track, 6081 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System

Command (m for help):

Now, since my drive here is a brand new drive, there are no partitions on it. If any partitions are present we'll just go ahead and delete them by pressing "d."

Now everyone should have the same thing. An unpartitioned hard drive. Next we'll need to partition our drive. We'll keep it simple and mount this drive with a large, single primary partition, just like a backup drive. To do that enter "n" at the command line to create a new partition. You should see something like this:

Code:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6081, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): 6081

Command (m for help):

As you can see, I hit "n" and it asked if I'd like to create a primary (P) or an extended partition (E) I hit P for a primary partition, entered "1" for it being my first partition on the drive. Your first cylinder will be "1" and the last one in our case will be "6081." Most times you will be able to hit enter and use the default cylinder counts.

Let's verify that we've done everything correctly up until this point. At the command prompt enter "p" to check the partition table again:

Code:
Command (m for help): p

Disk /dev/sdb: 50.0 GB, 50019202560 bytes
255 heads, 63 sectors/track, 6081 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1      6081  48845601   83  Linux

Command (m for help):

Now you can see that we've added a partition to the drive, but we're not done yet. No changes have been written to the disk yet, everything is just in memory. If everything looks right, go ahead and enter the "w" command which will write the changes to the disk.

Now that our disk is partitioned to sdb1 we'll need to format it. You can format your drive to any filesystem you want, but for our purposes here I'm going to format it with ext3, the most common today. To format your drive:

Code:
[root@chicago]# mk2fs -t ext3 /dev/sdb1
mke2fs 1.32
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
6111232 inodes, 12211400 blocks
610570 blocks (5.00%) reserved for the super user
First data block=0
373 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@chicago]#

Hmmm? What all did we just do? Using the mk2fs (make file system) command, we specified the type (using the -t) ext3 using the device and partition name (/dev/sdb1). You have successfully partitioned and formatted your new drive, but we're still not done. We need to mount this partition to make it usable, and add an entry in the file "/etc/fstab"

We're going to add this entry in the fstab file because on reboot, our drive that we just mounted will need to be remounted. By adding a simple entry in the fstab file our drive will be mounted every time on startup. To do this we're going to add the following code on the last line of the file "/etc/fstab"

Code:
/dev/sdb1               /backup                  ext3    defaults        1 2

Once you've added that to the last line in the file, save it and issue this final command as root:

Code:
# mount /dev/sdb1

The mount command mounts the drive for immediate use, and the /dev/sdb1 is our drives partition name.

That's it! You've just added a new hard drive to your cPanel server the "hard" way. cPanel comes with a built in handy utility that will automatically detect, format, and partition your new drive with just a few clicks.

To install your new hard drive through cPanel you'll need to login to WHM as root, and find the button on the left called "Format/Mount a new hard drive" under the drives tab about 3/4 the way down. Click on that. The next page will show you the newly detected drives and have a button next to the drive to select it. Once you select your new drive follow the onscreen instructions, and hit enter. In just a few minutes WHM takes care of everything for you.