How should you partition a Linux install?

If you’ve recently decided to try out Linux for the first time, you may have noticed that when you boot your computer with the install DVD (or USB drive) in it, you’re asked to partition your hard drive and select things called mount points for different folder. This is completely unlike what one would do during the installation process of Windows, where the installer asks you to select (or create) a partition to install the operating system into and that’s about it. The first time you install Linux, you may be tempted to let the installer handle all of it, if only to avoid making mistakes that can potentially make your system unusable. That’s what I did when I installed Ubuntu for the first time and what I do with virtual machines because, let’s face it, I’m lazy and life is too short to waste time on disk partitioning.

However, partitioning disks isn’t a mere exercise in geekiness, but is actually a useful way to customize where your operating system stores data and to improve performance.

The Linux directory tree in a nutshell

Throughout this article, I’m going to use the names folder and directory interchangeably. It should be noted, however, that folder is typically used in the Windows world and directory is a UNIX term. For the intents of this guide, using the two terms is effectively the same thing.

We should discuss briefly how Linux (and by extension, other UNIX flavours as well) manages storage space. If you come from the Windows world, you may be surprised to find out that Linux does not use drive letters to identify disks and partitions. Instead, all storage is part of a single, unified tree that starts from a directory usually known as root directory and shown in the operating system as /. Note that the root directory should not be confused with a folder with the actual name of /root. The latter is inside the root / directory and is the Home folder of the user named root, the almighty administrator user.

Inside /, you will find a number of folders with uncommon and I even dare say unfriendly names, such as bin, usr, sbin, var, etc, and so on.

Here’s what each is:

  • /bin (binaries) stores binary files, i.e. programs, that must be available in the early boot stage, even before the usr folder is available. These are, for the most part, small programs that may be useful for troubleshooting a computer that is misbehaving;
  • /sbin (superuser binaries) is similar to bin, however, it contains programs that can only be executed by root or another superuser (e.g., by invoking them through the sudo command);
  • /proc is a “virtual” filesystem that is created every time the system boot and contains information about the system, its devices, and so on. Information within it can be read using the cat command (e.g., cat /proc/cpuinfo gives information about the processor);
  • /dev (devices) lists and manages the devices connected to the system, from the graphics card, to optical disk readers, to hard drives;
  • /usr (user)
    is the folder where general-purpose applications reside;
  • /etc (et cetera) originally was the directory where all files that didn’t fit into other folders were stored. Nowadays, it stores configuration files;
  • /home contains one subfolder for each user of the computer. Inside it, users can store their own documents and other types of files. The current user’s home folder is usually shortened as ~. As anticipated above, the root user does not have a /home/root directory; its home folder would be:
  • /root, the root user’s home directory. The rationale behind its existence is to preserve the root account even when the /home directory has been deleted by accident or otherwise compromised;
  • /media is the default mount point for removable media, such as DVD drives, USB sticks, and external hard drives. It contains a subfolder for each logged in user that contains the actual mount points for removable media;
  • /var (variable) contains information that changes very frequently. For the most part, it’s used to store log files, useful for troubleshooting software problems.

Mount points

