Praji’s Weblog

Welcome to praji’s world

Fdisk for partitioning

leave a comment »

Partitioning the hard drive is essential part of Linux usage. Fdisk is a tool you can use for this purpose. Here we bring you a howto on fdisk for Linux, which mind you, is separate from the fdisk for Windows that most of us are familiar with. This is a matter of confusion for most rookies. For apart from sharing a name, there’s a world of difference between the two.

Fdisk is started by “fdisk device”. The device will be the hard drive that you want to partition. You have to be the root.

# fdisk /dev/hda

You will now find yourself at the fdisk command-prompt. A “m” will bring up the available commands.

Command (m for help):

The first command that you give is “p”, to list the partitions on your drive.

Partition creation

Partition creation is fairly easy. To create a new partition, press “n”. Now you will be asked whether you want to create a primary or an extended partition. Generally, you’ll have three primary partitions and an extended partition that occupies the rest of the space available. Finally, you will create logical partitions within this extended partition.

Command (m for help): n
First cylinder (3925-4963, default 3925):

The above prompt is what you will see after you select the partition you want to create. Either enter a starting cylinder value here, or just press enter to use the first available cylinder (here 3925). Most of you will take the second option.

Last cylinder or +size or +sizeM or +sizeK (3925-4963, default 4963):

In case you’re feeling really brave and want to enter the last cylinder for the partition, we suggest, you specify a size for the partition. Just pressing enter here will mean that all the free space available will be used for the partition. Enter the size in bytes–KBytes, Megabytes or Gigabytes. Prefix a “+””to the size you want to allocate to the partition followed by a K, M or G to specify KByte, MByte or Gbyte.


By default, fdisk creates a partition of type Linux with ID 83. This is incorrect, if you’re trying to create a partition of type swap. You can change the partition type using the command “t”.

Command (m for help): t
Partition number (1-8): 8

You will be prompted for the partition number of the type you want to change and will be followed by:

Hex code (type L to list codes):

Each partition type has a number assigned to it. For the most part, the hex codes of the partition ID’s are unique. In some cases, there are conflicts – Solaris partitions and Linux swap share the same ID. If unsure of the Partition ID, use “L” to check. As you can see, fdisk supports a wide variety of partitions from FAT to BSD to BEOS. We select 82 for Linux swap.

Hex code (type L to list codes): 82
Changed system type of partition 8 to 82 (Linux swap)

That was about creating partitions. But, what if you want to delete. Just press “d”.

Command (m for help): d
Partition number (1-8): 8

Key in the partition number and press enter. You will not get a confirmation message but you’ll find yourself back at the prompt.

Oops! That wasn’t the partition that was to be deleted. /dev/hda7 was to go and not /dev/hda8. What do you do? Don’t panic. Just press “q” and exit without saving your changes. You will be dropped back at the prompt. Get back into fdisk and you will see that your partitions are intact.

No changes you make to your disk partition will be committed until you explicitly use “w” to write changes to the partition table before exiting. Just check the partition list before doing so.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Re-read table failed with error 16: Device or resource busy.
Reboot your system to ensure the partition table is updated.

Warning: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information.
Syncing disks.

Now that you have the partitions you want, go ahead and create a filesystem on them.

There is one more option that’s useful in “a”, which sets a partition as bootable. The bootable tag is useful because at boot, if no boot manager is running, control is transferred to the partition with the bootable flag set.

After writing the entries to the partition table we can use the partprobe command to inform the operating system kernel about the  partition table change.


Written by praji

January 8, 2008 at 9:35 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: