Linux Tutorials

Linux Partition Management

Linux Partition Management
​Making Linux partitions is one of the toughest tasks for new Linux users. In this article, I will cover various topics on Linux partitioning. I’ll use different Linux partition managers to list, create, resize, extend and delete Linux partitions.

Linux partition managers

In this article, we will perform CRUD(Create or Clone, Read, Delete, Update) actions on system storage drive using various Linux partition managers. If you are a new Linux user, you might want to try an easy to use GUI based tool. If you like tinkering through Command line then we’ll also cover 4 cli-based partition managers.​I hope you find this article helpful. If at any point, you find something confusing, let me know in the comment section below this article. I will reply ASAP.

  1. GUI based tools
    1. Gparted
      1. List partitions
      2. Create partitions
      3. Resize partitions
      4. Delete partitions
  2. CLI based tools
    1. cfdisk
      1. List partitions
      2. Create partitions
      3. Resize partitions
      4. Delete partitions
    2. fdisk
      1. List partitions
      2. Create partitions
      3. ​Delete partitions

List drives & partitions in Linux

1. Gparted list partitions

Gparted is the most popular and powerful partition manager for Linux. You can easily perform CRUD on your storage drives.

Listing partitions in Gparted is nothing more than opening the app itself. It takes a few seconds to load all the system drives and partitions.

2. cfdisk list partitions

cfdisk and an extremely easy to use tool for managing partitions. It is cli based but provides easy to use options to perform actions on your system drives.​
sudo cfdisk
Just open the app and it’ll list out all the partitions of the current storage drive.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
 >>  /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
    /dev/sda3                    50782208     63211519     12429312     5.9G    83 Linux
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │ Partition type: Linux (83)                                                                           │
 │     Attributes: 80                                                                                   │
 │Filesystem UUID: 77518fa2-4624-430d-8965-abf7b328165d                                                 │
 │     Filesystem: ext4                                                                                 │
 │     Mountpoint: / (mounted)                                                                          │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
      [Bootable]  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
                                   Quit program without writing changes

​3. fdisk list partitions

To list partitions in fdisk, use the ‘l’ argument with fdisk.
sudo fdisk -l
sandy@LinuxAndPeppermint ~ $

sudo fdisk -l

Disk /dev/sda: 30.1 GiB, 32365232128 bytes, 63213344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa51a596a
Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 19531775 19529728  9.3G 83 Linux
/dev/sda2       19533822 50782207 31248386 14.9G  5 Extended
/dev/sda3       50782208 63213343 12431136  5.9G 83 Linux
/dev/sda5       19533824 27344895  7811072  3.7G 82 Linux swap / Solaris
/dev/sda6       27346944 50782207 23435264 11.2G 83 Linux
Partition table entries are not in disk order.

Create Linux partition

1. Gparted create a new partition

Creating a partition using Gparted is extremely easy and quick in Linux. Simply select the drive you want to create partition from, right click and click ‘New’. Make sure to unmount the drive otherwise ‘New’ option will be greyed out.

Enter the new partition size and hit ‘Add’ button.
​Click apply to start creating the partition.

​2. cfdisk Create Partition

To create a new partition using cfdisk, run cfdisk with sudo permission.​
sudo cfdisk
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
 >>  Free space                   50782208     63213343     12431136     5.9G
                        [   New  ]  [  Quit  ]  [  Help  ]  [  Write ]  [  Dump  ]
                                   Create new partition from free space
Select Free space you want to create a partition of. Select ‘New’ and hit enter.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
 >>  Free space                   50782208     63213343     12431136     5.9G
 Partition size: 5.9G
                  May be followed by M for MiB, G for GiB, T for TiB, or S for sectors.
Enter the partition size and hit enter. By default, it creates the partition of all free space. So just pause before you hit enter and see if you really want to create partition out of all free space.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
>>  /dev/sda3                    50782208     63213343     12431136     5.9G    83 Linux
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │Partition type: Linux (83)                                                                            │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
      [Bootable]  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
Everything is setup. Now select ‘Write’ and hit enter. It will ask you to type ‘yes’ and hit enter. This is the last confirmation, after this prompt, cfdisk will create the partition.
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │Partition type: Linux (83)                                                                            │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
 Are you sure you want to write the partition table to disk? yes_
                          Type "yes" or "no", or press ESC to leave this dialog.
That’s it. Partition created!
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │Partition type: Linux (83)                                                                            │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
      [Bootable]  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
                                  The partition table has been altered.

3. fdisk Create Partition

To create Linux partition using fdisk, first list partitions and note down the device path you want to create the partition from.
sudo fdisk -l
sandy@LinuxAndPeppermint ~ $ sudo fdisk -l
Disk /dev/sda: 30.1 GiB, 32365232128 bytes, 63213344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa51a596a
Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 19531775 19529728  9.3G 83 Linux
/dev/sda2       19533822 50782207 31248386 14.9G  5 Extended
/dev/sda3       50782208 63213343 12431136  5.9G 83 Linux
/dev/sda5       19533824 27344895  7811072  3.7G 82 Linux swap / Solaris
/dev/sda6       27346944 50782207 23435264 11.2G 83 Linux
Partition table entries are not in disk order.
For this tutorial, I want to create a new partition from /dev/sda3. Then select the partition using fdisk command –
sandy@LinuxAndPeppermint ~ $

sudo fdisk /dev/sda3

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x64d7e7ab.
Command (m for help):
To create a new partition use ‘n’ command.
Command (m for help):

n

Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):
Select partition type. To create a primary partition, use ‘p’ command and ‘e’ for extended type.
Select (default p):

p

Partition number (1-4, default 1):
Next, it will ask for partition number. Leave it default which is 1. Hit enter.
First sector (2048-12431135, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-12431135, default 12431135): +2000M
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help):

Then select the size of your new partition. The first sector, select default value, and Last sector enter the value in M. For example, to create a 2GB partition, type +2000M.At last, it’ll read the message as follows – ‘​Created a new partition 1 of type ‘Linux’ and of size 2 GiB. ‘

But the partition is still not created. To write changes to disk, use ‘w’ command. It’ll show the following message – “The kernel still uses the old partitions. The new table will be used at the next reboot. Syncing disks.”

For the new partition to appear, you’ll need to reboot your system.

Resize Linux partition

1. Gparted resize partition

Resizing partition in Gparted is very simple. Open the app, select the partition you want to resize, right-click and select ‘Resize/Move’.
Enter the new partition size and hit ‘Resize/Move’ button. Lastly, click the apply button to apply the changes you have just made.

2. cfdisk Resize Partition

Start cfdisk with sudo permission.
sudo cfdisk
Select the partition you want to resize. Select ‘Resize’ option and hit enter.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
 >>  /dev/sda3                    50782208     63211519     12429312     5.9G    83 Linux
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │ Partition type: Linux (83)                                                                           │
 │Filesystem UUID: 266f1f9d-5e6e-4d80-a973-4c991cf28763                                                 │
 │     Filesystem: ext4                                                                                 │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
      [Bootable]  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
                                 Reduce or enlarge the current partition
Enter the new partition size.
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │ Partition type: Linux (83)                                                                           │
 │Filesystem UUID: 266f1f9d-5e6e-4d80-a973-4c991cf28763                                                 │
 │     Filesystem: ext4                                                                                 │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
 New size: 5.9G_
                  May be followed by M for MiB, G for GiB, T for TiB, or S for sectors.
And finally, write changes to disk by selecting write option.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
 >>  /dev/sda3                    50782208     57073663      6291456       3G    83 Linux
    Free space                   57073664     63213343      6139680     2.9G
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │ Partition type: Linux (83)                                                                           │
 │Filesystem UUID: 266f1f9d-5e6e-4d80-a973-4c991cf28763                                                 │
 │     Filesystem: ext4                                                                                 │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
      [Bootable]  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
                         Write partition table to disk (this might destroy data)

