10 fdisk Commands to Manage Linux Disk Partitions

fdisk stands (for “fixed disk or format disk“) is an most commonly used command-line based disk manipulation utility for a Linux/Unix systems. With the help of fdisk command you can view, create, resize, delete, change, copy and move partitions on a hard drive using its own user friendly text based menu driven interface.

This tool is very useful in terms of creating space for new partitions, organising space for new drives, re-organising an old drives and copying or moving data to new disks. It allows you to create a maximum of four new primary partition and number of logical (extended) partitions, based on size of the hard disk you have in your system.

fdisk command examples
fdisk command to manage disk partition

This article explains 10 basic fdisk commands to manage a partition table in Linux based systems. You must be root user to run fdisk command, otherwise you will get a “command not found” error.

Caution – Don’t Create, Delete or Modify Partitions. Unless you know what you are doing!

1. View all Disk Partitions in Linux

The following basic command list all existing disk partition on your system. The ‘-l‘ argument stand for (listing all partitions) is used with fdisk command to view all available partitions on Linux. The partitions are displayed by their device’s names. For example: /dev/sda, /dev/sdb or /dev/sdc.

[[email protected] ~]# fdisk -l

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

2. View Specific Disk Partition in Linux

To view all partitions of specific hard disk use the option ‘-l‘ with device name. For example, the following command will display all disk partitions of device /dev/sda. If you’ve different device names, simple write device name as /dev/sdb or /dev/sdc.

[[email protected] ~]# fdisk -l /dev/sda

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

3. Check all Available fdisk Commands

If you would like to view all commands which are available for fdisk. Simply use the following command by mentioning the hard disk name such as /dev/sda as shown below. The following command will give you output similar to below.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help):

Type ‘m‘ to see the list of all available commands of fdisk which can be operated on /dev/sda hard disk. After, I enter ‘m‘ on the screen, you will see the all available options for fdisk that you can be used on the /dev/sda device.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):

4. Print all Partition Table in Linux

To print all partition table of hard disk, you must be on command mode of specific hard disk say /dev/sda.

[root@tecmint ~]# fdisk /dev/sda

From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter ‘p‘, it will print the specific /dev/sda partition table.

Command (m for help): p

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

Command (m for help):

5. How to Delete a Partition in Linux

If you would like to delete a specific partition (i.e /dev/sda9) from the specific hard disk such as /dev/sda. You must be in fdisk command mode to do this.

[root@tecmint ~]# fdisk /dev/sda

Next, enter ‘d‘ to delete any given partition name from the system. As I enter ‘d‘, it will prompt me to enter partition number that I want to delete from /dev/sda hard disk. Suppose I enter number ‘4‘ here, then it will delete partition number ‘4‘ (i.e. /dev/sda4) disk and shows free space in partition table. Enter ‘w‘ to write table to disk and exit after making new alterations to partition table. The new changes would only take place after next reboot of system. This can be easily understood from the below output.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d
Partition number (1-4): 4

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
You have new mail in /var/spool/mail/root

Warning : Be careful, while performing this step, because using option ‘d‘ will completely delete partition from system and may lost all data in partition.

6. How to Create a New Partition in Linux

If you’ve free space left on one of your device say /dev/sda and would like to create a new partition under it. Then you must be in fdisk command mode of /dev/sda. Type the following command to enter into command mode of specific hard disk.

[root@tecmint ~]# fdisk /dev/sda

After entering in command mode, now press “n” command to create a new partition under /dev/sda with specific size. This can be demonstrated with the help of following given output.

[root@tecmint ~]# fdisk  /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e

While creating a new partition, it will ask you two options ‘extended‘ or ‘primary‘ partition creation. Press ‘e‘ for extended partition and ‘p‘ for primary partition. Then it will ask you to enter following two inputs.

  1. First cylinder number of the partition to be create.
  2. Last cylinder number of the partition to be created (Last cylinder, +cylinders or +size).

You can enter the size of cylinder by adding “+5000M” in last cylinder. Here, ‘+‘ means addition and 5000M means size of new partition (i.e 5000MB). Please keep in mind that after creating a new partition, you should run ‘w‘ command to alter and save new changes to partition table and finally reboot your system to verify newly created partition.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

7. How to Format a Partition in Linux

After the new partition is created, don’t skip to format the newly created partition using ‘mkfs‘ command. Type the following command in the terminal to format a partition. Here /dev/sda4 is my newly created partition.

[root@tecmint ~]# mkfs.ext4 /dev/sda4

8. How to Check Size of a Partition in Linux

After formatting new partition, check the size of that partition using flag ‘s‘ (displays size in blocks) with fdisk command. This way you can check size of any specific device.

[root@tecmint ~]# fdisk -s /dev/sda2
5194304

9. How to Fix Partition Table Order

If you’ve deleted a logical partition and again recreated it, you might notice ‘partition out of order‘ problem or error message like ‘Partition table entries are not in disk order‘.

For example, when three logical partitions such as (sda4, sda5 and sda6) are deleted, and new partition created, you might expect the new partition name would be sda4. But, the system would create it as sda5. This happens because of, after the partition are deleted, sda7 partition had been moved as sda4 and free space shift to the end.

To fix such partition order problems, and assign sda4 to the newly created partition, issue the ‘x‘ to enter an extra functionality section and then enter ‘f‘ expert command to fix the order of partition table as shown below.

[root@tecmint ~]# fdisk  /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): x

Expert command (m for help): f
Done.

Expert command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

After, running ‘f‘ command, don’t forget to run ‘w‘ command to save and exit from fdisk command mode. Once it fixed partition table order, you will no longer get error messages.

10. How to Disable Boot Flag (*) of a Partition

By default, fdisk command shows the boot flag (i.e. ‘*‘) symbol on each partition. If you want to enable or disable boot flag on a specific partition, do the following steps.

[root@tecmint ~]# fdisk  /dev/sda

Press ‘p‘ command to view the current partition table, you see there is a boot flag (asterisk (*) symbol in orange color) on /dev/sda1 disk as shown below.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

Next enter command ‘a‘ to disable boot flag, then enter partition number ‘1‘ as (i.e. /dev/sda1) in my case. This will disable boot flag on the partition /dev/sda1. This will remove the asterisk (*) flag.

Command (m for help): a
Partition number (1-9): 1

Command (m for help): p

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

Command (m for help):

I’ve tried my best to include almost all basic commands of fdisk commands, but still fdisk contains a variety of other expert commands you can use them by entering ‘x‘. For more detailed information, check out ‘man fdisk‘ command from the terminal. If I’ve missed any important command, please do share with me via comment section.

Read Also :

  1. 12 “df” Commands to Check Disk Space in Linux
  2. 10 Useful “du” Commands to Find Disk Usage of Files and Directories

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

33 Comments

