How do I create a new partition on a hard disk, from the terminal? I've been reading the man pages for fdisk and mkfs, but they're confusing. I need to know how to create a new partition on a blank drive, as well as on a drive that already has partitions. Some colleagues told me the latter isn't possible and I need to format; is that accurate?

  • Are GUI applications allowed? – Gert Dec 21 '10 at 7:15
  • No i want to do it from the command prompt – Sen Dec 21 '10 at 7:23

If you install GNU parted (libparted), you get an extra command line progam parted.

GNU Parted manipulates partition tables. This is useful for creating space for new operating systems, reorganizing disk usage, copying data on hard disks and disk imaging. The package contains a library, libparted, as well as well as a command-line frontend, parted, which can also be used in scripts.

| improve this answer | |
  • Thanks for the reply, but i would like to know more about using fdisk and mkfs in getting this achieved. – Sen Dec 21 '10 at 8:20
  • 3
    I'd like to add that there is a very good GUI called gparted for libparted (I know GUI's not allowed but it is still worth mentioning). – Maciej Piechotka Dec 21 '10 at 12:36
  • Backup every piece of data you can't afford to lose and don't do this on a mission-critical server.
  • umount the partition you want to split into two or more parts.
  • Use resize2fs to free up the desired amount of space at the end of partition.
  • Launch fdisk.

Unfortunately, this tool doesn't have an option to change the size of partition. You'll need to delete it first and then create the desired new partitions on the unallocated space left from it.

First re-create the partition you've just deleted with lower amount of allocated space. Be sure to specify size enough to hold your resized filesystem. Allocate the rest of unused space as you see fit.

The fdisk tool doesn't touch your partition table unless you specifically say it to do so. In case of mess up, just terminate it with ^C and start over.

  • Now that you have you new partitions setup, use an appropriate mkfs command to create new filesystems. Don't run mkfs on the original partition number -- only on the new ones!
  • Take extra care at every step as you risk the need start over in case of mistyped command.
| improve this answer | |
  • can you give me the commands i should use for achieving the same? – Sen Dec 21 '10 at 9:35
  • 1
    @Sen: sorry, no. You'll have to figure it out. Feel free to ask separate questions, specific to the command you'll trying to learn about. Like 'How do I use resize2fs?' – alex Dec 21 '10 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.