42

Having installed various Linux distros for tinkering, I'm puzzled by the installers offering partition layouts - for an easy way out I just use the whole available disk space.

Some of the partitions offered have cryptic names, including /var, swap, /usr, and /home. The installers don't really explain these to me - what purpose do they serve, and which, if any, should be used?

0

9 Answers 9

62

The brief answer about directory names: type "man hier" into a terminal :)

That's the man page for the filesystem hierarchy, which explains the general purpose of the directory names and what they hold. You can see a web version here.

There's also more reading on Wikipedia:

Those links will explain everything about what partitions are called what and what they are (or were historically) used to store.

The answer about using seperate partitions rather than just directories in the same partition comes back to maintainability and expandability. If you've got one partition with, say, / and /home on it, Joe User can fill up his /home/joe folder, and the entire machine will run out of disk space and stop working (I'm simplifying here, but that's the general result). If you've got / and /home on different partitions, Joe User can fill up his /home/joe folder, and the /home partition will be full, but the machine will continue to operate because / is not affected.

So expand that principle out to almost all different directories being on different partitions, and you can see how it would be useful, particularly when a machine is running 24/7 in a multi-user and multi-service role.

3
  • 12
    +1 for man hier Teach a man to fish and all that. Aug 5, 2010 at 1:14
  • Yeah, thanks for the pointer to hier(7). I have always been visiting the FHS web page, without knowing that I have had answers much more easily available.
    – andol
    Aug 5, 2010 at 7:57
  • Problem is that while these are explained how they are intended to be used, some are not in fact used that way by default as in the /srv directory. Apr 13, 2012 at 9:32
7

When installing, many distributions give you the options to put different directories on different partitions. For example, a lot of users choose to have the /home directory on a different partition than the rest of the installation. This is because everything in the /home directory belongs to a user--documents, videos, and all other user-specific data goes here. By putting the /home directory on a separate partition, and the actual OS files on another, if a user decides to do a fresh install of his Linux operating system, he can just rewrite the main partition and leave his /home partition (and all of his files) intact.

This also allows a user to install multiple Linux distributions on different partitions, all sharing the same /home partition. This way, a user can access his files no matter what Linux version he's using.

A casual user shouldn't really have to worry too much about assigning a separate /var, swap, /usr, etc. All of these directories are part of the OS, and have little to do with the user's files.

3
  • +1 for the good link. Isn't /swap always a separate partition? Aug 5, 2010 at 1:13
  • @George Marian: It does not need to. It is possible to configure filesystem swap (which is a file inside the filesystem of an existing partition) instead of partition swap. In this way, the Ubuntu system can work on one single partition.
    – txwikinger
    Aug 5, 2010 at 2:11
  • 3
    For those playing at home, it's worth noting that the ability to use a swap file on a regular filesystem is filesystem-dependent. IE: Don't try this with btrfs, it will (in older kernels) allow you to silently corrupt data and (in newer kernels) throw an error when you try to add the swap.
    – RAOF
    Aug 5, 2010 at 2:29
6

Using the whole available disk space is a perfectly valid (and probably the recommended) option for Personal computers. Partitioning the filesystem like that is in my opinion a layover from ancient times before RAID or virtual volume management were practical in software.

In UNIX-like systems the filesystem starts at the root directory '/'. In the DOS/Windows terms that would be 'C:'

While in DOS/Windows you add drives to dive letters D:, E:, etc. In UNIX-like systems you 'mount' drives into directories. Back in the day when you had 10 or 10 megabyte hard drives you could mount various directories in different drives and partitions to give the illusion of a single large drive. Pretty much a poor-man's RAID 0.

There are many reasons to partition out the various root directories but one popular idea is that since the swap and /var partitions were written to the most they have the highest chance of failing. By separating them out into different partitions it's really easy to just add another drive from backup and re-mount it.

Also having a separate /home parition can be really great if you run multiple versions of linux on one machine. (For example Ubuntu and Red Hat). Since Unix/Linux programs place the user's settings inside his or her home directory. This works much better in theory than in practice though. Because you need to thoroughly understand the permissions implications.