Delete Linux partition

1. Gparted Delete Partition

To delete a partition in Linux using GParted, simply select the partition, right-click and select delete option to delete the partition.
Do not forget to apply changes after deleting the partition.

2. cfdisk Delete Partition

To delete the partition using cfdisk, start cfdisk with sudo.
sudo cfdisk
Highlight the partition you want to delete and select ‘Delete’ option.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
 >>  /dev/sda3                    50782208     63211519     12429312     5.9G    83 Linux
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │ Partition type: Linux (83)                                                                           │
 │Filesystem UUID: 266f1f9d-5e6e-4d80-a973-4c991cf28763                                                 │
 │     Filesystem: ext4                                                                                 │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
      [Bootable]  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
                                       Delete the current partition
And finally, write changes to disk by selecting ‘Write’ option.
                                              Disk: /dev/sda
                           Size: 30.1 GiB, 32365232128 bytes, 63213344 sectors
                                    Label: dos, identifier: 0xa51a596a
    Device          Boot            Start          End      Sectors     Size    Id Type
    /dev/sda1       *                2048     19531775     19529728     9.3G    83 Linux
    /dev/sda2                    19533822     50782207     31248386    14.9G     5 Extended
    ├─/dev/sda5                  19533824     27344895      7811072     3.7G    82 Linux swap / Solaris
    └─/dev/sda6                  27346944     50782207     23435264    11.2G    83 Linux
 >>  Free space                   50782208     63213343     12431136     5.9G
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
 │Filesystem UUID: 266f1f9d-5e6e-4d80-a973-4c991cf28763                                                 │
 │     Filesystem: ext4                                                                                 │
 └──────────────────────────────────────────────────────────────────────────────────────────────────────┘
                        [   New  ]  [  Quit  ]  [  Help  ]  [  Write ]  [  Dump  ]
                         Write partition table to disk (this might destroy data)

3. fdisk Delete Partition

To delete a partition using fdisk, first, run fdisk and select the partition to be deleted.
sandy@LinuxAndPeppermint ~ $

sudo fdisk /dev/sda3

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
Then use ‘d’ command to delete the selected partition.
Command (m for help):

d

And after it’s deleted you can create a new partition by using ‘n’ command and finally write all the changes to the disk by passing ‘w’ command.

Conclusion

So that was all for now on how to manage Linux partitions. In this article, we taught you listing Linux partitions, creating Linux partitions, resizing partitions and deleting partitions using three main partition management tools in Linux.

I will keep updating articles with more commands and options. As I said above, if you have any question, drop it in the comment section below this article. I will try my best to cover that as well in this article.

Our sponsor - Deploy your server within 3 minutes


7 comments

franz ulenaers November 4, 2019 at 1:02 am

I am missing here gpt-partitions made with the gdisk utility

Reply
Mohd Sohail April 4, 2021 at 4:19 am

Yes I missed that. I will cover that separately or will update this article with gdisk.

Reply
franz ulenaers April 4, 2021 at 2:42 pm

thanks,
Good article !

Reply
Jim November 4, 2019 at 2:59 pm

While I always install gparted for hard drive issues, I install and often use gnome-disks for simple tasks like formatting a USB key or just checking a disk.

Reply
Mohd Sohail April 4, 2021 at 4:21 am

gparted is a good choice for GUI lovers. But other tools I have mentioned here are fast and have more options.

Reply
Ram Sambamurthy January 4, 2021 at 10:11 pm

I didn’t know about cfdisk until reading this article. it’s so much faster than gParted which is so slow while reading partitions.
Thank you.

Reply
Mohd Sohail April 4, 2021 at 4:24 am

Thanks for reading! And yeah CLI tools are faster and have much more functions than some popular GUI tools.

Reply

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More