How to: partition hard drive for Linux

February 11, 2008

partition hard drive for Linux Linux has a complicated hierarchy of files and folders that can be confusing right from the start when a user is trying to migrate to Linux. When asked for partition information by the installer, a user may feel uncomfortable continuing.  We’ll try to sort through some of that mess here.

About the Linux filesystem hierarchy

Linux has a filesystem hierarchy that is pretty common amongst various flavors of Linux. Let’s look at a few of the most common ones:

Note: It is easy to confuse “root” as in the user and “root” as in the root directory. The two are separate; the root directory is “/”, the root user is “root”.

  • “/” – pronounced “slash”, it is also referred to as “root” (see next item). “/” is the trunk of the file tree. It serves as a starting point of the filesystem. Every other file or directory is subordinate to “/”.
  • “/root” – not to be confused with “root”, it is usually the home directory for the root user (remember the note above). It typically contains installation logs and a few scripts used by the system administrator. It is a good idea to at least make sure it is on the root partition.
  • “/bin” – where the essential user binaries are stored for both admin and users, such as “ls”, “cat” and “mv”. It should be on the root partition.
  • “/sbin” – the location of essential binaries used for system administration and by the system itself. It should be on the root partition.
  • “/lib” – where libraries needed by binaries in the “/bin” and “/sbin” are stored. This directory also needs to be on the root partition.
  • “/boot” – where the boot loader (from the MBR) looks to load the kernel. This is before any other partition is mounted or any user mode programs are ran. To the bootloader, this partition is root. Then, the bootloader loads the kernel (which resides in the /boot partition) and tells the kernel which partition it should use as root.
  • “/etc” – an acronym for… well actually no one agrees on what it stands for. The majority seems to think it stands for et cetera. It is basically where your configuration files go.
  • “/home” – the place for user account directories. Typically, each user has a directory within “/home” where they have all control over it and whatever may be beneath it. Also, user specific configurations may be stored in it’s sub structure.
  • “/usr” – contains the subdirectories “/usr/bin”, “/usr/sbin,” and “/usr/lib” which perform similar purposes as “/bin”, “/sbin”, and “/lib”, but are not needed at boot time. Non-essential user and system binaries may be stored here. “/usr” contains also documentation for the binaries and libraries.

What is a partition

A partition is a division in the hard drive (HDD). One HDD can be separated into multiple partitions. This division is actually done by putting an entry into the proper partition table on the HDD pointing to the block that begins the partition. There are two types of partitions, logical and extended. There can be up to 4 partitions in the primary partition table. HOWEVER, the extended partition points to an extended partition table and can have even more partitions within it.

Filesystem Type

This is a whole post within itself. Usually the default will be fine. EXT3 is pretty popular. Unless your doing something really specific, EXT3 should be fine. Another filesystem type is swap. There should always be a swap partition. It is a special filesystem used by the operating system as “swap space”, or temporary storage for recovery and RAM overflow. Generally, it should be twice the size of your ram.

Mount Points

First, let’s talk about mount points. A mount point is simply a directory on one partition that is used to mount the root (top level of that partition) of another partition. What this means is that once you mount the numerous partitions, you can navigate to them just as they were part of the root partition. Say you had a partition (we’ll call this one “p1″) with two directories inside named “mounted” and “not_mounted”. Their paths would be of course “/mounted” and “/not_mounted”. Inside each of those directories you create a file called “seeme”. The structure would like like this:

root
|__ /mounted
|   |__/mounted/seeme
|__ /not_mounted
    |__/not_mounted/seeme

Now say you had another partition (this one is “p2″) with 5 files in the root of it. Say the files were simply called “one”, “two”, “three”, “four”, and “five”. The structure for this partition would be like this:

root
|__/one
|__/two
|__/three
|__/four
|__/five

Do you know what would happed if you mounted “p2″ to “p1″ using “/mounted” as a mount point? Let’s see what happens to the file structure then. You get:

root
|__/mounted
|   |__/mounted/one
|   |__/mounted/two
|   |__/mounted/three
|   |__/mounted/four
|   |__/mounted/five
|__/not_mounted
    |__/not_mounted/seeme

