Monday, June 4, 2012

Linux Partitioning Guide

Introduction
This seems to be a popular topic among people new to Linux, and why wouldn't it be?  Partitioning your hard drive is one of the first things you have to do when you install Linux.
I'm making this guide, because over the past couple months, I've seen a couple of sub par guides on the subject.  Hopefully those that need this information most will find my guide useful.  If anyone has any suggestions for what I could add or change, please let me know in the comments.


Brief Overview of Some Commonly Used File System Types
(note: When talking about file systems, journaling refers to a file systems ability to document information about the files.  Journaling can prevent data from becoming corrupted when the system is turned off in the middle of a file transfer.  As an added bonus, systems that support journaling can perform file system checks must faster.)


FAT32 - This is a non-journaling file system, mainly used for compatibility with Microsoft systems.  This file system is often recommended for thumb drives as it wont read and write as much data as NTFS.

NTFS - This file system supports journaling as well as other features such as file permissions.  It is probably what you use for your Windows partition.

EXT2 - This is a non-journaling Linux file system.  Just like FAT32, it's often recommended for thumb drives due to the fact that it wont read and write as much data as other file systems.  The maximum file size and partition size however are much larger than that of FAT32.  Files can be as large as 2 TB as opposed to FAT32's limit of 4GB, and partitions can be up to 32TB as opposed to FAT32's limit of 8TB.

EXT3 - Journaling Linux file system that allows in place upgrades from ext2, uses less CPU than XFS, and it also considered stable and well tested.

EXT4 - Journaling Linux file system with improved performance over EXT3, and more features.

XFS - Offers stability and advanced journaling features.  This file system cannot be shrunk and it yields poor performance when performing certain tasks such as deleting a large amount of files.  It was created by Silicon Graphics, and is often implemented on large servers.

Swap Area
Linux will occasionally write pages of data from RAM to the swap area to free up memory.  It's generally said that you should use one and a half times the amount of ram in your system for the size of your swap area.  If you aren't doing much with your system, you have a decent amount of ram(4GB+), and you don't plan on hibernating your computer, you barely even need a swap area.  Some people just opt not to use swap these days.  The amount you use is generally just preference.

Devices
In Linux, hard drives will generally be referred to as /dev/sdX where X is the letter of the drive.  The first drive is a(/dev/sda), the second drive is b(/dev/sdb), and so on and so forth.  IDE drives were at one point referred to as /dev/hdX, but the latest kernel will just use /dev/sdX for that as well.

Boot Loader
The boot loader (which starts up the operating system when you turn on your computer ex. grub) should be installed on the MBR of the primary hard drive (not to be confused with a primary partition).
You should make sure the partition you install the grub files to is marked as bootable.  If you don't make a separate boot partition this will be the root partition.  Many distros will do this for you, but if you're using something where you need to do the partitioning manually and separate from the install, such as slackware or gentoo, keep that in mind.

Partition Types
Primary - There's room for 4 primary partitions on a hard drive, unless you want an extended partition in which case you're allowed 3 primary.  Windows will only boot from primary partitions, but you can use logical drives for Linux if you wish.

Extended - An extended partition is broken up into logical partitions.  To bypass the limit of 4 partitions per hard drive you can make an extended partition and break it up into as many logical partitions as you desire.

Partitioning Example Using Xubuntu Linux
I've put together a set of screenshots to demonstrate how to manually partition your drive during the Xubuntu Linux install.

First we're going to select "Something else" on the installation menu.  You should get a screen like this with any Ubuntu variant, and most likely something similar with other Linux distros.




For the sake of this demonstration I've created an NTFS partition that takes up the entire hard drive.  Lets let this NTFS partition represent a Windows install we want to keep on the computer.  First click on /dev/sda1 (or whatever partition your windows install is located on) and then select change on the menu.




Since this is a dummy install and I don't really need it, I'm going to make it one gig.  Change the box to whatever size you want your windows partition to be, keeping in mind that you might want some extra space left over.  You should also back up any important data on the partition in case anything goes wrong with the resize.  Click on OK to continue partitioning the drive.




















At this point the installation will warn you that you're about to resize the partition and anything you've done up to this point will be finalized.  Click on continue to proceed.

















You will now notice you can select free space under the first partition.  Click on add to create a partition in the space we cleared up.






The first partition we're going to make is the swap area.  Type in the size of the partition in megabytes and then select swap area from the "Use as:" menu and click OK.






















Now that we've created some swap space we're going to add the partition where the operating system will be located.















This time select enough space for the main operating system.  You could either fill up the entire hard drive, or leave room for more partitions.  In this example I made it 5 gigs which fits the minimum requirement for Xubuntu.  You will most likely want more than that.  In the box "Mount point:" put a forward slash.  This indicates that it will be for the root file system.  The root file system contains everything not otherwise specified.  At this point you could also change the file system type of this partition, but the default choice of EXT4 is probably what you want anyway.


Now that we've set up the root partition, and we still have some space left, lets make a home partition to store various user settings and files.  Having a dedicated home partitions makes reinstalling, upgrading, or installing new distributions a breeze.



For this last partition I'm going to keep the default file system Ext4 once again.  Since I'm using the rest of the drive I'm not going to enter a new size, but I will type in /home under mount point.  At this point I click OK and I'm almost done.

Before hitting install make sure that the boot loader is pointed to go on the correct drive (whichever one the computer boots from) by selecting it on the menu on the bottom of the window.  Double check everything and you're good to press install and continue the installation.






Conclusion
If you need to partition things and resize partitions manually, without using an installer, the easiest way to do so is with a program called Gparted.  You can open Gparted from the command line on the Xubuntu live cd by typing "sudo gparted".   Depending on what distro you use, you use you may need to install it first.  It's pretty self explanatory.

If you've made it this far you should have a pretty clear understanding of how to partition a drive.  If you would like to learn how to partition from the command line, I suggest looking into parted.  Unfortunately you can't resize ntfs with parted alone, but there are other programs out there to do so such as ntfsresize.


No comments:

Post a Comment