Fdisk
Fdisk is the command line utility in linux systems which is used to manage partitions in linux using the CLI commands and it is one of the most popular tool for managing partitions by the linux administrators.
sudo fdisk /dev/xxx
Replace the xxx
with the target partition which we are about to change
Here is the basic manual of fdisk utility :
Help:
GPT
M enter protective/hybrid MBR
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Use-Case 1 : Creating the partition using fdisk in ubuntu

Here we can see there are two physical disks allocated on the system sda & sdb
where the sda
partition is mounted as the main primary disk and OS is mounted on the 3 partitions on it. Now we will add the sdb
as the secondary partition on the linux.
We will enter the fdisk console with the target disk sdb
sudo fdisk /dev/sdb
Type n
to create the new partition on the physical disk and select the primary option and then enter the partition number & pass the other parameters to keep the value default and make a primary partition of full disk.
Upon successful execution we can see that sdb1
is created with the volume size of 5G
and now we will format it as ext4
partition type to make it usable in linux

Now we will format this partition as ext4 using :
sudo fdisk /dev/sdb
Type p
to check the current partition table the output should look like :

Now we will use the following command :
sudo mkfs.ext4 /dev/sdXn
The ourput should look like :

Here we have successfully created the ext4 partition and the output should reflect in lsblk

Now we will need to mount the partition to make it usable , The steps to mount the partition is as follows :
sudo mkdir -p /mnt/extended
Now we will mount the partition on the path we just created
sudo mount <disk_voulme> <mount_point>
# sudo mount /dev/sdb1 /mnt/extended
Now the disk is mounted and we can confirm it using lsblk

There is a slight issue the partition mount will be lost in case the machine it restarted, to make it mounted on startup we will need to make following changes :
Mounting disk on startupLast updated