Here are a few important directories for UNIX-like operating systems and their explanations.

  • /bin - Basic system executable files
  • /lib - Basic system libraries (.so in Linux, .dlls in Windows).
  • /boot - Where you're kernel lives. Computer wont start without this one.
  • /var - Directory were services can store files. Like log files and mailboxes
  • /etc - System configuration files
  • /usr - Non-essential user applications. (A unix-system can boot without a /usr (for recovery purposes) but it would not be very fun. In older systems this is the same as /home.)
  • /home - User's home directories. Normal users can only write to their own home directory.
  • swap (not a directory) This is usually a separate partition in UNIX. There is no swap directory, although you can make swap-files in Linux.
8
  • 2
    I would say that even for a desktop/personal computer, having /home in a separate partition is a good idea. That way, you have fewer headaches should you fill up your home directory. Aug 5, 2010 at 1:17
  • @George There's nothing stopping you from symlinking to your home directory on another drive. In my setup, to allow compatibility with windows, my home partition is NTFS and I symlink whatever folders I use into my home folder. I would symlink the whole folder but I like to keep the hidden stuff in ~/ separate in case I decide to do a fresh install. Using hardcoded filepaths linked to separate partitions may have been necessary twenty years ago but the architectural constraints that made them necessary don't exist today. Sep 16, 2010 at 13:25
  • 1
    @evan I'm confused. Are you referring to symlinking directories into your home directory or symlinking your home directory somewhere else? How is this different then setting /home to a different partition? (Note, "different partition" may be on an entirely different drive.) I was referring to guarding against default behavior (e.g. downloads being placed in a sub directory of your home folder) inadvertently filling the root partition. Sep 17, 2010 at 6:17
  • @George Both and whichever you prefer. The point I'm trying to make is, why set hardcoded links during the system install when you can just simply throw in a few symlinks after that do the same thing and can be changed easily at any time? Sep 17, 2010 at 8:50
  • @evan A fair point. I've never had much luck messing with this kind of stuff after the install, so I've always preferred to do it the "default" way. Sep 17, 2010 at 17:31
2

You can find a very detailed description on the pages of The Linux Documentation Project: Linux Filesystem Hierarchy

1
  • +1 for the link. But You should include the necessary information here and provide the link for reference
    – Anwar
    Sep 22, 2012 at 6:41
1

The swap partition is also used for hibernation. If you want to put your laptop or desktop in hibernation, you need a swap partition or swap file that is big enough to hold the running operating system and your open applications.

It is often suggested that the swap partition be the same size as your RAM memory.

1

You can make separate partitions during install. a /home partition will mean everytime you install Ubuntu your personal user settings will remain.

/ - is the root.
/var - (explained above)
/dev - contains "links" to registered devices. i.e. /dev/Video0 is a capture card...

/bin /sbin - contain applications

better yet Wikipedia has a great page http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

The biggest thing I find is having a 2nd partition (the largest) for your stuff and like I said everytime you reinstall or upgrade. Select that partition again and make sure you uncheck the format box and then everything is back. Even your wallpaper!

1

Well, swap is used a swap space. It's like a page file in Windows. It kinda supplements RAM.

/home is used for user data like My Documents in Windows,

/usr is where most of the programs are much like C:\Windows, and

/var contains data that is changed when the system is running normally.

As for why the are in separate partitions I think it's mainly if your OS goes down your data does not go down with it. But I'm really not sure.

1
  • Diff between /var vs /etc?
    – Pacerier
    Nov 1, 2017 at 22:49
1

Historically, it's considered best-practice to have /home, swap, and other critical nodes reside in different partitions, different physical disks, or even different physical machines. Although for convenience (for better or worse), and with the advent of cheap external or cloud-based backups, everything now live in one single large partition and you just do backup of your personal things to elsewhere.

/usr, stands for Unix System Resources

/sbin, System Binaries

Contrary to popular beliefs, /etc does not stand for et cetera. Instead, it stands for Extended Tool Chest. But, contrary-contrary to popular beliefs, it's still a matter of debate.

Here's some more info on those folders and how they're organized.

0

Swap should be kept separately if you use it. And use 1.5-2.0 x your ram size for it.

The rest can be kept together, and doesn't really matter (Linux/Unix is not windows and have single directory hierarchy, whether your /var directory is separate partition or not, it looks exactly the same). The main purpose of partitioning is to use different filesystems and to split possible "disk full" scenarios (so, for example, if /var fills with logs of some crazy app, /home stil works)

As a sidenote, I strongly recommend using LVM which allows one to create as many freely resizeable and removable partitions as one likes, and even adding new hard disks to the family. Still, it requires learning some command-line so is not for the total beginner.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .