Creating Partitions in Linux

Page content

Partitions Defined

A partition is a logical drive created on a physical hard drive. Partitions information is written to the first sector on the Master Boot Record (MBR) called the Partition Table. The partition table holds information such as the starting and ending position of the partition and its type.

On a Windows system, many users create a partition to hold the operating system (the C: Drive) and a partition to hold data (the D: Drive). This enables them to restore their Operating System without damaging their data.

Partitions are also used when dual booting two or more operating systems. Each operating system requires at least one partition and the partition must be of a type the OS will understand. For example, Windows requires a Fat32 or NTFS partition and Linux requires an ext2 or ext3 partition.

Technically, Linux only requires one primary (root) partition and a swap partition. In a stand alone set up, this is fine. However, in a multi user setup, it is customary to have additional partitions for /home, /var, /etc, /usr, /tmp and /boot. Using these partitions restrict file growth and help keep run away processes from clogging up the system. It also keeps user data away from the system data.

Creating the Partitions

Note: All the commands used here must be performed as the root user, or by adding “sudo” to the beginning of the command.

If you are unsure of the device name of your hard drive type “fdisk -l”. This will give you the device names of all the hard drives currently available to your system. If you are partitioning a secondary drive, your unpartitioned hard drive will have a device name like “/dev/hdb” or “/dev/sdb/".

To start the partitioning procedure type the following command:

fdisk /dev/sdb

The fdisk utility has the following commands:

p print the partition table

n create a new partition

d delete a partition

q quit without saving changes

w write the new partition table and exit

First, type “p” to see the size of your hard drive. You will get output such as:

Disk /dev/sdb: 64 heads, 63 sectors, 621 cylinders

Units = cylinders of 4032 * 512 bytes

You determine your hard drive size by the following math: heads*sectors*cylinders*bytes=total size of hard drive.

Decide how you want to spit up the partitions. If you want four partitions that are exactly the same size, each partition would be 320,495,616 bytes or 305M (320,495,616/1048576).

Next, type “n” to create the first partition. Enter the following information:

Partition number (1-4): 1

First cylinder (1-621, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-621, default 621): +305M

Repeat this process for each partition.

When you are finished creating the new partitions, check the partition table by typing “p”. If you are satisfied, type “w” to write the partition table.

Formatting and Labeling the Partitions

The partition table has been created, but there is no data on the partitions and they are not formatted. This must be done with another utility. If you are creating a Windows partition, it is best to use the Windows utilities to format the drives. If you are creating Linux partitions, the “mke2fs” command will do the formatting and create the labels.

To create an ext3 filesystem, with the label home, on the first partition of /dev/hdb type the following command:

mke2fs -j -L home /dev/hdb1

Now the first partition on the secondary drive will be mounted as /home.


Although there are graphical tools that will partition a hard drive, the fdisk utility will give you more control over your partitions. It will also work when the graphical tools fail. As such, it is a good utility to understand, even if you ultimately choose to use the graphical options available.