Partitioning Hard Disks in Linux

Written by:  • Edited by: Michael Dougherty
Updated Jun 10, 2009
• Related Guides: Windows | Linux

In this article we check out how you can partition your hard-disks in Linux. This can be useful information even if you're not going to use Linux on an everyday basis. LiveCDs with GParted can be used for diagnostic/repair and partitioning in Linux is very easy once you know the simple commands.

Introduction

Partitioning your disks is generally done so that you can segregate and categorize your data. With the sizes of hard-disks going up everyday, it becomes very difficult to manage a single 500GB partition with all your data mixed in. Windows has a built-in partition manager (refer to guide here) and many other third party applications available to help you with your Windows partitioning. Partitioning disks in Linux can be done through various utilities, some of them command-line based and others, graphical. In this article, I'll be going over a few popular partition managers in Linux. The list includes fdisk and GNU Parted, which are command-line applications, and GParted which is a graphical application based on GNU Parted.

fdisk

fdisk
click to enlarge
fdisk is a very popular command-line based Partition Manager. The command is invoked with the device which is going to be used for partitioning. For example, if you want to partition the disk at /dev/sda, then the relevant command would be "sudo fdisk /dev/sda". This will open the /dev/sda disk for partitioning. Make sure to include just the disk device and not a specific partition like /dev/sda1.

Once you've invoked fdisk, it will open a small interactive command-line menu which will allow you to do various things regarding partitioning. Viewing the list of keys can be done by typing "p", then pressing the Enter/Return key. This will print a list of all keys used in fdisk. Check out the list of keys which will be used during any partitioning job:

n - Create new partition. Remember that you can only have 4 Primary partitions. The correct thing to do if you need more than 4 partitions is to create 3 Primary partitions and 1 Extended partition. The Extended partition can then hold multiple Logical partitions. Once you type "n" and press Enter/Return, it will ask you for a partition number. Assuming that the disk is completely empty, type 1. If you have created any partitions before, increment the number to type and then press enter. It will then ask for the first cylinder that it should use for the partition. You can safely type Enter and let it take the default value unless you want to create another partition in between. The next query will be about the last cylinder that it should use. You can also specify the size of the partition by typing +sizeK or +sizeM, for example, +500M. This will create a 500MB partition.

t - Set the type of partition. This can be used to change the partition type, for example Swap, Linux, Extended, Windows and so on.

a - Set the bootable flag on a partition.

d - Delete a partition. It will ask you for a partition number.

p - Print current partition table.

w - Write the modified partition table to disk.

q - Quit fdisk.

Showing page 1 of 2

Comment

Showing all 1 comments
 
Greg Zeng Nov 12, 2009 9:30 AM
PCLINUX OS makes this entry obselete
Decades ago, the above information was relevant. Now I'm using PCLOS (latest version), partitions are easy. Not mentioned, to have your SWAP partirion at the very beginning of your HDD - it's fastest there. Similarly on your other different HDDs. However if you use any of the electronic drives, it does not matter where on the drive the swap partition is.
 
blog comments powered by Disqus
Email to a friend