Adding a new partition to an existing Linux server

Suppose you have an up and running Linux server and you have a need for a new partition, here is an easy way to do that from the command line. For this demonstration, I am using a CentOS.

Here is a summary of the partitions available on my server before creating the new partition using the lsblk command.

For this post, I will be using the dd tool, other tools similar to dd in Linux are clonezilla, KDE Partition Manager, BXImage etc

  1. First, we use the dd command below to create a partition image. I will be creating a 1GB partition
dd if=/dev/zero of=1GB_HDD.img bs=1M count=1024

Once the above command is executed, the output should be something like this

  1. 2 Create a partition with the fdisk command.
fdisk 1GB_HDD.img

When you use the fdisk command, a DOS partition table is automatically created. Switch to a GPT table by entering “g” on the first fdisk prompt. To make this easy, accept the default values for partition number, first sector and last sector at the fdisk prompt by hitting the enter button when prompted.

Input “n” at the next prompt. This means a new partition is been created;

Then input “w” to write the changes made.

  1. 3 Now format the partition with a file system of your choice; I will be using the mkfs command
mkfs.ext4 1GB_HDD.img

press “y” for yes at the prompt

Next, use the losetup utility to assign the next available loop device to the newly created partition

If all these steps have been carried out properly, the partition should be available. The lsblk command should confirm that

Create a new directory for the new partition and mount it there

With the steps above, you should be able to create and mount a partition on a running server. Try this and let me know if it works for you.

Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x