Linux – Convert primary partition to logical partition in linux

gpartedlinuxpartition

I have created new partition through Gparted in linux mint and now have used up all 4 primary partitions. Gparted directly created primary partition, the logical option was disabled.
So I cannot create any more partitions even though there is lot of free space on my disk.

How can I convert the data partition(non system related) to a logical partition, so that it frees up a primary one?
I would prefer a Linux solution, since I have recently switched to Mint 19.1 from Windows 10 though it is still present as dual boot.

Output of sfdisk:

sudo sfdisk -d /dev/sda
label: dos
label-id: 0xfc515ad7
device: /dev/sda
unit: sectors

/dev/sda1 : start=        2048, size=     1124352, type=7, bootable
/dev/sda2 : start=     1126400, size=   408475648, type=7
/dev/sda3 : start=   409602048, size=  1000001528, type=f
/dev/sda4 : start=  1409605632, size=    40960000, type=83
/dev/sda5 : start=   409602056, size=   409599984, type=7
/dev/sda6 : start=   819204096, size=    78123008, type=83      
/dev/sda7 : start=   897329152, size=     9762816, type=82
/dev/sda8 : start=   907094016, size=   195309568, type=83
/dev/sda9 : start=  1102403592, size=   307199984, type=7

Best Answer

The partitions are spaced well enough, and you could transform the primary partitition sda4 into a logical one sda10, if you first resize the extended partition sda3.

See below for a modified table that you could use with sfdisk /dev/sda < new_partition, and for a diff showing the modifications made. After this, you should have a free slot for another primary partition (a new sda4).

However I strongly advice you to first try it on a dummy file that you could create with

 $ dd if=/dev/null of=/tmp/dummy bs=1 seek=1000G
 $ sfdisk /tmp/dummy < new_partition

Then, as root:

 # kpartx -a /tmp/dummy

The last step will let the kernel attach a loop device (/dev/loop0 if it isn't already in use) to /tmp/dummy and scan all the partitions that you have created on it. Then you could check with partitioning tools like fdisk or gparted if they're able to parse the partitioning of /dev/loop0 fine. Only after all that proceed with the

# sfdisk /dev/sda < new_partition

followed by a reboot.

You should also change any references to sda4 to sda10 (and (hd0,msdos4) to (hd0,msdos10)) in /etc/fstab and /etc/grub.d/* (the latter followed by an update-grub).

By all means, do not accuse me of anything if you're hosing your system ;-)

It may be better to wait for another answer, there are probably automated tools that could convert your partition table to GPT or such things, or more friendly partitioning programs that let you do it in a guided way.

new_partition:

/dev/sda1 : start=        2048, size=     1124352, type=7, bootable
/dev/sda2 : start=     1126400, size=   408475648, type=7
/dev/sda3 : start=   409602048, size=  1040963584, type=f
/dev/sda5 : start=   409602056, size=   409599984, type=7
/dev/sda6 : start=   819204096, size=    78123008, type=83
/dev/sda7 : start=   897329152, size=     9762816, type=82
/dev/sda8 : start=   907094016, size=   195309568, type=83
/dev/sda9 : start=  1102403592, size=   307199984, type=7
/dev/sda10 : start=  1409605632, size=   40960000, type=83

diff:

@@ -1,9 +1,9 @@
 /dev/sda1 : start=        2048, size=     1124352, type=7, bootable
 /dev/sda2 : start=     1126400, size=   408475648, type=7
-/dev/sda3 : start=   409602048, size=  1000001528, type=f
-/dev/sda4 : start=  1409605632, size=    40960000, type=83
+/dev/sda3 : start=   409602048, size=  1040963584, type=f
 /dev/sda5 : start=   409602056, size=   409599984, type=7
 /dev/sda6 : start=   819204096, size=    78123008, type=83
 /dev/sda7 : start=   897329152, size=     9762816, type=82
 /dev/sda8 : start=   907094016, size=   195309568, type=83
 /dev/sda9 : start=  1102403592, size=   307199984, type=7
+/dev/sda10 : start=  1409605632, size=   40960000, type=83
Related Question