Open In App

fdisk command in Linux with examples

Improve
Improve
Like Article
Like
Save
Share
Report

fdisk also known as format disk is a dialog-driven command in Linux used for creating and manipulating disk partition table. It is used for the view, create, delete, change, resize, copy and move partitions on a hard drive using the dialog-driven interface. 
fdisk allows you to create a maximum of four primary partitions and the number of logical partition depends on the size of the hard disk you are using. It allows the user: 

  • To Create space for new partitions.
  • Organizing space for new drives.
  • Re-organizing old drives.
  • Copying or Moving data to new disks(partitions).

Synopsis:  

fdisk [options] device

or

fdisk -l [device...]

1. View All Disk Partitions:The first thing to do before doing any thing with the disks and partition is to view basic details about all available partition in the system. The below command is used to list the partitions on your system and see their /dev names. For example /dev/sda, /dev/sdb or /dev/sdc

$ sudo fdisk -l

2. View Partition on a Specific Disk: Below command is used to view all disk partitions on device /dev/sda.  

$ sudo fdisk -l /dev/sda

3. View all fdisk Commands: To see all the command which are available under fdisk command you can use /dev/sda partition with fdisk command.  

$ sudo fdisk /dev/sda

Note: This will prompt for a command. Type m for seeing all the operations which can perform on /dev/sda. After pressing m you will get:  

4. Create a Hard Disk Partition: For this go inside the hard drive partition that is the /dev/sda partition, and use the following command:  

$ sudo fdisk /dev/sda

Now you have to type n to create new partition and then type p for making a primary partition and e for making an extended or logical partition depending on the type of partition to make.  

Run w command to write the changes and reboot your system. 

5. Delete a Hard Disk Partition: To delete a partition for the hard disk and free up space occupied by that partition for example /dev/sdb. Go to the command menu using following:  

$ sudo fdisk /dev/sda

and then type d to go to the delete partition menu. It will prompt the partition number you want to delete(type the number).  

Run w command to write the changes and reboot the system. 

6. How to view the size of your Partition:  

$ sudo fdisk -s /dev/sda

Note:  

  • To check for the manual page of fdisk command, use the following command:
$ man fdisk
  • To see the help message and listing of all options, use the following command option:
$ sudo fdisk -h

 


Last Updated : 20 Jan, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads