Partitioning New Linux Installs

30 November -0001
Sept. 25, 2002

When installing a new Linux system, partitioning your hard drive is usually the first, and often the most daunting tasks. There are no hard rules for partitioning your system, although there are some guidelines that I'll go over. Be sure to understand partitioning and what is going on before you proceed any further in your installation since partitions are semi-permanent and mistakes or poorly partitioned systems are difficult to clean up. Partitioning is very useful for smooth system performance, but a bad partitioning scheme can actually limit your system. Be sure to scrutinize any 'recommended' partitioning scheme on a new installation. Often these schemes aren't sufficient for intended machine use and can be easily altered during the installation phase. All Linux distributions I know of come with a partitioning too that you can use to set up your new system. Make sure you understand the tool you are using and the process before you get any farther. Laying a solid foundation from the beginning can save you time and hassle down the road and optimize your system for maximum performance.

Swap Partition

The first partition that you usually create in your new Linux installation is the swap partition. Now, the name 'swap' isn't particularly informative, so many people may wonder what this partition is used for. Well, swap partitions are devoted to 'virtual memory.' Basically this space can be used like RAM, but it is contiguous space on the hard disk. The fact that the partition is contiguous means that the machine can access the information quickly (since it is all grouped together on the plates) rather than scanning all over a hard disk to find the appropriate sectors. A swap partition can be anywhere up to 128 Megs in size and you may have up to 6 swap partitions (allowing for a total of 2 gigs of swap space). Swap is useful in boosting the performance of your Linux machine. Although hard disk access is slower than RAM access, it allows your machine to use disk space in addition to RAM. This means that if you are running a program that takes up too much temporary memory, then your Linux machine can allocate hard drive space to handle the overload. Programs use RAM to store temporary information, or information that will be needed immediately by the program. RAM, since it is fast and easy to access, is usually the primary storage area for this information. However, swap space will allow you to simulate more RAM, without actually boosting the machine. The only drawback is that the swap 'virtual memory' is slower than actual RAM. Using the 'free' command will give you a good idea of how much memory is being used by RAM and swap. On my home Linux server, issuing a free command gives this result:

[jkeane@home jkeane]$ free
	total	used	free	shared	buffers	cached
Mem:	70316	66632	3684	4	2568	42408
Swap:	248968	14172	234796	 	 	 

As you can see there is a lot of swap space available, but it is being used as the RAM is almost completely being used up.

Once your system is installed you can actually create more swap space by using a swap file. This is a file that can be used to store swap information. The drawback to this method is that a file is usually scattered around a hard disk (in non-contiguous fashion) and access will be even slower as drive heads spin and search for the sectors of swap space.

Other Partitions

You may create as many other partitions as you like (within reason). The reason you want to partition your hard drive is to divide up space. This is really handy for controlling 'disk full' errors. The worst case scenario is that a program or server might create an error and begin writing lots of error logs to disk. When your disk fills up with these errors your system will crawl to a halt and rebooting will be very difficult. To prevent this situation and many others (like users filling up the whole hard disk with their own personal junk) you can create partitions. Partitions devote certain amounts of disk space to specific purposes. You can limit the space allowed for your log files, and when that fills up your log files won't spill into space reserved for other material. Be careful though, if you limit the space to be used, for say, user applications, and it fills up, you may not be able to install any new programs, even if there is still room on other partitions. In other words, partitions cannot allocate new space or write over to one another. To begin with you may want to only create one partition. To check partition sizes and usage you can use a 'df' command. On my home system this gives the following:

[jkeane@home jkeane]$ df
Filesystem	1k-blocks	Used	Available	Use%	Mounted on
/dev/hda5	7858784		824944	6634628		12%	/
/dev/hdc	662976		662976	0		100%	/mnt/cdrom<

As you can see I've really only got one main partition on my home computer, and it is the root partition '/'. The other partition that is showing up is the CD-ROM (looks like I left a disk in the drive at home) and you can see it is all filled up. It is a good idea to only use one partition on the disk if you're not sure what exactly the machine is going to be used for (for instance there is no sense in reserving 25% of your hard disk for your web server space if you don't ever use it) or if you're just starting out. Keep in mind that once you create a partition for a specific use, you can't really use it for anything else, and undoing a partition is rough stuff. Below is a description of some common partitions and their usage:


This is the root partition, it will hold all the material in you directory tree if you don't specify any other partitions. At its most simple this partition would hold the super user's (root's) files. All other branches of the directory stem from root.
Etc (pronounced 'eht-see') is the home of all your configuration files. Your /etc directory will hold almost all of your configuration files for not only your operating system, but also your servers.
Home is where all users' files will be stored. By default when users connect to a Linux server they will begin their experience in their /home directory. If users want to store a lot of files or programs you will want a large /home partition. You may want to limit the size of the /home directory if you don't enforce quotas on users' space (thereby restricting the total amount of the hard disk they may occupy).
The /tmp (pronounce temp) directory is used to hold temporary files used by programs and servers. Usually the /tmp directory is really small and most programmers are pretty careful about cleaning up the /tmp dir, but if this isn't the case you may want to limit the /tmp dir by partitioning it to be about 100 MB.
The /usr or user directory is where the actual binaries used by users are stored. All the programs available to users are stored here. If you will be using your Linux machine as a desktop (which will have lots of programs), you will want a large /usr partition. Be careful with limiting this space though, because a limited size will mean that you can only install so many programs on your system.
This is the mother partition for servers. The /var partition will hold most of your server information, your print and mail spools, and your log files. Make sure you leave a large /var partition for servers.
This subdirectory of the /var directory, but it is where all your log files are stored. You can actually make this a separate partition. You want to leave a lot of room for your log files if you do this, or make sure you back up your old logs elsewhere, but having a limited /var/log partition will allow you to avoid run away log file sizes that could crash your computer.
This also is a subdirectory of the /var directory. This is where web server files (your html documents and downloads) will be stored. You may want to limit this area if you don't want the web server area to overrun your hard disk.

Final Thoughts

In the end you may need to play around with your partitioning to find out what works best for you. I would recommend starting with the documentation provided with your distribution or with the official website of the distribution. Make sure you do a good job with your partition so that you don't have to repeat a time consuming installation.

Another handy trick if you are dual booting with Windows and Linux is to leave one partition that is formatted FAT32. This format is readable by both Linux and Windows, allowing you a drive that you can see under Linux as /mnt/windows and under Windows as D: (for instance). With this drive if you have problems with your Linux install you can boot over to Windows, use that OS to trouble shoot and download software to the FAT32 partition, then reboot into Linux and access the files from /mnt/windows. You can also use the dual boot to trouble shoot (for instance, if the sound works under Windows, it should work under Linux as well (i.e. it isn't a hardware problem)). Feel free to drop me a line if you have any questions.