Managing Multiple Hard Drives with cPanel

4.7/5 - (8 votes)

If you have a server with single standalone drives, you may have considered the possibility of adding additional hard drives to provide more disk capacity to your system. Luckily, this is very easy to set up and use with cPanel.

First things first, I’ll assume that you already have the hard drive physically installed in your system. This guide will show you how to partition, format, and configure cPanel to use an additional hard drive, in the simplest way possible.

1. Partitioning the Disk

We’ll assume that the additional disk is supplementary to a system that already has an existing drive and OS installation. Therefore, the new disk will usually only need to be one single partition, unless you have different planned uses for it. If this is the second disk in your server, it’s going to be named either /dev/sdb or /dev/hdb, depending on what kind of drive it is. The last letter in the drive name will depend on how many other disks you have in your server, so see this article for a simple explanation on Linux drive mappings.

To find the new disk you added, use fdisk -l, which will list the disks active on your server. The additional disk should show up in the order that it’s physically configured inside the server:

Disk /dev/sdb: 250.0 GB, 250000000000 bytes
255 heads, 63 sectors/track, 30394 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

If you notice, the already-partitioned volumes also list the partition info. For example, this is what the output for the primary hard drive in my test server looks like, which is already set up with two partitions on the primary drive:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 29884 240043198+ 83 Linux
/dev/sda2 29885 30394 4096575 82 Linux swap / Solaris

The partition information is blank for the new disk, indicating that it has not been partitioned yet. If yours has already been partitioned and you want to keep that structure, you can skip this section and go straight to formatting.

From here, I want to create one partition which will be /home2 on this server, to provide additional capacity for users on this system. GNU parted is a simple command line utility to manage disk partitions, and I’ll use this to create a partition on my new hard drive:

parted /dev/sdb

Once in parted, type print free to show how much space is available to be partitioned:

Number  Start   End    Size   Type  File system  Flags
        0.00kB  250GB  250GB        Free Space

Since I’m only creating one partition, I use the parted mkpart command to specify the start and end space to occupy the whole disk:

(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? ext3
Start? 0kB
End? 250GB

Then when I type in print, I see my new partition listed:

Number Start End Size Type File system Flags
1 0.51kB 250GB 250GB primary

Now, if you’re creating multiple partitions on the disk, do the same thing, but modify the start and end parameters to sequentially create your partitions. In the above example, that partition would have a device name as /dev/sdb1, since it’s the partition numbered 1 on disk /dev/sdb. If I had a second and third partition, they would be named /dev/sdb2 and /dev/sdb3, respectively.

Type quit to close the parted session.

2. Formatting and Configuring the Disk

Once you’ve created the partitions, you can format them easily with mkfs.ext[2|3], using the device name as the argument:

  • For ext2: mkfs.ext2 /dev/sdb1
  • For ext3: mkfs.ext3 /dev/sdb1
  • For ext4: mkfs.ext4 /dev/sdb1

Repeat this for all the partitions you created, which will be numbered started as /dev/<device><partition>. My example is using the first partition of the second SCSI hard drive, so the partition device name is /dev/sdb1 . You can also find the new partition names by running fdisk -l again to see the names of the partitions for the new disk.

I also prefer to set the reserved disk space for the root user, as by default this will be 5% of the total partition size. This means for my 250GB disk, about 12GB is being reserved, which is a bit excessive. I instead usually set this to 2500 blocks:

root@server [~]# tune2fs -r 2500 /dev/sdb1
tune2fs 1.39 (29-May-2006)
Setting reserved blocks count to 2500

TIP: You can also pass -m <%> to the mkfs.ext[2|3] commands to set the percentage for reserved disk space during formatting, which can of course be changed later with tune2fs

3. Labeling and Mounting the Disk

Now, you need to label the disk and add it to fstab. In my example, I want to label the disk as /home2, so I’d use the e2label command and pass the partition’s device name and my desired label as arguments:

e2label /dev/sdb1 /home2

This can be confirmed by typing e2label /dev/sdb1:

root@server [~]# e2label /dev/sdb1
/home2

In order to mount the partition, it needs a mount point, and to be added to the file system table. Since the partition will be mounted as /home2, I created a folder called /home2, and added the following to /etc/fstab:

LABEL=/home2 /home2 ext4 defaults,usrquota,noatime 0 0

The LABEL value would be set to the label you used in e2label.  Replace ‘ext4’ with the partition type you created in step 2. To find out more about the fstab file, see this article. Again, you need to repeat these steps for each partition you created.

After you do this, you can mount the new partitions normally:

mount /home2

4. Setting up cPanel

As far as setting up cPanel, there’s only one file you have to edit – /etc/wwwacct.conf.

  • HOMEDIR : The location where all new user home folders will be created (/home by default)
  • HOMEMATCH: Additional home directories that will also be used for new home directory creations – only takes one value, leaving blank disables.

So, if you want to specify the partition/folder that all users are set up on, edit the HOMEDIR value and leave HOMEMATCH blank. If you specify a value for HOMEMATCH, cPanel will pick the partition based on which one has the most free space available.

For example, if you specify “home” for HOMEMATCH, it will configure users in the following locations:

  • /home
  • /home* (/home2, /home3, etc)
  • /anythingwith/home
  • /usr/home

Additional Resources:

Tutorial: Adding Additional Hard Drives in Linux

cPanel Wiki: Disk Drive Management (WHM)

5 Comments

  1. Pingback: Servers Admins » Blog Archive » Managing Multiple Hard Drives with cPanel

  2. Pingback: Removing WHM Disk Space Errors | IT Admins

  3. Pingback: Removing WHM Disk Space Errors | TurboNoc.com

  4. Sajjad Reply

    Thanks, I know it’s an old post but came in useful. I hope the label part sticks and won’t give me any problems… Would it not be better to mount on fstab using the regular convention of /dev/sdx?

  5. Pingback: Removing WHM Disk Space Errors :: The cPanel Admin

Leave a Reply

Your email address will not be published. Required fields are marked *

Log in