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
- 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
- 2 Create a partition with the fdisk command.
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.
- 3 Now format the partition with a file system of your choice; I will be using the mkfs command
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.