Howto use 2TB+ hardisks in linux servers

Storage is becoming cheaper as technology advances. Therefore I started using 3TB and 4TB data disks in the hybrid cloud solutions we provide to our SMB (Small and Medium Business) customers. Being accustomed using fdisk to partition the disks, I ran into the problem only being able to create partitions totalling up to 2TB. This totally defies the use of implementing large harddisks.

Lets dive into the root cause of the issue.

Why am I only able to create partitions up to a total of 2TB on bigger harddisks?

The answer is simple. I was using ‘fdisk’. Fdisk is an old tool which uses a 32-bit ms-dos partition table. Subsequently, the Master Boot Record (MBR), in which the partition begin and end-points are stored is 32 bit, and thereby it can’t handle anything above 2 TeraBytes.

So how do we avoid using fdisk and create partitions larger 2TB in linux

To fully use your 2+TB harddrive, you have to use a partition table that supports it. We now know that the MS-DOS partition table (MBR) does not, so what should you use instead? GPT.

GPT supports up to 9.4 ZB (ZetaByte). That’s 9895604649984 GB (GigaByte)!. It’s pretty safe to say, that you will not hit this limit in the near future.

Requirements

First make sure that you have a backup of all your data thats on the harddrive, somewhere else. Because what you have to do WILL wipe the drive clean, and delete everything on it!

You need a program called “parted”. It’s the easiest way to create the partition table and create a partition of the desired size. It might be installed already on your Linux system. If not then you have to install it using your favorite package manager.
In debian that would be:

apt-get install parted

In RedHat EL/CentOS that would be:

yum install parted

Identify your harddrive

You have to find out what your harddrives name is.
In Linux, every harddrive get’s a name. This can be “sda”, “hda” or something similar depending on what kind of interface they are connected to.

Find your drive names using the following tools:
lsblk
fdisk

Run the command:

lsblk

And you should see something like the following:

You see how there is a “sda” and a “sdb” ?

If you notice the nice treeview lsblk makes, you will see that below “sda” there is “sda1″ and “sda2″. These are partitions on disk “sda”
sdb has a partition too, because I already formatted my harddrive to 4TB, but before I formatted it with a GPT partition table, “sdb1″ only had 1.8TB under the column “SIZE” which is the same problem you have.

Now we need to find the maximum size of your harddrive. You can do this by using the program “fdisk” with the following syntax:

fdisk -l /dev/<your harddrive name here>

In my example it would be:

fdisk -l /dev/sdb

You will get an output that looks something similar to this, it’s the top line marked with the number of GB we are interested in:

Create the filesystem

There are many filesystems to choose from. I prefer ext4 and that is what I will use in this guide. For general purpose, ext4 should be just fine. If you need to use the harddrive for something special, then please read up on what filesystem would be best for you and use that instead.

If you run the “lsblk” command again like earlier in this guide, you should now have a “1″ partition like I did in my example: “sdb1″