Linux has a complicated hierarchy of files and folders that can be confusing right from the start when a user is trying to migrate to Linux. When asked for partition information by the installer, a user may feel uncomfortable continuing. We’ll try to sort through some of that mess here.
About the Linux filesystem hierarchy
Linux has a filesystem hierarchy that is pretty common amongst various flavors of Linux. Let’s look at a few of the most common ones:
Note: It is easy to confuse “root” as in the user and “root” as in the root directory. The two are separate; the root directory is “/”, the root user is “root”.
- “/” – pronounced “slash”, it is also referred to as “root” (see next item). “/” is the trunk of the file tree. It serves as a starting point of the filesystem. Every other file or directory is subordinate to “/”.
- “/root” – not to be confused with “root”, it is usually the home directory for the root user (remember the note above). It typically contains installation logs and a few scripts used by the system administrator. It is a good idea to at least make sure it is on the root partition.
- “/bin” – where the essential user binaries are stored for both admin and users, such as “ls”, “cat” and “mv”. It should be on the root partition.
- “/sbin” – the location of essential binaries used for system administration and by the system itself. It should be on the root partition.
- “/lib” – where libraries needed by binaries in the “/bin” and “/sbin” are stored. This directory also needs to be on the root partition.
- “/boot” – where the boot loader (from the MBR) looks to load the kernel. This is before any other partition is mounted or any user mode programs are ran. To the bootloader, this partition is root. Then, the bootloader loads the kernel (which resides in the /boot partition) and tells the kernel which partition it should use as root.
- “/etc” – an acronym for… well actually no one agrees on what it stands for. The majority seems to think it stands for et cetera. It is basically where your configuration files go.
- “/home” – the place for user account directories. Typically, each user has a directory within “/home” where they have all control over it and whatever may be beneath it. Also, user specific configurations may be stored in it’s sub structure.
- “/usr” – contains the subdirectories “/usr/bin”, “/usr/sbin,” and “/usr/lib” which perform similar purposes as “/bin”, “/sbin”, and “/lib”, but are not needed at boot time. Non-essential user and system binaries may be stored here. “/usr” contains also documentation for the binaries and libraries.
What is a partition
A partition is a division in the hard drive (HDD). One HDD can be separated into multiple partitions. This division is actually done by putting an entry into the proper partition table on the HDD pointing to the block that begins the partition. There are two types of partitions, logical and extended. There can be up to 4 partitions in the primary partition table. HOWEVER, the extended partition points to an extended partition table and can have even more partitions within it.
This is a whole post within itself. Usually the default will be fine. EXT3 is pretty popular. Unless your doing something really specific, EXT3 should be fine. Another filesystem type is swap. There should always be a swap partition. It is a special filesystem used by the operating system as “swap space”, or temporary storage for recovery and RAM overflow. Generally, it should be twice the size of your ram.
First, let’s talk about mount points. A mount point is simply a directory on one partition that is used to mount the root (top level of that partition) of another partition. What this means is that once you mount the numerous partitions, you can navigate to them just as they were part of the root partition. Say you had a partition (we’ll call this one “p1″) with two directories inside named “mounted” and “not_mounted”. Their paths would be of course “/mounted” and “/not_mounted”. Inside each of those directories you create a file called “seeme”. The structure would like like this:
Now say you had another partition (this one is “p2″) with 5 files in the root of it. Say the files were simply called “one”, “two”, “three”, “four”, and “five”. The structure for this partition would be like this:
Do you know what would happed if you mounted “p2″ to “p1″ using “/mounted” as a mount point? Let’s see what happens to the file structure then. You get:
Now what happened to “/mounted/seeme”? It’s still there, but will be invisible while that directory is being used as a mount point. Usually, if a directory is being used as a mount point, you should not put files in it.
Benefits of using separate partitions
Put simply, keeping directories that tend to fill up separate from directories needed by the system to function safeguards the system against a crash. If “/home” and “/tmp” were both on the same partition, they would share the same HDD resources. When “/home” fills up, the operating system would not be able to allocate storage to other important system functions that need “/tmp”.
Another plus is that you can format one partition and keep the data on another. You can reinstall your operating system without losing data on the “/home” partition. Also, in the case of a partial HDD failure, your chances of saving data is increased.
Deciding which directories to partition separate
There are so many correct ways of partitioning your HDD. Of course, this is based on the needs and available resources for your system. You may choose to only have one partition (plus another swap partition). Here are some considerations:
- swap should be twice the size of your ram
- most of the storage is going to be used by the “/home” directory for a desktop
- keeping “/home” on a separate partition allows you to reinstall another operating system and keep the data on “/home”
I will explain my setup as an example:
Fedora 7 on 100GB HDD “sda”
|partition||logical or extended||mount point||size||notes|
|sda2||logical||/boot||100MB||I use this for multiple Linux installations|
|sda3||logical||swap||2GB||1 GB ram x 2|
|sda4||extended||N/A||remaining ~61GB||This contains the other partitions|
|sda5||extended||/ or /mnt/FC6||15G||This is my Fedora Core 6 installation|
|sda6||extended||/ or /mnt/F7||15GB||This is my Fedora 7 installation|
I hope that I’ve given you some insight into how to partition your HDD as a new linux user. Whatever happens, don’t let frustration with learning hinder your decision to stick with Linux. While the learning curve is pretty steep to begin with, the benefits are ten-fold.