How to create partitions larger than 2TB in Linux

 
 

It’s well known that is impossible to create partitions larger than 2TB in Linux using the default utility fdisk that comes with most of Linux distros, at least for now. In this short tutorial we’ll learn how to create larger than 2TB partitions using parted utility instead of fdisk on CentOS Linux. Assuming that we have to add three new disks to a new fictive server called mydbhost that will be used for a MySQL service for example, being master, slave, standalone it doesn’t matter, all that we care is the partitioning bit.

Installing parted utility

We can start our quick tutorial by checking if we have parted installed on our server, just type the magic command parted --help and if an error comes up saying that parted is not installed then we have to install it like shown in the example below:


$ yum install -y parted

Checking available disks on our server

Great, now that we have installed the missing package let’s go straight to disks and let’s have a quick look over how many attached disks are on this particular server:


$ ls -la /dev/sd*
brw-rw---- 1 root disk 8,  0 May 22 07:19 /dev/sda
brw-rw---- 1 root disk 8,  1 May 22 07:19 /dev/sda1
brw-rw---- 1 root disk 8,  2 May 22 07:19 /dev/sda2
brw-rw---- 1 root disk 8, 16 May 22 07:19 /dev/sdb
brw-rw---- 1 root disk 8, 32 May 22 07:19 /dev/sdc
brw-rw---- 1 root disk 8, 48 May 22 07:19 /dev/sdd

We can clearly see from this output that we have four disks on our server, one being sda having two partitions called sda1 and sda2 and another three disks that aren’t partitioned, those disks being called sdb, sdc and obviously sdd.

Running parted utility

We need now to run parted for each of our attached and unpartitioned disks like this:


$ parted /dev/sdb

We will get a console output similar to the one below where we can see that parted will run for /dev/sdb exactly as instructed in the command above:


GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

Creating partition table

Now that we’ve managed to instruct parted that we’ll make changes on sdb disk we can now move to the next step and specify what kind of partition table we want to create for the selected disk. We will instruct parted to create a GPT (GUID Partition Table) partition table for our disks as this can support partitions larger than 2TB:


(parted) mklabel gpt

On the next step we have to check the size of our sdb disk in order to correctly size and create our new partition:


(parted) print free

The output of print free command will look similar to this:


Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name  Flags
        17.4kB  537GB  537GB  Free Space
(parted)

Creating disk partition

We can see that our sdb disk max capacity is 537GB and the offset size is set to 17.4kB. Let’s create a primary partition for this disk by setting up a higher offset size like 1M and the rest of the available space up to 537GB to be allocated for our new partition:


(parted) mkpart primary 1M 537GB
(parted)

Let’s check if our previous command has been successfully applied:


(parted) p

We can see that all specified values like offset size, partition size and partition table type were applied:


Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  537GB  537GB               primary
(parted)

Knowing now that our primary partition on sdb disk has been created having the right values we can safely quit parted like shown below:


(parted) q
Information: You may need to update /etc/fstab.

Repeating the steps above for sdd and sdc disks

On this part of our short tutorial we will repeat the steps above for sdc disk:


$ parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) print free
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name  Flags
        17.4kB  129GB  129GB  Free Space

(parted) mkpart primary 1M 129GB
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  129GB  129GB               primary

(parted) q
Information: You may need to update /etc/fstab.

Now we’ll follow the same steps for our 3rd disk called sdd. This is the biggest disk from our fictive server having more than 4TB in total size, being actually the most important disk from our short tutorial about how to create partitions larger than 2TB in Linux:


$ parted /dev/sdd
GNU Parted 3.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) print free
Model: VMware Virtual disk (scsi)
Disk /dev/sdd: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
        17.4kB  4398GB  4398GB  Free Space

(parted) mkpart primary 1M 4398GB
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdd: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  4398GB  4398GB               primary

(parted) q
Information: You may need to update /etc/fstab.

Listing disks and partitions

So far we’ve managed to create our desired partitions on each of the three unpartitioned disks. Let’s list once again the content of our /dev/ directory and see if we have the partitions listed here:


$ ls -la /dev/sd*
brw-rw---- 1 root disk 8,  0 May 22 07:19 /dev/sda
brw-rw---- 1 root disk 8,  1 May 22 07:19 /dev/sda1
brw-rw---- 1 root disk 8,  2 May 22 07:19 /dev/sda2
brw-rw---- 1 root disk 8, 16 May 22 07:19 /dev/sdb
brw-rw---- 1 root disk 8, 17 May 22 07:19 /dev/sdb1
brw-rw---- 1 root disk 8, 32 May 22 07:19 /dev/sdc
brw-rw---- 1 root disk 8, 33 May 22 07:19 /dev/sdc1
brw-rw---- 1 root disk 8, 48 May 22 07:19 /dev/sdd
brw-rw---- 1 root disk 8, 49 May 22 07:19 /dev/sdd1

From the above console output we can see that our newly created partitions are in place being now listed as /dev/sdb1, /dev/sdc1 and /dev/sdd1.

Formating partitions

We are now one step closer to use our newly created partitions but this only after making those partitions ext4 and mounting them. In this step we will make use of mkfs utility which will allow us to format the partitions and obviously we will start with our first partition named sdb1:


$ mkfs.ext4 /dev/sdb1

A successful console output will look similar to this one listed below:


mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131071488 blocks
6553574 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
4000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
	102400000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Let’s repeat the step above for our sdc1 partition this time:


$ mkfs.ext4 /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
7864320 inodes, 31456768 blocks
1572838 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2178940928
960 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

And finally our last partition preparation, sdd1:


$ mkfs.ext4 /dev/sdd1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
268435456 inodes, 1073741312 blocks
53687065 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3221225472
32768 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
	102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Creating directories before mounting the partitions

Now we can say that we’re in a very good position with our tutorial, we have made a lot of progress like creating partitions using parted and formatting these using mkfs utility. Now all we need to do is just to create some directories and mount these partitions. Let’s start by changing the directory quickly to mnt:


$ cd /mnt/

And let’s do a quick list and check if we have any directories on /mnt/:


$ ls -la
total 0
drwxr-xr-x.  2 root root   6 Apr 10 22:59 .
dr-xr-xr-x. 17 root root 244 May 22 03:33 ..

As we can see there are no directories (in our case). We have to create three new directories, each one for each new partition:


$ mkdir mysql-{data,logs,temp}

Let’s do a check once again if our newly created directories are in place:


$ ls -la
total 0
drwxr-xr-x.  5 root root  60 May 24 07:32 .
dr-xr-xr-x. 17 root root 244 May 22 03:33 ..
drwxr-xr-x   2 root root   6 May 24 07:32 mysql-data
drwxr-xr-x   2 root root   6 May 24 07:32 mysql-logs
drwxr-xr-x   2 root root   6 May 24 07:32 mysql-temp

All three directories are now present, we can now move to the next step.

Amending fstab file

We have three partitions from our three disks and also and three new directories.
Let’s join these partitions with our directories by editing the fstab file:


$ vi /etc/fstab

Having now fstab open we need to add three new lines at the end of it like shown below:


...
/dev/sdb1 	/mnt/mysql-logs 	ext4 	defaults 	0 	0
/dev/sdc1 	/mnt/mysql-temp 	ext4 	defaults 	0 	0
/dev/sdd1 	/mnt/mysql-data 	ext4 	defaults 	0 	0

We can now save fstab file and move to the next step where we can mount the partitions.

Mounting partitions

We can achieve this by using mount command like shown below:


$ mount -a

If everything went fine and no errors were encountered we should be able to see now our partitions mounted, let’s run df command and make sure that everything we’ve done so far has been successfully:


$ df -TH

A successful console output will look like this one below:


Filesystem                      Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl_mydbhost-root    xfs        28G  2.6G   26G   9% /
devtmpfs                        devtmpfs   17G     0   17G   0% /dev
tmpfs                           tmpfs      17G     0   17G   0% /dev/shm
tmpfs                           tmpfs      17G   21M   17G   1% /run
tmpfs                           tmpfs      17G     0   17G   0% /sys/fs/cgroup
/dev/sda1                       xfs       1.1G  217M  848M  21% /boot
tmpfs                           tmpfs     3.4G     0  3.4G   0% /run/user/1001
/dev/sdb1                       ext4      529G   76M  502G   1% /mnt/mysql-logs
/dev/sdc1                       ext4      127G   63M  121G   1% /mnt/mysql-temp
/dev/sdd1                       ext4      4.4T   93M  4.2T   1% /mnt/mysql-data

We’re now done, we’ve managed to link the partitions with our directories. Now we can start populating these new partitions with files.

Summary of our short tutorial about how to create partitions larger than 2TB in Linux

On this short tutorial called “How to create partitions larger than 2TB in Linux” we have learned quite a few things like:
– How to install parted using yum
– How to view the disks and partitions using ls
– How to create GTP partition tables
– How to create disk partitions with parted
– How to format disk partitions using mkfs utility as ext4 file system
– How to create 3 directories with one command line
– How to add new entries in fstab file
– How to mount disk partitions using mount command
– And how to see all usable partitions on our server using df

Video

No video posted for this page.

Screenshots

No screenshots posted for this page.

Source code

No code posted for this page.

About this page

Article
How to create partitions larger than 2TB in Linux
Author
Category
Published
04/06/2018
Updated
05/11/2018
Tags

Share this page

If you found this page useful please share it with your friends or colleagues.