Now what happened to “/mounted/seeme”? It’s still there, but will be invisible while that directory is being used as a mount point. Usually, if a directory is being used as a mount point, you should not put files in it.

Benefits of using separate partitions

Put simply, keeping directories that tend to fill up separate from directories needed by the system to function safeguards the system against a crash. If “/home” and “/tmp” were both on the same partition, they would share the same HDD resources. When “/home” fills up, the operating system would not be able to allocate storage to other important system functions that need “/tmp”.

Another plus is that you can format one partition and keep the data on another. You can reinstall your operating system without losing data on the “/home” partition. Also, in the case of a partial HDD failure, your chances of saving data is increased.

Deciding which directories to partition separate

There are so many correct ways of partitioning your HDD. Of course, this is based on the needs and available resources for your system. You may choose to only have one partition (plus another swap partition). Here are some considerations:

  • swap should be twice the size of your ram
  • most of the storage is going to be used by the “/home” directory for a desktop
  • keeping “/home” on a separate partition allows you to reinstall another operating system and keep the data on “/home”

Example

I will explain my setup as an example:
Fedora 7 on 100GB HDD “sda”

partition logical or extended mount point size notes
sda1 logical /home 37GB  
sda2 logical /boot 100MB I use this for multiple Linux installations
sda3 logical swap 2GB 1 GB ram x 2
sda4 extended N/A remaining ~61GB This contains the other partitions
sda5 extended / or /mnt/FC6 15G This is my Fedora Core 6 installation
sda6 extended / or /mnt/F7 15GB This is my Fedora 7 installation

Conclusion

I hope that I’ve given you some insight into how to partition your HDD as a new linux user. Whatever happens, don’t let frustration with learning hinder your decision to stick with Linux. While the learning curve is pretty steep to begin with, the benefits are ten-fold.

Be Sociable, Share!

6 Responses to “How to: partition hard drive for Linux”

  1. Ken:

    If I was to give any advise to a fledgling penguinista it would be to put /home on a separate partition. You can reinstall and be up and going in a fraction of the time when compared to a Windows clean install.

  2. Ken Mitchell:

    Yes, but don’t try that when upgrading or installing a new distro, as things left over in places like .gnome or .evolution can cause weird issues. This happened to me when going from FC6 to Fedora 7.

    Sometimes, I like to store MP3s and other bulky media in /srv, keeping it on its own partition.

  3. tobias:

    I am very new to linux and partitioning. i have a few questions:1) sda5 sda6 have mount points:/ or /mnt/fc6 and / or /mnt/f7 respectively. does this mean you can have / as mount points on both 5 & 6 partitions simultaneously? 2)And BTW is this where your OS actually resides? If this is this the case then what is sda2 (100mb) for with “space for multiple linux installations”. What do you mean by multiple linux installations with just 100mb 4) Does sda1 hold the home folders for all your installations? I plan to install mandriva, and ubuntu. can you help me. Thanks -Tobias

  4. aspiradoras sin bolsa , aspiradoras , robot aspiradora , aspirador robot , escoba electrica , aspirador , electrodomesticos baratos:

    Wonderful paintings! That is the kind of info that are supposed to be shared across the net. Disgrace on Google for no longer positioning this submit higher! Come on over and consult with my web site . Thank you =)

  5. pre market tips:

    Thank you a lot for sharing this with all folks you actually realize what you’re talking about! Bookmarked. Kindly also discuss with my website =). We will have a hyperlink change agreement between us

  6. partitions:

    It’s in reality a great and helpful piece of info. I am happy that you just shared this useful info with us. Please keep us up to date like this. Thank you for sharing.

Leave a Reply:


Recent stories

Featured stories

RSS Windows news

RSS Mac news

RSS iPad news

RSS iPhone & Touch

RSS Mobile technology news

RSS Tablet computer news

RSS Buying guides

RSS PS3/Wii/Xbox 360

RSS Green technology

RSS Photography

Featured Content

Archives

Copyright © 2014 Blorge.com NS