When you install Linux for the first time, you will need to partition your hard drive during the install process. If you’re using one of the more friendly distros such as Ubuntu it will by default partition your hard drive in a logical manner (this is called guided partitioning). However the partitioning it does is very basic, if you want to get more power from your Linux install, you will need to manually partition your hard drive during the installation. Most people shy away from this thinking that it is too difficult to know what part of the file system should get it’s own partition and what the partition size should be. Things, however, are not as difficult as you might believe and I will attempt to give a quick guide to how you can manually partition your hard drive to get more out of your Linux installation (I use Ubuntu so everything will be biased towards that distro).
Ubuntu Guided Partitioning
To make Ubuntu easier to install for those not familiar with Linux, it provides guided partitioning. Basically, the installation process will partition your hard drive without you having to get involved. This is fine if you’re new to Linux or are just not comfortable partitioning your hard drive manually. However, guided partitioning is very basic, it simply divides your drive into two partitions. The smaller one will be the swap partition (this one will usually be no more than a few gigabytes). The larger part of the hard drive will contain everything else (i.e. will house the root of the file system – /). While this type of partitioning is easy and will serve your basic needs, if you decide to manually allocate partition sizes for your hard drive you can get the following advantages:
- isolate parts of the file system, so that they can be preserved if you reinstall the operating system (e.g. you can reuse your home folder so that all your documents and customizations are preserved)
- separate data that changes frequently from data that changes infrequently, which can reduce disk fragmentation and prolong the life of the system
- separating data that you want backed up into a separate partition can make your back up procedures much simpler
- make your system more resilient to attack, if your system becomes the target of an attack or one of your programs behaves badly, it can create large log files or other files which can fill up the whole disk, however if you have multiple partitions, it can only ever fill up one partition which means your system is less likely to crash
Manually Partitioning Your Drive
Obviously if you decide to go with manually partitioning your drive you will need to consider the kinds of activities that are likely to occur on your system, this will determine what partitions you’ll need. This is completely up to you, however, generally the following parts of the Linux file system are good candidates to get their own partition (pick and choose the ones you think you will require).
/ (known as root) – this is the root of the file system (clearly :)) and will always get it’s own partition. Anything that doesn’t get a partition of it’s own will become part of the root partition.
/boot – the kernel and various other data needed for the system to boot live here. This partition can usually be pretty small. The data on this partition changes very infrequently and therefore you may not even need the ext3 file system on it (it can use ext2 instead) and having it as a separate partition can facilitate this.
swap – the swap partition is used to temporarily store data when the system does not have enough RAM for it’s current tasks. As a guide the swap partition should be double the size of system RAM and doesn’t need to be bigger than about 2 gigabytes. These days, systems often have more than 2Gb of RAM, but you do still need a swap partition (a system could, technically speaking, function without a swap partition, but I wouldn’t recommend it). Considering that disk space is so cheap these days, it is usually not an issue to have a 2Gb (or more) swap partition. The swap partition is never mounted and so does not get a mount point of it’s own (i.e. you won’t be able to browse the files on your swap partition).
/home – this is where the home directories of all users of your system will live. Having this as a separate partition allows you to reinstall the operating system without losing all your personal data. The other advantage is, if you have a multi-user system, a single user won’t be able to fill up the whole drive with their data and crash the system (at most only this partition will get filled up).
/usr – most of the packages you install on the system will end up here. Having this as a separate partition will allow you to backup or export this partition to another system easily (if you need to).
/usr/local – many additional packages (those other than Ubuntu core packages, if you’re using Ubuntu), will end up here. Some of the software packages you compile from source will also often end up here. You can have this one as a separate partition for similar reasons to /usr.
/opt – other packages you install and compile from source get installed here, so once again, for similar reasons to /usr and /usr/local – you might want a separate partition for it.
/var – the data here usually changes frequently (hence the name). Much of the system log data, package and accounting information resides here. It is a good idea to have it as a separate partition, if someone runs a job that consumes a lot of disk, this area won’t be affected and you will still have the information you need (such as logs) to diagnose the problem. The only caveat if you’re using Ubuntu is the fact that, the Apache web server will store all it’s web content under /var. So if you’re planning to use the system as a web server, it might be prudent to configure a different location for Apache to use.
/var/log – system logs usually live here, and so it may be a good idea to isolate the system logs from other parts of the system, considering how important logs can be do diagnose problems when something goes wrong.
/tmp – this one is pretty self explanatory. It can be used as a temporary space to store files or for programs to write temporary data. Strictly speaking you don’t really need a separate partition for this, but it certainly won’t hurt.
Possible Sizes For Your Partitions
- /boot – usually don’t need more than 200Mb but disk space is cheap so give it 500Mb (0.5Gb).
- (swap) – depends on amount of RAM, but for modern system with lots of RAM, make it the same size as the amount of RAM you have (e.g. 2Gb RAM – 2Gb swap)
- /home – this one depends on how you plan to use the system, how many users you plan to have and the kind of work they plan to do. It is hard to give a guide for this one, however for a single heavy user (lots of data in home directory), you can plan anywhere between 20Gb – 100Gb or more.
- /usr – depends on how many packages you plan to install on your system. For standard number of packages plan around 4Gb, for lots of packages anywhere up to 20Gb or more. For a regular home system, 20Gb should be plenty.
- /usr/local – once again depends on how many packages you plan to install, but as disk space is cheap, for a regular home system you can make this one the same size as /usr.
- /opt – similar situation as /usr and /usr/local here, make it the same size as the other two.
- /var – if you don’t plan to run many severs this doesn’t need to be too big, so around 2Gb should be enough. If you do plan to run a few servers, this may need to be much bigger (depending on what servers you plan to run). Use your judgment here and remember that disk space is not expensive. To give yourself some future flexibility make this one around 20Gb.
- /tmp – once again depends on how you plan to use your system (yeah I know, it always depends :)). This one is normally less important, give it around 10Gb.
- / (root) – it is always a good idea to create the root partition last. Since this partition will contain all the data which you decide not to put in a partition of it’s own, the size required can change drastically. If everything else has it’s own partition then this doesn’t need to be much bigger than 2Gb or so. However, if you decide not to have a separate partition for something else, you will need to increase the size of this partition accordingly.
Depending on the size of your drive, you may have a lot of space left over after this. It is up to you how you dispose of that space. You may want to increase the size of each of your partitions proportionally to use up your whole drive. You may also want to use the rest of the space for another OS (dual boot).
That’s all there is to it. As you can see, manually partitioning you drive during a Linux install does not have to be a major drama. Having said that, I am not a great Linux guru, this is just the way I understand it. If you ARE a Linux guru, or simply have some extra tips in addition to the above, please feel free to share so that everyone can learn.
Image by Andres Rueda