multi-OSes and partitioning

Alan McKinnon alan at
Sat Apr 8 20:15:45 UTC 2006

On Saturday 08 April 2006 20:12, taeb wrote:
> Hi:
> I've been using Linux for some time on an old Mac, but recently
> started using it on a PC, and discovered the four-partition limit. 
> It has taken me a while to get my foggy brain wrapped around how
> that works -- and I'm still wrapping.  I'd like to get some
> feedback on this topic.
> Even though I don't run any M$ software on my machine, it still has
> the 4-partition limit -- well, top-level limit.  That's required
> because of the BIOS, right?

No, it's more of a throwback to the bad old days of MS-DOS. Windows 
still uses the "4 primary partitions or 3 primary plus one extended" 
scheme so in the interests of dual booting, Linux systems tend to 
stick with it too.

> At first I thought this limit meant only four systems per disk, but
> some of the stuff I've read says you can have an arbitrary number
> of sub-partitions in an extended partition.  OK, so one primary
> (required I think) and then the rest of the disk an extended
> partition which I can sub-divide into an arbitrary number of
> partitions to hold other OSes. Easy --  except the non-linux OSes
> I've read about say they need a primary partition.  Why?  There
> must be some distinction between primary and extended other than
> the ability to sub-divide the extended.

An extended partition is a special kind of primary partition and there 
can only be one of them. This extended partition "contains" other 
logical partitions (it acts like a box to put the logical ones in). 
The absolute limit is 64 partitions total per disk, but I've seen 
implementations that limit you to 16.

You don't have to have a conventional primary partition at all, in 
fact a default Ubuntu install will give you one extended with two 
logical inside. You won't be able to dual-boot Windows on a disk like 
that though (maybe XP can cope with it, but '98 certainly couldn't).

You might run across the term "bootable" partition or some such. 
That's another DOS thing, DOS didn't use a real boot loader so it 
figured out which partition to load the OS from by looking at this 
flag. You can safely ignore this for Linux, and set a Windows 
partition to bootable. grub and lilo are both smart enough to not 
need such bizarre work-arounds. Windows must have a primary partition 
to boot from, simply because Microsoft coded it that way - don't try 
and figure out the logic here, because there isn't any logic to it - 
it just is that way.

Here's my disk layout:

develop genkernel # fdisk -l /dev/hdb

Disk /dev/hdb: 163.9 GB, 163928604672 bytes
255 heads, 63 sectors/track, 19929 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot  Start       End      Blocks   Id  System
/dev/hdb1   *       1        13      104391   83  Linux
/dev/hdb2          14       143     1044225   82  Linux swap / Solaris 
/dev/hdb3         144     18119   144392220    f  W95 Ext'd (LBA)
/dev/hdb4       18120     19929    14538825   83  Linux
/dev/hdb5         144      1417    10233373+  83  Linux
/dev/hdb6        1418      2055     5124703+  83  Linux
/dev/hdb7        2056      2692     5116671   83  Linux
/dev/hdb8        2693      3330     5124703+  83  Linux
/dev/hdb9        3331      3967     5116671   83  Linux
/dev/hdb10       3968      6517    20482843+  83  Linux
/dev/hdb11       6518      7126     4891761   83  Linux
/dev/hdb12       7127      8429    10466316   83  Linux
/dev/hdb13       8430     14803    51199123+  83  Linux
/dev/hdb14      14804     17380    20699689+  83  Linux
/dev/hdb15      17381     17510     1044225   82  Linux swap / Solaris
/dev/hdb16      17511     18119     4891761   83  Linux

/dev/hdb1, 2 and 4 are primary partitions. /dev/hdb1 is the one marked 
bootable but this is meaningless for me. Note that sectors used 
by /dev/hdb1 to 4 follow consecutively to use all 19929 cylinders on 
the disk. /dev/hdb3 is the extended partition, and it contains 
partitions 5 to 16 (check the sector numbers). Observe that hdb3 
isn't the last primary partition; there are some docs on the internet 
that say it must be but this isn't true. Mine is hdb3 because I, um, 
made a mistake when setting up the partitions :-)

> One of the man pages -- fdisk I think -- said you can have swap as
> a (primary) partition or a sub-partition, but the primary partition
> was more efficient.  What is the extra overhead involved in
> accessing sub-partitions, and doesn't that imply a performance hit
> for accessing, say, /usr in a sub-partition rather than a primary? 
> How much of a hit is it?

I think you are getting confused between swap partitions and swap 
files. Partitions are more efficient because the kernel can use the 
clusters directly. With a swap file it has to go through the disk 
subsystem - an extra step.

There is no difference between using a primary and a logical 
partition. Once the kernel knows which disk cylinders are involved 
with a partition it can get them from the disk with no further 
information needed. There is only one reason for having extended 
partitions at all - the original DOS conventions only had space for 4 
partitions in the MBR. Once a Linux kernel is running it couldn't 
care less about this limit.

> Also, if I have swap in a primary partition I presume I can use the
> same swap area for different OSes.  Couldn't I also share the swap
> if it were in a sub-partition?

That's what I do - I have a primary and an extended swap partition. 
You can usually share swap between OSes - the whole point is that 
data on swap is not supposed to survive a boot. Two gotchas:

There's an ID field to identify what disk conventions are used on a 
partition. Unfortunately Linux swap and Solaris happen to use the 
same value for this :-( Dual-booting Linux and Solaris means you must 
be careful that these OSes don't step on each other. Safest is to set 
these two up to never share each other's partitions.

Suspend to disk usually dumps RAM to a swap partition so that it can 
be read back when the machine wakes up. If you suspend, then run a 
different Linux distro that uses the same swap, then try resuming the 
first distro, it won't work - the suspend data has been clobbered.

Other than these two rare cases, it's safe to share swap.

> Finally, the pertinent info on my PC system is:  P4-630, 2GB RAM, 1
> SATA DVD-RW and 1 SATA 160GB HDD.  Although Ubuntu is my primary
> system I want to have three other OSes also: freeDOS, because I
> might need to update the BIOS some day; Minix3 -- if it ever
> supports my SATA DVD-RW -- because I think it's interesting; and
> freeBSD to see what it's like.
> The partitioning scheme I'm planning to use is:
> P1: freeDOS     ~100MB
> P2: minix3      ~900MB
> E3: freeBSD     ~59GB
> E4: Linux       <remainder of disk>
> Inside E4 would be partitions 5-9 laid out something like:
> p5: Linux-1     to hold one version of Ubuntu -- current or next
> p6: Linux-2     to hold another version of Ubuntu
> p7: swap
> p8: Home

That won't work, you have two extended partitions and can only have 
one (maybe E3 is a typo). This will work better:

P1: freeDOS	~100M
P2: minix3	~900M
P3: freeBSD	~59G
E4:		remainder
  L5: Linux 1
  L6: Linux 2
  L7: swap
  L8: home

Remember that Linux couldn't care less about this weird partition 
convention. The only software where it matters is fdisk and others in 
the same class.

> Any comments on conflicts or problems or whatever?

Need any help with the deep dark voodoo secrets on getting grub to 
work intelligently on a multi-OS disk? :-)

Alan McKinnon
alan at linuxholdings dot co dot za
+27 82, double three seven, one nine three five

More information about the ubuntu-users mailing list