Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Every tutorial on Linux-based partitioning schemes (or, just partitioning in general) will tell you that a PC can have either 4 primary partitions, or 3 primaries and 1 extended. They will all also tell you that Linux (in my case, Ubuntu) can be installed on either.

It's also come to my attention that it is not too atypical for FHS directories, such as usr/, tmp/, etc/, home/ or var/ to be mounted separately on other partitions.

Several questions I am unable to find the answers to, purely for my own edification: (1) By "PC", are we really talking about common PC disk types, like IDE or SATA? I guess I'm wondering why PC uses are limited to 4 primaries or 3 primaries + 1 extended

(2) I'm choking on some basic OS concepts: it is said that a partition can be mounted by a file system or an OS. So I assume this means I can somehow instruct Ubuntu to mount to 1 partition, and then any part of, say, ReiserFS, to be mounted to another partition? How?

(3)(a) What about creating swap partitions? Is there too much of a good thing with swap partitioning? If I have 4GB RAM over 320GB disk, what should my swap partition size be, and why? (3)(b) Are swap files the only way to create swap partitions? Wouldn't a Linux partitioning utility allow me to define a partition as being for virtual memory only?

(4) Why are partitions limited to being "mounted" by just OSes and file systems? Why couldn't I write a program to take up its own, say, 512 MB partition, and then have it invoked or uses by an OS installed on another partition?

Thanks for shedding any light here... not critical that I know this stuff, but it's got me thinking incessantly. And when I think incessantly, I...can't......sleep....

share|improve this question
add comment

migrated from stackoverflow.com Dec 29 '10 at 3:05

This question came from our site for professional and enthusiast programmers.

5 Answers

1) Typically the "extended" partition you see can be subdivided into a number (the precise amount escapes me) of extended partitions, it was the original workaround to the 4-partition limitation that eventually everybody supported.

2) I have no idea what you mean here. Partitions are just logically segemented pieces of your hard drive. Think of your hard drive as a filing cabinet, partitions are the drawers. Except these drawers you can size however you need when you set the filing cabinet up, but you can't rearrange them without first emptying everything out. Each drawer can be formatted (organized) in a different way, with EXT, RFS, XFS, NTFS, etc. Every OS handles mount points differently, *nix systems handle them as normal file paths.

3a) Yes, there's a point of diminishing returns for swap size. ask 3 geeks, you'll get 3 different answers. In most modern machines, if the box has a ton of RAM, I typically don't do much more than match the amount of memory for swap space. If the machine's duties are such and it is under specced, I may bend that rule and give it more. If the machine's duties are light, and its over specced, I will give it less.

3b) Swap File != Swap Parition. Swap partitions are very specifically formatted pieces of the drive, formatted exactly as the OS formats its memory spaces, so that memory can be cleanly, and more importantly quickly, moved out of RAM and onto disk, and vice versa. This is one of those areas that has for so long allowed Linux to best Windows in many respects, since Windows resorts to a swap/page file, wherein memory must be translated back and forth into a page file, written in the native file system. It makes for a slow process, but allows them to be more dynamic in virtual memory usage.

4) There are some virtualization systems that do precisely that (pending I am understanding what you propose correctly).

share|improve this answer
add comment

peelman already covered the bases, I'll just add a couple of notes:

1) By PC, we are talking about the IBM PC standard from 1981. The 4-partition limit is a side-effect of the master boot record format IBM picked in 1980, and is still with us today since "PC compatible" is a big deal.

But the single "extended partition" can be split up into lots of "logical partitions", so you can have more than four partitions per drive in Linux, for example.

This limit is also on the way out due to a new standard called GUID Partition Table, part of an effort to replace the BIOS with something more modern.

3a) The traditional advice is that the swap partition should be twice the size of RAM, see this Ubuntu swap FAQ for a discussion.

