Partitions and filesystems

Here are a few notes to add to the information we went over on partitions.
First, why partition again? I forgot...
Partitioning helps you to monitor what is taking up too much space on your disk, and keeps any file from filling up your whole disk and making your system difficult or impossible to use. When a disk is partitioned, the most a run-away file can fill up is it's partition. Also a partitioned disk can be a speedier. Partitions are also handy from keeping user data apart from system data. Many backup systems are built to backup a certain partition (though with newer tools suchas rsync this isn't as true anymore) but you find that most parts of a free software system are replacable. you can download a whole new system for free if you ever have to replace all the system software, however it is much harder to replace your private data, all your emails and writings. Having them all on one partition makes it easier to know what to try to recuperate if there ever is a problem. (All hardware will fail :)
Review hardware concepts:
First the PC IDE interface, which is a hardware standard, allows for 4 partitions. Under linux these are called primary parititions, because linux has developed a software extention called extended partitions. If you declare one (or more) of your primary paritions as being extended, you can then redivide these extended partitions into as many logical partitions as you like (there is an upper limit of 64 I think -I know that under ppc -linux which runs on macs the limit is 15 which is much more constraining).

You can't write a filesystem directly to an extended partition, you must create logical partitions within the extended partition in which you can lay down your filesystems.

The partition numbers /dev/hda1-4 are reserved for the primary partitions. Logical partitions, under fdisk will start numbering themselves as /dev/hda5, and continue /dev/hda6 etc.. This is good to remember because it allows you to recognize a partition as being primary/extended or logical . Primary will be /dev/hda1-4 (any of which could be extented), the first logical /dev/hda5, all others after that /dev/hda6+

Swap is a type of partition which the kernel uses when it has run out of memory (RAM). Swap should be in a primary partition. This helps to make the linux memory system very safe as it is much harder to overwrite files in your harddrive if there is a memory problem. I usually place my swap partition in the middle of the other partitions because I was told this was the fastest way. The needle on the harddisk is most often closer to the middle than to either of the two edges of the plates. Ruben tends to think that the hardware places the first partitions in the middle of the disk for this reason and that thus the fastest place to put swap is in the first partition. This issue cannot be solved without testing, and may be different for different harddisks, so I propose not to discuss it further.

Some points on how partitions get mapped to the directory tree:
The main root "/" partition, for a kernel is specified in the boot loader. This root partition has an entry in its filesystem for each directory inside it such as /sbin, /etc /var etc. . Some of these entries are mapped to the "/" node of another partition. So /var might actually be a link (or node) from your main file system to another partition. This link is called a mount point. There is a file in your /etc directory called fstab which maps all of these mount points to the different partitions partitions on your system. Any partitions mapped in /etc/fstab will be mounted automatically at boot time.

If a partition is not mounted, say the partition which contains the contents of your /var directory, /var will look empty. It is possible to mount partitions on different mount points either on the fly by using mount and unmount, or to do this permanently by editing /etc/fstab. It is also possible to hide a directory by mounting a partition on it's mount point. Say you mount a partition to /var, but there is directory information in the /var directory under the root "/" partition, this information will be hidden.

There are a few directories which should always be in your root "/" filesystem partition. These include /etc, /bin and most absolutely /sbin. This ensures that incase your system is only able to boot it's root partition, you will still have a working system.

These points are complicated so let me try to run through this again looking from the angle of your system booting: (I've had enough! and this guy want's to keep talking?)
Each partition with a file system, has a top node "/". You must tell the boot loader which partition is your root partition for each kernel (operating system) on your system. This root partition will be the "/" partition for your whole system. The boot loader is the small file in the masterboot record on your harddisk which knows where the different bootable partitions are on your system and where the kernels are in these partitions (yes you can have multiple kernels for testing or different needs).

The bootloader, loads your kernel into memory from the harddisk, and starts a first process called init. The init binary is stored in /sbin (remember /sbin must be in the root partition?). One of the things init does in bringing up the system is to read a file called /etc/fstab to find out where on the main tree it should mount the other partitions. /etc/fstab maps filesystems to mount points. (/etc/fstab stands for filesystem table-- also remember /etc must be in the root "/" partition). Thus a partition gets mapped to /usr, /tmp, /var, /usr/local or /opt (or any you make up, such as, I like to have a /cd where I mount cd's because I don't like to type out /mnt/cdrom which is the default for most distributions).

More on partitioning schemes: (details, a religious war?)

It is a good idea to have /home on its own partition, because this is where your user's files will go (including you user). You wouldn't want to download too many mp3's and find yourself with such a full disk that your system can't run.

Also it is good to put /var in it's own partition because this is where all the log files for all the processes in your system go. By limiting /var to it's own partition you know how much space the log files are taking up, and that they can't fill up your whole disk. Some problems create so many logs that /var could fill up your disk (linux tries to inform you of what's going wrong remember -- This is not about calling tech support to order your next $129 upgrade). If you are having problems with a program or with your system /var is where you will do alot of diagnostics.

/tmp is where your system writes some dynamic runtime information. Some programs will put working files in /tmp, or download to /tmp, beware though /tmp does get wiped clean when you reboot, so this is not the place to put files you want to keep. I have used /tmp to make images of a disk when I am burning cd-roms so you might want to be sure to make /tmp larger than 650M.

You may also want to make /usr , /usr/local or /opt on their own partitions as these are where all the downloaded programs tend to go and can start to fill up alot of space.

There is no one way to partition. You probably will have to have partitioned a few systems to get a good idea how you prefer. Also as Ruben described in class you can be suprised by a new distribution which has so many new programs, and might require a new partitioning scheme.

Copyright Marco Scoffier, released under the GFDL