Pin Me

Partitioning Hard Disks in Linux

written by: Pranav Thadeshwar•edited by: Michael Dougherty•updated: 6/10/2009

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.

  • slide 1 of 6


    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.

  • slide 2 of 6


    fdisk 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.

  • slide 3 of 6
    Partitioning HDD in Linux - Using GPartedOn this page, we check out GParted, a GUI frontend for GNU Parted. GParted is a very powerful partition manager which is available as a separate package and also as a special LiveCD which can be useful for diagnostic/repair purposes.
  • slide 4 of 6

    GNU Parted

    GNU Parted, in GNU's own words, is an industrial-strength package for creating, destroying, resizing, checking and copying partitions, and the file systems on them. This is useful for creating space for new operating systems, reorganizing disk usage, copying data on hard disks and disk imaging. It contains a library, libparted, and a command-line frontend, parted, which also serves as a sample implementation and script backend.

    As with fdisk, you invoke parted by using a device, like "sudo parted /dev/sda". This will open an interactive application which will guide you through the partitioning. Unlike fdisk though, parted is a lot more powerful and supports a lot more commands and functions. Here are some of the main commands to work with parted:

    mkpart partition_type [filesystem_type] start final_size - Creates a new partition. For example, "mkpart primary fat32 0.0 700" will create a primary partition for the fat32 filesystem which will start at cylinder 0 and go upto 700MB. Filesystem type is optional.

    rm partition_number - Removes the partition with the specified partition number

    mkfs partition_number filesystem - Makes a filesystem on the specified partition. Filesystem can be ext2, fat16, fat32, linux-swap, reiserfs.

    print - Will print the partition table. Typing "print partition_number" will give more information about that specific partition.

    quit - Will quit GNU Parted.

  • slide 5 of 6


    GParted GParted, not to be confused with GNU Parted, is a graphical frontend for GNU Parted. It is used for creating, deleting, resizing, moving, checking and copying partitions, and the file systems on them. This is useful for creating space for new operating systems, reorganizing disk usage, copying data and mirroring one partition with another.

    GParted is easy to use since it has a graphical interface. It is available in all major distributions through the package manager. A special LiveCD of GParted is also available which is very useful for diagnostics and repairing disk partitions in case of an unbootable Linux/Windows installation. You can check out an article that Berry has written specifically for GParted here.

    For more information, check out GParted's Wikipedia article. To download GParted, go to its official site here.

  • slide 6 of 6

    Final Words

    Any of these partition managers are up to the task and will help you partition your disk as per your needs. I'm personally biased towards fdisk since it's so simple, works from the command-line and is found on almost every Linux distribution. For newbies, GParted can be a very useful tool. However, make sure to use any partition manager carefully since it can cause serious damage to your data and system!