share|improve this answer
add comment
    • By "PC", are we really talking about common PC disk types, like IDE or SATA?

      They hard drive connection is irrelevant to anything but the write speed of the drive. Nope. Disk types include CD, Hard drive, flash drive, etc.

    • I guess I'm wondering why PC uses are limited to 4 primaries or 3 primaries + 1 extended

      It's a holdover from when the human race was stupid and thought that 4 partitions was unthinkable. An extended partition is just a logical partition that holds partitions.

  1. I'm choking on some basic OS concepts: it is said that a partition can be mounted by a file system or an OS. So I assume this means I can somehow instruct Ubuntu to mount to 1 partition, and then any part of, say, ReiserFS, to be mounted to another partition? How?

    No. A partition is basically a part of the disk that looks to the computer to be another disk (kind of like cutting up a pizza slice in half--it's looks like they're two different slices, but they're really the same slice). You can mount partitions, that is, you say that no other system can use it because you're using it, and on that partition is a filesystem.

    Let's try a file cabinet metaphor. You have a file cabinet that represents your drive. You set up dividers inside it that keep different sections separate. Those divisions are partitions on your drive. And in each division you have hanging folders and some stray files. A partition without a filesystem would be just one really long sheet of paper. You divided that sheet of paper into different pieces, files, and their organizers, folders. That's your filesystem. Let's open it up. By looking through the files in a certain division, you have to mount it, that is, open up the cabinet, find the right section, and start fingering through it.

    • What about creating swap partitions? Is there too much of a good thing with swap partitioning? If I have 4GB RAM over 320GB disk, what should my swap partition size be, and why?

      There's not really too much of a good thing with swap except for the opportunity cost. A 64GB swap partition on a 128GB hard drive isn't helping anyone. Generally they say that double your RAM count is good (so that you have space to dump if you hibernate and they duplicate the ram on disk) but others say it's too much. I myself say that 320GB is a freaking huge amount of space that you can afford to allocate 8GB on.

    • Are swap files the only way to create swap partitions? Wouldn't a Linux partitioning utility allow me to define a partition as being for virtual memory only?

      No. Any decent partitioner has an option to set the filesystem for a partition to be swap. Linux goes through the drive in logical order (that is, by the logical partition #s) to search for swap and just grabs the first swap partition it finds. Any swap partition is dedicated to virtual memory.

  2. Why are partitions limited to being "mounted" by just OSes and file systems? Why couldn't I write a program to take up its own, say, 512 MB partition, and then have it invoked or uses by an OS installed on another partition?

    They aren't. Partitions contain filesystems. If you want to write such a program, it's possible, but will require root privileges since partitioning is about as dangerous as diffusing a bomb to the Linux kernel. When they are mounted they are opened to a world of glorious reading and writing and reading.

share|improve this answer
add comment

(1) By "PC", are we really talking about common PC disk types, like IDE or SATA? I guess I'm wondering why PC uses are limited to 4 primaries or 3 primaries + 1 extended

This is it the PC standard from 1980. For boot disks this is the simplest way to deal with disks on PC systems. The bios will read and execute code from the start of the first sector of the disk to boot the system. Other hardware use different patterns and may have a different number of primary partitions. Extended partitions use a partition table at the start of each partition, and chain from one extended partition to the next. There is an upper limit to the number of extended partitions allowed.

When using LVM (Logical Volmume Management) disks, I often format the raw disk as an LVM volume. When I only have one file system on a disk, I sometimes format the whole disk (/dev/sdb) instead of a partition (/dev/sdb1).

(2) I'm choking on some basic OS concepts: it is said that a partition can be mounted by a file system or an OS. So I assume this means I can somehow instruct Ubuntu to mount to 1 partition, and then any part of, say, ReiserFS, to be mounted to another partition? How?

A partition is mounted by the OS using a file system. A file system is method of formatting some disk so that it can store files and directories. or data in some other format.

(3)(a) What about creating swap partitions? Is there too much of a good thing with swap partitioning? If I have 4GB RAM over 320GB disk, what should my swap partition size be, and why? (3)(b) Are swap files the only way to create swap partitions? Wouldn't a Linux partitioning utility allow me to define a partition as being for virtual memory only?

(a) You generally want more than your RAM so that your system can hibernate to disk. Modern systems don't run very well if programs are swapping to disk. Except for use as tempfs (an in memory file system) backing store) extra swap space is likely wasted. I would use 8 to 12 GB as swap space. You want at least RAM + the size of your tmpfs partitions as swap space. (b) Swap files are the least preferred way to create swap space. A swap partition can be accessed relatively directly as it is to the disk. Access to a swap file needs to be mapped files disk blocks. A swap file may be useful when you need temporary swap space for a program with a huge virtual memory footprint.

(4) Why are partitions limited to being "mounted" by just OSes and file systems? Why couldn't I write a program to take up its own, say, 512 MB partition, and then have it invoked or uses by an OS installed on another partition?

Partitions are not limited to be mounted by just OSes or file systems. Normally permissions require root access to mount them, but this is changeable. There are programs which can use raw disk as storage.

  • This is one of the formats that can be used for to mount storage for the Oracle database. Oracle now has a variety of methods of using raw partitions.
  • Raw partitions are also one of the formats which can be used for Virtual Machine disk spaces.
  • A partition can be mounted as disk on a loopback device, and partitioned as another disk.
  • If permissions allow it, you could use a raw partition as file for almost any program, unless your file is as large as the partition you would be wasting space (usually a lot of space).
share|improve this answer
add comment

The answers you have received are mostly good. One thing to add about swap. If you have multiple hard disks (or SSDs) mounted on different buses, putting swap partitions on each can give increased swap speed by splitting the I/O requests across the two buses. Putting two swap partitions on the same disk offers no speed advantage and probably a penalty.

If you rarely swap, this won't make much of a practical difference.

share|improve this answer
    
I'd suggest you add that to one of the answers instead of posting your own. –  digitxp Jan 2 '11 at 4:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.