5

I had my primary partitions maxed out but I deleted some and now I want to make one of my logical partitions a primary. Can I do this with gparted or other free tools?

Thanks

1
  • you probably can't. Why do you need a primary partition? Can you post fdisk -l
    – Jure1873
    Aug 1, 2009 at 19:01

6 Answers 6

6

Before you do anything, do a full metal backup as things do go wrong with these types of processes.

The "easy button" is Acronis Disk Director for $24.

The other way to do this is by editing your partition table.

NOTE: This procedure doesn't work (I don't think) on a system (like a Mac) that uses EFI.

To do that, boot off a linux live CD and run:

sudo sfdisk -d /dev/sda > partitions.txt

...in a folder you can write to. That will give you a file called partitions.txt that has your partition table. Then edit that file using your favorite text editor, and put your logical partition above your extended partition by changing the numbers and order.

For example, if your sda5 is the partition you want to make primary, change "sda5" to "sda1" (or 2/3/4) and push the rest of the numbers down. The main point is you want to make sure the start, size, and id are the same.

Then run:

sudo sfdisk --force /dev/sda < partitions.txt
5

General

Under some limited constraints it is possible to convert a logical partition into a primary. This is however a rather uncommon operation, so I am not aware of any tools that support this out of the box in one operation, although you should be able to do it yourself with the help of parted, fdisk or similar programs, although possibly by re-calculating start/end for partitions manually.

Some years ago I wrote a program to print the content of the partition table. Let's say that your disk is partitioned in the following way:

                      Disk /dev/hda (CHS=30401/255/63)
                      WDC WD3200JS-00PDB0

                     +------------------------------+
            0 - 1043 |             hda1             |   8189 Mb
                     +------------------------------+
         1044 - 2087 |             hda2             |   8189 Mb
                     +------------------------------+
         2088 - 4699 |             hda3             |  20489 Mb
   + - - - - - - - - +------------------------------+
   .     4700 - 5483 |             hda5             |   6150 Mb
   .                 +------------------------------+
   .     5484 - 5999 |             hda6             |   4048 Mb
   .                 +------------------------------+
   .     6000 - 7044 |             hda7             |   8197 Mb
   .                 +------------------------------+
   .     7045 - 8089 |             hda8             |   8197 Mb
h d a 4              +------------------------------+
   .            8090 |             hda9             |  40986 Mb
   .           13314 |                              |
   .                 +------------------------------+
   .           13315 |                              |
   .                 |                              |
   .                 |            hda10             | 134027 Mb
   .                 |                              |
   .           30400 |                              |
   + - - - - - - - - +------------------------------+

Here hda4 is the extended partition containing the logical partitions. By shrinking hda4 (to cover cylinders 4700 to 13314 or cylinders 5484 to 30400) it would be possible to make either hda5 or hda10 into a primary partition.

Now from a strictly theoretically point of view it could perhaps be possible to put a primary partition inside the extended (instead of shrinking the extended partition and only being able to change the partitions at the ends), but who knows what avalange of compability problems you would trigger by that. That would be considered to be a sane partition layout by an extremely low number of programs/persons (if any/anyone).

In the concrete example above, the partition table already contains 3 primary partitions in addition to the extended partition, so there are no entries left to create a primary partition; you would have to delete one of hda1, hda2 or hda3 in in order to possibly change hda5 or hda10 into a primary partition.

Your question

You say that you have free entries to make a new primary partition, so that should be ok. You do not however specify any details for the logical partition that you want to convert, so I cannot say if that is possible without you giving more details.

Steps to do it

  1. Save/print out a copy of the partition table as it is before you start messing with it. This can be done with my printpar program, or with parted while using unit sectors ("Fdisk -l" can also be used, but this is only reliable if the partitions starts at exact cylineder boundaries (which traditionally have been the case, however is becomming less common)).

  2. Make sure the copy from point 1 is available either on paper or some storage other than the disk you are modifying.

  3. For all steps below, make sure that the partition editing program does not touch the filesystems in any way while doing the operations mentioned (i.e. for parted you should use 'mkpart' and not 'mkpartfs').

  4. Delete all the logical partitions (e.g. hda5 to hda10), and then delete the extended partition (e.g. hda4).

  5. Recreate the extended partition, now with either the start or the end moved so that the partition to be changed ends up outside the extended partition (e.g. hda4 covers cylinders 4700 to 13314 or cylinders 5484 to 30400, only that cylinded numbers are not 100% reliable, you should use sector numbers which will exact).

  6. Recreate all the logical partitions except the one to be changed (e.g. hda6 to hda10 or hda5 to hda9), making sure that they start and end at the very exact places as before (which is why you want to operate on absolute sector numbers).

  7. Recreate the partition which should be changed as a primary partition, also starting/ending at the very same locations as before. In this step it is extremely important to be able to give locations in absolute sectors, because the new primary partition would then typically be created with a 63 sectors offest compared to where the original logical partition were.

  8. Print out a new copy of the partition table and compare. The only differences should be the new primary partition, the start/end of the extended partition, and possibly renumbering of the logical partitions.


For the example above, if the original hda3 partition is deleted (to give an free entry for creating a primary partition) and hda5 is converted to a primary partition (which then becomes hda3), the layout would be the following:

                     +------------------------------+
            0 - 1043 |             hda1             |   8189 Mb
                     +------------------------------+
         1044 - 2087 |             hda2             |   8189 Mb
                     +------------------------------+
         2088 - 4699 |            unused            |  20489 Mb
                     +------------------------------+
         4700 - 5483 |             hda3             |   6150 Mb
   + - - - - - - - - +------------------------------+
   .     5484 - 5999 |             hda5             |   4048 Mb
   .                 +------------------------------+
   .     6000 - 7044 |             hda6             |   8197 Mb
   .                 +------------------------------+
   .     7045 - 8089 |             hda7             |   8197 Mb
h d a 4              +------------------------------+
   .            8090 |             hda8             |  40986 Mb
   .           13314 |                              |
   .                 +------------------------------+
   .           13315 |                              |
   .                 |                              |
   .                 |             hda9             | 134027 Mb
   .                 |                              |
   .           30400 |                              |
   + - - - - - - - - +------------------------------+

Notice that all the remaining logical partitions are renumbered compared to the original situation.

1
  • You just spared me a complete re-install of Linux. Thanks a million. Jun 8, 2012 at 1:14
5

My FixParts program is an open source tool that can do the job, albeit with constraints of what can be converted based on MBR's limitations and limitations imposed by your current layout. (FixParts is a partition table editor alone; it can't shrink or move partitions, so if your primaries are all crammed up against each other with no room between them, the only one you could convert to a logical partition would be the first one.)

1
  • This software is awesome. Some resizing magic with gparted to make space for extended partition headers and it did the rest very easily. Otherwise I would have needed quite a bit of time searching for specs and editing the raw disk with dd.
    – Alicia
    Aug 9, 2015 at 23:03
3

I used system rescue cd TestDisk and after doing a quick scan it list all my partitions and I flipped the L to a P then rewrote the partition table

it was dirty but it worked

1
  • I can confirm this just worked for me :)
    – squareborg
    Nov 23, 2011 at 12:11
2

Paragon Partition Pro bootable disk converts logical to Primary easily. Just did it.

0

You can use Partition Wizard (has a free version) and follow the instructions in this article.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .