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?

Eric Carvalho
  • 55,453

9 Answers9

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.

Jorge Castro
  • 73,717
Ben Williams
  • 1,330
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.

jhappoldt
  • 103
Makario
  • 191
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.
Anwar
  • 77,855
wm_eddie
  • 571
2

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

ddeimeke
  • 3,149
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.

Eric Carvalho
  • 55,453
Cody Harlow
  • 1,482
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!

Anwar
  • 77,855
M J
  • 71
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.

Eric Carvalho
  • 55,453
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.

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.

Mekk
  • 536