Making sense of partition tables

17

1

This is output of fdisk:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   419424255   209711104   83  Linux
/dev/sda2       419424256  1258291199   419433472   83  Linux
/dev/sda3      1258291200  1300236287    20972544    f  W95 Ext'd (LBA)
/dev/sda4   *  1300236288  1709836287   204800000    7  HPFS/NTFS/exFAT
/dev/sda5      1258293248  1275062271     8384512   82  Linux swap / Solaris

And this is output of cfdisk:

Name         Flags       Part Type   FS Type           [Label]         Size (MB)
--------------------------------------------------------------------------------
                                     Unusable                               1.05  *
sda1                      Primary    ext4                              214744.18  *
sda2                      Primary    ext4                              429499.88  *
sda5         NC           Logical    swap                                8586.79  *
                          Logical    Free Space                         12889.10  *
sda4         Boot         Primary    ntfs                              209715.20  *
                                     Unusable                          124768.71  *

I am supposed to have 2 Linux partitions, 1 Windows partition extended partition of about 20 GB with logical 8GB swap partition and about up to 130GB un-partitioned space.

As if it wasn't enough, output of gparted is also kind of different. enter image description here

I am confused from the outputs which I posted here.

  1. Why is /dev/sd4 marked as bootable if I boot to GRUB2?
  2. What is /dev/sda3? What is its type (primary/logical)? Why it is not displayed in cfdisk?
  3. Why is that free space (I suppose 124768 in cfdisk) marked as unusable?
  4. What does NC flag mean in cfdisk for swap partition?

ps-aux

Posted 2014-07-14T16:47:21.707

Reputation: 3 397

Answers

26

Why is /dev/sd4 marked as bootable if I boot to GRUB2?

The bootable is a flag in the MBR (actually a byte which is compared to 0x80). That entry is marked as bootable. A 'traditional' bootloader reads the MBR, looks for an entry with the bootable flag, and passes control to it. As you are using grub, it does something completely different, as it instead uses its configuration file. But the tools are telling you how are partitions configured (actually, you may have a bootloader in the MBR jumping you to /dev/sda4, and grub2 installed there).

What is /dev/sda3? What is its type (primary/logical)? Why it is not displayed in cfdisk?

/dev/sda3 is a primary partition of type extended partition. It's a partition used as container for other partitions. gparted is showing it quite well on its graphic.

You could argue if it's actually a partition or not, on the one hand it takes a slot in the MBR, on the other hand it's a container of partitions, you don't put a filesystem there.

Partition tools treat them specially, so cfdisk seems to prefer not to show it. fdisk for instance also doesn't allow some actions on those partitions.

Why is that free space (I suppose 124768 in cfdisk) marked as unusable?

I think those are the 116.20 GiB showed by gparted at the end

You can only have up to 4 primary partitions (counting the extended partition). That comes from the number of slots at the end of the MBR. As you already have 4 of them, that unallocated space at the end can't be partitioned (you can't put a logical partition there, since you can only have a single extended partition, and it shall be contiguous).

Your (easy) options to use that space would be to either:

  • extend /dev/sda4 to use it
  • extend /dev/sda3 to include /dev/sda4 (and preferably also to the end of the disk) and make /dev/sda4 a logical partition

What does NC flag mean in cfdisk for swap partition?

Quoting the cfdisk man page: "The flags can be Boot, which designates a bootable partition, or NC, which stands for "Not Compatible with DOS or OS/2"." Not something to worry about

Ángel

Posted 2014-07-14T16:47:21.707

Reputation: 960

11

Let's start out...

  1. It's marked as bootable, so that Windows can load its boot loader from it. Even though Grub may load first, it will "chainload" into the Windows boot loader, if Windows is selected from the list. For the Windows Bootloader to run, it needs to be on a bootable partition (Could someone double check this for me? I've never tried removing the Bootable flag on a Windows 7 install...)

  2. SDA3 is actually an Extended partition. Your disk is formatted as MBR, instead of GPT. One of the restrictions is that MBR can only have up to 4 primary partitions. To get around this, you can use an Extended primary partition, to then create multiple smaller logical partitions inside (getting you more than 4 partitions).

  3. Because of the MBR limitation, it can't create a 5th primary partition outside of the Extended Logical partition. This is normal. If you extend the Extended Partition, then you should be able to create a new partition inside of it, and use the rest of your disk.

  4. From the cfdisk Man pages:

The flags can be Boot, which designates a bootable partition or NC, which stands for "Not Compatible with DOS or OS/2".

Canadian Luke

Posted 2014-07-14T16:47:21.707

Reputation: 22 162

No problem. I was posting the same answer(s), and that one was the only one that you didn't nail down better than me. ;) – Ƭᴇcʜιᴇ007 – 2014-07-14T17:32:08.417

3

Partitions 1 to 4 are by convention "physical" (they were the only type available back in the times). So you have:

Device    Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   419424255   209711104   83  Linux
/dev/sda2       419424256  1258291199   419433472   83  Linux
/dev/sda3      1258291200  1300236287    20972544    f  W95 Ext'd (LBA)
/dev/sda4   *  1300236288  1709836287   204800000    7  HPFS/NTFS/exFAT

/dev/sda5      1258293248  1275062271     8384512   82  Linux swap / Solaris

...sda1 is physical, Linux. sda2 is physical, Linux again. sda3 is a logical partition where other partitions (5 onwards) may reside. Finally sda4 is a Windows partition, marked bootable - I think only Windows cares for that anymore. GRUB2 will gladly boot whichever partition you desire, but Windows wants to be on a bootable partition.

Now, inside the logical partition sda3, that cfdisk does not show as such, there are the equivalent of more physical partitions. In this case only sda5.

And since sda3 goes from sector 1258M to sector 1300M, but sda5 only uses them up to 1275M, sectors 1275062272 to 1300236287 are free (but allocatable to sda6).

Finally, your sda4 (the last possible physical partition - the MBR only holds four) does not fill up to the end of the disk. It leaves about 116Gb off. That space is unusable because you cannot create a physical partition to cover it (the extended partition sda3 can't grow, because its extent is "blocked" by sda4):

[SDA3...(sda5)...| FREE    ][...sda4...][ UNREACHABLE SPACE ]end-of-disk

Solutions to recover the unavailable space

None painless, I'm afraid. Depending on the geometry, you could delete sda4 and annotate its boundaries. Then grow sda3 to include the whole disk (same start, 1258291200, but end up to the end of the disk), or delete it and recreate with same start and maximum end. Now you can create a partition sda6 inside sda3, and make it so it ends at the cylinder just before sector 1300236288. This will occupy the free space currently left in the existing sda3. Finally you create a partition inside sda3, and it will be sda7, telling the system it extends from 1300236288 to 1709836287 and is type 7.

If you do not format that partition, the contents will remain as it is, and it is a valid Windows partition. It is

Of course if things go wrong, you stand to lose all of your data. Physical partitions (as the Windows one is now that is sda4) and physical-inside-logical partitions (as it would be once it became sda7) do not necessarily mix; some tools will flat refuse to create them. I'd suggest making a test on a virtual disk of the same size, created inside a sparse file (the file itself would really be only a few gigabytes) or on an external disk.

Another way, maybe safer, is to delete sda5 (it's just swap) and sda3, move sda4 parameters to sda3 (this may imply deleting sda4 and recreating sda3 with the old sda4's parameters), and this will leave the sda4 slot free (and a "hole" in the middle of the disk). Most BIOSes allow for out-of-sequence partition tables. Again this should not require copying anything. sda4 now becomes sda3 and remains a physical partition, so its geometry should better agree with a partitioning tool's assumptions.

Of course the recommended and safest way (and slowest) of all is to backup all the partitions, reformat them all, and restore them after having "repositioned" them properly, with the extended partition last and occupying the whole remaining hard disk. This will get rid of the free space inside sda3 and reclaim the unavailable space at end, with no risks (if the backup is done properly - check it after backing up. I once backed up on a faulty external disk, which died on me upon restore. Wasn't amusing at all).

LSerni

Posted 2014-07-14T16:47:21.707

Reputation: 7 306

0

In addition to what was already said about the meaning of all this, I think the most painless solution would be to have the swap space in the big area at the end and to add the empty space in the middle to your /home.

To do so, you have to

  • delete your swap file as soon as it is unused, and as well the extended partition holding it
  • extend your sda2 to include the complete empty space after it (you'll have to delete and recreate it).
  • recreate the extended partition to sit after sda3 and use it to hold as many partitions as you want (well, within certain limits).

This is most easily done with cfdisk, as it handles the extended partition dynamically. But take care that sda2 keeps its starting LBA, as otherwise you will lose its contents.

After extending the partition size, you have to resize the file system enclosed to make use of the full space.

glglgl

Posted 2014-07-14T16:47:21.707

Reputation: 1 327