Partitioning Your Hard Drive During A Linux Install

Hard DriveWhen 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

  • bobsmith

    “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).”

    Why wouldn’t you recommend it? I have 3 GB of RAM and have functioned without a swap partition for quite some time with no problems whatsoever. Or one could use a swap file, which is just as fast as a swap partition. See this:

    • Look, you’re probably right, I guess it is a bit of a hold-over from the olden days when RAM was scarce and a swap partition was really important. For general usage, if you have a lot of RAM you probably won’t even notice if you don’t have a swap partition. However, if you run a lot of memory hungry apps at the same time, having a swap partition might prevent issues (although I haven’t tried this out, but it seems logical).

      As far as file vs partition goes, it probably makes little difference if you use one or the other, and the link you provide seems to confirm that.

  • Korny

    The other reason you might need a swap partition – some dumb software installers, specifically Oracle XE, check for a “big enough” swap partition and fail if they can’t find it.

    On the general topic – I used to split my drives into partitions, and ended up deciding that it was more trouble than it was worth. If you split your file system, then you always waste disk space leaving enough room for /usr and other app-like areas to grow – or you don’t leave enough space and suffer.

    The only exception is where you have separate physical drives for some reason – like my home server, which has one big drive for /, and a pair of disks as a Raid array for /home, for a fraction more data safety.

    • Ah see I didn’t even think of that, that is certainly a good reason to have a swap partition.

      I do like the idea of having a separate partition for your home, as to everything else, it is probably unnecessary for a home install, but if you plan to run servers and support multiple users etc., do lots of installs (i.e. be an admin), it becomes more useful.

      LVM is another way to go if you’re worried about wasting space, don’t know much about it as yet (gotta make some time and look into it :)).

  • mehboob sadicote

    I searched ‘high and low’ for something as simply and lucidly described, but until now, always found something complicated, and that which invariably veered off into a heated debate of some sort; so thanks. Having said that, there are couple of bits of information that would complete the tutorial for me.
    1) the optimal positioning of the various partitions or their sequence, when creating them during installation–making allowances for a new install every 6 months, and fragmentation (for e.g. i read somewhere that swap should be sda1, /boot should be sda2, etc.), and
    2) the procedure for creating and naming a separate data partition during installation, and it’s mount point. Could you please take the trouble?

    • I am glad you found it useful, regarding your questions:

      1. In the olden days the /boot partition had to be at the start of the physical hard disk, these days it is not mandatory any more. To be on the safe side you can make your /boot partition the first partition on the disk, but aside from that the positions and order of all the other partitions don’t really matter too much. With modern file systems fragmentation is a lot less of an issue, so I wouldn’t worry too much about it.

      2. As far as data is concerned I am presuming you want a separate partition here so that you can easily back up and not have to blow away your data if you re-install. If that is correct then for a single user system, what you’re really interested in is your /home directory. Even in a multiuser system, all user directories will live under /home. Normally most of your important data should end up under your user directory under home e.g. /home/*your_username*. So, as long as you have created a separate /home partition you’re going to be ok as far as your data is concerned.

  • mehboob sadicote

    Thanks Alan, but i was thinking of making a provision for installing, or upgrading to a new release every 6 months or so, in that case wouldn’t a separate /home partition be a bit of an impediment? That’s why i thought of a huge data partition occupying the rest of my disk following your tutorial:
    sda1>>swap>>2G, sda2>>/boot>>256MB>>Ext2, sda3>>Linux>>/>>15GB>>Ext4, and data>>?>>rest>>Ext3. Only problem is, i don’t how to do that during the installation, anything about it’s mount point, or how to create it later.

    • If you upgrade rather than it’s not an issue. If you reinstall then you can do things like, putting your /home partition on a separate disk all together and then simply reusing the partition during the new installation. This way your home partition acts as your data partition and you don’t need to have another separate partition for it.

      If you still want a data partition then the easiest thing to do would probably be to create it after you complete your installation. If you install gparted it will let you create and resize partitions and assign whatever mount points you want. From memory it is pretty easy to use, so have a look.

      • mehboob

        Thanks a lot, that clears up a lot of things for me.

  • alok

    i have created all directories( /, /boot etc.) .how to create swap part? does remaining space ia automatically assigned as swap?

    • No, remaining space automatically becomes part of /.
      When you’re manually creating your partitions during the install, swap doesn’t get assigned it’s own mount point.
      So just create a new partition during install with whatever size and then pick:
      (Use as: Swap area)
      That should be all you need to do.

  • One good reason to keep a swap partition is for when things goes wrong. For example if some code has a memory leak or you simply are running too many processes, the machine will slow rather than crash once your physical memory is used up. Giving you the opportunity to gracefully recover.

  • Pablo

    So many partitions. It looks a bit like overkill, doesn’t it (I’m not saying it’s a bad idea)?

    I usually just have the swap and home partitions. I will give your schema a try in a VM to see how it feels after an upgrade.

    • You’re right, something like this is less useful for a personal setup. At home, as long as you have /home on a separate partition, it’s probably good enough.

  • It is good for linux Basic file System.

  • Pingback: Interesting Question | My Blog()

  • John Austin

    OK, I understand the partitioning idea, where I’m stymied is how do you tell the computer where to find (/). Three different distros hang on installation because I haven’t designated (/) previously. I’m attempting to build a multi-boot system with pre- selected partitions. I used gpartid to setup as follows:
    /dev/sda1 SWAP 3GB
    /dev/sda2 25GB for data sharing
    /dev/sda3 -Extended Partition
    /dev/sda5, 6, 7, 8, 9 ….. Logical partitions inside Extended partition, 12 GB each for different OS.
    I have been a lurker around linux for 20 years, but have never mastered it’s fundamentals.

  • John Austin

    The statement above is my current status. I can automate an installation, by letting the program hog the whole disk, so I have one distro per computer, but would prefer to have multiple systems on the same box. It is not obvious how to tell Gparted which is -/. etc

  • Arun

    Thanks Alan. It was explanatory and able to understand much easier. Thanks again for this good stuff.

  • sohaib

    so helping info thnx

  • Pingback: Which partition is my OS installed on? - Admins Goodies()

  • khanz

    I don’t think having a separate /usr partition is healthy rather it will create compatibility issue after say an upgrade. Only /usr/local should be recommended & default application should be reinstalled afreash with every distro update, one can make a list of PPAs & installed application & save it to txt file

  • rasool

    hi, at first tnx for your explaination, how can i instal linux ubuntu after instaling win7, should i delete one of partitions to use it as a free space for linux(ubuntu)

  • fuckyou

    why are all of you so fucking dumb. quit making shit so long it takes 4 hours to read an still not fucking get the correct answer you pices of fucking shit!!!……… 40 different pages to read the same bull shit! why !? because nonm of you know how to make shit simple and easy…… i dont give a fuck i want the sizes and basic partitions needed

    • You should back away from your computer, shut it down, get yourself literate, and stop hating. None of this is hard, nor all that dramatic. Peace.

      • thank you for your wonderful description of each element of linux fs- it is the best one I have found so far. I do sympathize with Jon Whittum though. I have been reading every article I can find about partitions and multi-booting, and not only is there a wealth of info, much of it assumes that the user is much more familiar with the command line and the intricacies of all the changing standards (MBR & GPT). I do not think anything about the topic is simple. Finally because everyone has different needs and desires, the possible set ups are almost as various as the number of people using them. One thing is sure about computers; they demand that you stay very firmly rooted in the rational and calm partition of our very arbitrary human mind. But we have all been to the place of total frustration with the seemingly needless complexity of our tech. thank you for your efforts to elucidate a highly difficult topic.

  • Rory Geoghegan

    thanks alan for the great article. i was hoping you could help with my situation. i have a small (120 gig) ssd and a 1tb hdd. i am attempting to teach myself ubuntu atm and i’m wondering how to take advantage of the two drives. obviously i want to run the OS off the SSD and i’m thinking it would make sense to run the /home folder off the HDD?
    the other concern i have is where should i be installing applications to? the SSD of the Hard drive? and what folders? in windows you have program files, is there a ubuntu verson? and how will the OS know where to locate those files when i wish to run those apps?
    thanks in advance. i know these are very noob sort of questions but you have to start somewhere.

  • Mahdi Bouafif

    where i can save my films and my documents when i move to linux