How To Use fdisk To Partition Disk latest updated

How to use fdisk in linux for partition disk

How to use fdisk to Partition Disk in Linux

Fdisk is a disk partition table manipulation program. By this command, you can manipulate the disk partition table. fdisk is can be used for less than 2TB disk more than 2TB you have to use the parted command. 

In this article, we will see how to delete and create a new partition using fdisk in Linux.

Step 1 – List the disk 

Use the below command to list the disk and their partition table.
#fdisk -l 
check disk using fdisk
This will show you the disk information. In our case, we have added new disk in our system so we will check sdb (select which disk you have added) by below command:
#fdisk -l /dev/sdb
check disk by fdisk

Step 2 – Using the command to delete 

Now we have one disk sdb with label gpt we have to delete it. Use below command to enter :
#fdisk /dev/sdb
fdisk delete
Type “m” for help, this will show you all command available for this disk. This is a tip also because in a small Linux environment people share the same disk to another system and sysadmin tries to create a partition but he fails because everyone skips step one and then we get an error ” Value out of range. ” in the disk. check size available too.
fdisk help
We are going to delete so we press “d” for delete partition :
Command (m for help): d
delete disk partition
Command (m for help): w
fdisk save configuration
press w to save the configuration.
If you have raw disk then you can skip step 2 but it is always safe to check first then proceed.

Step 3 – Create partition 

We will do the same steps to enter the disk and press m for listing available options for the disk.
use n for creating a new partition,1 for the number of partition one press enter to leave default settings to use the full disk.
# fdisk /dev/sdb
Command (m for help): m  
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-33554398, default 2048):    press enter key if you need default 
Last sector, +sectors or +size{K,M,G,T,P} (2048-33554398, default 33554398):  press enter key if you need default
Command (m for help): w
create partition using fdisk

Now you have successfully created partition. Now you can create PV,VG , LVM, and formate disk in any filesystem to mount on the mount point.

Leave a Comment

Your email address will not be published.

Scroll to Top