Leave a Reply
  1. Hi, I am having this issue whilst trying to install Linux ‘Ubuntu Studio‘ onto my old Samsung (this laptop has a new clean and empty SSD installed) I burnt the Ubuntu Studio onto a USB and am unable to complete the installation due to it telling me ‘No root file system! No root file system is defined. Please correct this from the partitioning menu’ Could you please advise how I would proceed?

    Reply
  2. Hey there!

    How can I convert a 16 bit bootable partition to 32 bit?

    In my case, my bootable partition on my internal emmc drive, is accessible via terminal when booting from a live USB stick, And is located at: ‘/dev/mmcblk0p1’.

    Thanks!

    Reply
  3. Sir, for me newbie beginner any many others it would be very interesting to read in each of your great publications in what/which application an user can enter the command(s) so beautiful documented – hope to read more fine quality publications

    Reply
  4. Thanks, may i know what command used to see another user command history? how can i come to know what are the command executed another user in the Linux server?

    Reply
  5. Hi, can your please let me know how to see how much free space in my disk using fdisk command and also what are the commands used to re-read the partition table on Linux.

    Reply
  6. Hello Sir,

    I wanted to know about Patching. Why patching is necessary in Linux? What role patching plays in real time work.
    Please help me out.

    Reply
  7. How to make backup process for files and directory in linux in real time??? What are the steps in performing backup? When is backup performed?

    Reply
  8. what is the solution for this error!

    Partion number :1
    First sector (2048-15249407, default 2048) : ___(M,G,T,P)
    Value out of range. ERROR

    How can i decide the values for my disk, which size is 7.3GB?
    I am using primary type for partition.

    Reply
  9. Can someone please explain me this error message……..
    @ -HP-ENVY-Notebook:~$ sudo apt-get install ubuntu-restricted-extras openjdk-8-jdk
    [sudo] password for :
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    openjdk-8-jdk is already the newest version (8u91-b14-0ubuntu4~16.04.1).
    openjdk-8-jdk set to manually installed.
    You might want to run ‘apt-get -f install’ to correct these:
    The following packages have unmet dependencies:
    libstdc++-5-dev : Depends: libstdc++6 (>= 5.4.0-6ubuntu1~16.04.1) but 5.3.1-14ubuntu2.1 is to be installed
    libstdc++6 : Depends: gcc-5-base (= 5.3.1-14ubuntu2.1) but 5.4.0-6ubuntu1~16.04.1 is to be installed
    ubuntu-restricted-extras : Depends: ubuntu-restricted-addons but it is not going to be installed
    Recommends: unrar but it is not going to be installed
    Recommends: libavcodec-extra
    wine1.6-amd64 : Depends: wine1.6:any (= 1:1.6.2-0ubuntu14)
    Recommends: libcapi20-3 but it is not going to be installed
    Recommends: libosmesa6 but it is not going to be installed
    Recommends: unixodbc
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
    @ -HP-ENVY-Notebook:~$

    Reply
    • @Rahul,

      The openjdk-8-jdk package already installed on the system, why you want install again? about the error, its clear that you’ve older version of libstdc++-5-dev and system requires libstdc++6 in this case you need to upgrade your system to most recent version, if you want to correct these errors try running the following command:

      $ sudo apt-get -f install
      
      Reply
      • Hi Ravi, Thank a lot for your response. Actually I want to do netmeeting but getting the below error message. Can you please help me on this. I have Ubuntu 16 on my machine.

        Error Message:
        Java is NOT working.

        Enable Java in your browser, and then refresh this page to join the meeting. To enable Java, follow these steps:
        1

        Select Tools > Add-ons.
        2

        Find Java under Plugins section, and select Enable.

        Reply
      • Hi Ravi,

        Getting the below message while running the command.

        TrueType core fonts for the Web EULA

        │ END-USER LICENSE AGREEMENT FOR MICROSOFT SOFTWARE

        │ IMPORTANT-READ CAREFULLY: This Microsoft End-User License Agreement
        │ (“EULA”) is a legal agreement between you (either an individual or a
        │ single entity) and Microsoft Corporation for the Microsoft software
        │ accompanying this EULA, which includes computer software and may include
        │ associated media, printed materials, and “on-line” or electronic
        │ documentation (“SOFTWARE PRODUCT” or “SOFTWARE”). By exercising your
        │ rights to make and use copies of the SOFTWARE PRODUCT, you agree to be
        │ bound by the terms of this EULA. If you do not agree to the terms of
        │ this EULA, you may not use the SOFTWARE PRODUCT.

        Reply
    • @Rahul,

      In Ubuntu, by default the Windows partition mounted and you can view the partition from the Computer tab on the Desktop or you use following command view the windows mounted partition as shown:

      $ sudo fdisk -l
      

      You will see some-think like:

      /dev/sda5     4892672 1173295103 1168402432 557.1G Microsoft basic data
      
      Reply
    • @Joginder,

      A /boot partition is a partition that includes important files for booting Linux operating system properly,

      When it comes to LVM, the /boot partition must be created separately under normal disk partitioning, because grub boot loaders could not read files from an LVM partition. So, its always better approach to create a separate /boot partition.

      I hope it will clear your confusion…

      Reply
  10. Just wanted to note that “format disk” is incorrect as this tool never has formatted a drive/disk. Formatting refers to creating a filesytem and overwriting an old one in some cases. That is more like what mkfs does not what fdisk does. As you have shown, fdisk is a partitioning tool.

    Reply
  11. Hello
    There is an error in the write up “7. How to Formatting a Partition in Linux”, supposed to be”How to format a partition in Linux”

    Reply
    • @Aaron,

      Oh man thanks for your findings in the article, always appreciated your work towards Tecmint. Corrected in the writeup..

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.