In this article, we want to teach you How To Create a New Disk on Linux.
Note: This article only shows how to create a new partition and doesn’t include partition extension or any other switches.
How To Create a New Disk on Linux
In this guide, we will use the fdisk command to create a new disk on Linux servers.
Let’s see how to use it.
Use the fdisk command to Add a New Disk on Linux
fdisk also known as format disk is a dialog-driven command in Linux used for creating and manipulating disk partition tables.
It is used the view, create, delete, change, resize, copy and move partitions on a hard drive using the dialog-driven interface.
This command will list your current partitions and configurations.
At this point, we attach a hard disk of 20GB capacity.
Run the above command again, you will see that the new disk has been added as
/dev/xvdcon your Linux server.
If you are adding a physical disk it will show as
/dev/sda the base of the disk type. Here we used a virtual disk.
Some commonly used fdisk commands:
n– Create partition
p– print partition table
d– delete a partition
q– exit without saving the changes
w– write the changes and exit.
To partition a particular hard disk, for example, /dev/xvdc, run the following command:
As we are creating a partition, we use the n option.
Then, you need to create primary/extended partitions. By default, you can have up to 4 primary partitions.
After that, you need to give the partition number as desired. It is recommended that to choose the default value 1.
The next value you need to choose is the first sector. If it is a new disk, always select the default value. If you are creating a second partition on the same disk, you need to add
1 to the last sector of the previous partition.
Next, you need to give the value of the last sector or the partition size.
Always recommended to give the size of the partition. Always prefix
+ to avoid value out of range error.
At this point, you need to save the changes and exit with the w option.
Now you should format your disk with the following command:
When your format is completed, mount the partition as shown below:
mount /dev/xvdc1 /data
Then, you need to make an entry in the/etc/fstab file for permanent mount at boot time.
/dev/xvdc1 /data ext4 defaults 0 0
At this point, you learn to Create a New Disk on Linux with the fdisk command.
Hope you enjoy it.
May this article about How To Find Hard Disk Information on Linux is useful for you.