A prominent feature of UNIX operating systems is that a partition can be mounted into any empty directory. The directory a partition is mounted into is known as its mount point. All partitions must have one in order for the user to access the files therein, except swap areas, which do not require one (mostly because the user isn’t supposed to interact with their contents directly.

The operating system keeps track of the partitions to be mounted at startup through the /etc/fstab file. It’s a simple text file that contains a few entries like these:

The first column contains the device name, the second its mount point, the third its filesystem type, if the file system needs to be backed up through the dump command, and the order in which the filesystems must be checked at boot time.

It’s still possible to mount other filesystems manually using the mount command, but this goes beyond the scope of this article, so we won’t be dealing with that.

A few scenarios

Letting the installer handle partition may be fine if your computer only has a single hard drive or SSD, but if you have more than one or want to fine-tune the details of partitioning on your installation, configuring partitions manually is the way to go. In the following paragraphs, I’ll present to you a couple ideas to better configure a Linux system. We will use Linux Mint 18, but the same considerations apply to every flavor of Linux.

Single hard drive or SSD

Imagine that the computer has a single hard drive. In this case, leaving partitioning to the installer is the easiest way to get your computer up and running, but there are a few tricks that you can learn to squeeze a bit (but not a lot) more performance out of your computer.

The main thing to keep in mind is that you want to reserve as much space as possible to your /home folder. Linux applications generally do not take up much space, so you can feel free to assign about 15 GB to the /bin, /sbin and /usr folders collectively and leave the rest to your /home folder.

This partitioning scheme is fairly simple. We have a swap partition to help when the system runs out of RAM and a root partition where everything is stored. This is basically a spin on how the installer creates partition, with a notable difference. For whatever reason, the installer puts the swap area at the very end of the disk. If your computer has a single SSD, that’s not terribly important, but mechanical hard drive will benefit from having the swap area being located at the beginning of the disk.

The screenshot above shows a much more complex type of partitioning. We created a 4 GB swap partition at the very beginning of the hard drive to help performance when our machine runs out of RAM (see the following paragraph for more details), a small boot partition, another 4 GB root partition for storing generic applications and whatnot, a big home folder for our data, a 10 GB /usr partition where all programs are stored, and a small /var partition for log files and whatnot.

Short stroking (single hard drive only)

Short stroking is a technique where the disk partitioning is optimized for performance. Data on hard drives is stored in a spiral that starts from the outer edge of the platter and ends towards the center. Since platters spin at a constant angular velocity, data from the outer edge of the hard drive is read and written slightly faster than that placed on the inner edge. The UNIX® and Linux® System Administration Handbook, 4th edition (2010) has this to say about short stroking: “[…] the throughput of a disk’s outer cylinders (those containing the lowest-numbered blocks) can exceed the throughput of its inner cylinders by 30% or more”.

It should be noted that only mechanical hard disks benefit from short stroking, whereas SSDs do not, since there’s no moving parts that have to travel to the physical spot where the data the computer is looking for is located.

To be perfectly clear, short stroking your hard drive won’t make a slow computer become magically fast. It will, however, slightly improve performance.

If we wanted to optimize our hard drive for performance when booting and opening applications, we would use a partitioning scheme like this one:

This configuration features a swap area at the very beginning of the disk, with the /boot partition immediately after to slightly improve the initial boot sequence. The /usr and root directories follow, for a total of about 15 GB, and then we have a decently sized /home partition. At the very end, we have the /var partition.

If your computer has two or more mechanical hard drives, it is indeed possible to short stroke both, for example by setting the mount point for / at the beginning of the first hard drive and that for /usr at the beginning of the second.

One SSD and one hard drive

This configuration has proven particularly popular in desktop computers, especially custom-built ones, because it combines the speed of SSDs with the bigger storage space provided by mechanical hard drives. I’ve said it previously and I’ll say it again: if you’re building a desktop PC or having one built for you, this is by far the way to go.

In this example, the 64 GB device represents our SSD and the 250 GB one, the hard drive.

Since we want to optimize the operating system to execute programs as fast as possible and store our data on the hard drive, it’s recommended that stuff like the swap area, the /boot partition and the / folder reside on the SSD, while the /home and /var directories will be located on the mechanical disk, since neither requires all that speed for general office work.

Conclusion

Obviously, these aren’t the only ways you can partition a Linux system. The possibilities are literally endless. This article only wants to give you a few ideas on how to partition your new Linux system. And of course, letting the installer manage them for you is always a possibility.

About Andrea Luciano Damico 126 Articles
Andrea Luciano Damico is a freelance translator from Italy. Among his interests are linguistics, technology, video games, and generally being a chill guy. He runs Let's Translate.it and Tech4Freelancers.net.