Linux Partition Management
Table of Contents
Linux partition managers
- GUI based tools
- CLI based tools
List drives & partitions in Linux
1. Gparted list partitions
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
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
/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
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
Enter the new partition size and hit ‘Add’ button.
2. cfdisk Create Partition
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
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.
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 ]
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ │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.
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│Partition type: Linux (83) │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘
[Bootable] [ Delete ] [ Resize ] [ Quit ] [ Type ] [ Help ] [ Write ] [ Dump ]
The partition table has been altered.
3. fdisk Create Partition
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.
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):
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 (default p):
p
Partition number (1-4, default 1):
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
2. cfdisk Resize Partition
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 >> /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
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ 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.
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
2. cfdisk Delete Partition
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 >> /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
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
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):
Command (m for help):
d
Conclusion
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.
LinuxAndUbuntu Newsletter
Join the newsletter to receive the latest updates in your inbox.