How to create a new partition on a hard disk?

5,130

Solution 1

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.

Solution 2

  • 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.
Share:
5,130

Related videos on Youtube

Navaneeth Sen
Author by

Navaneeth Sen

Updated on September 17, 2022

Comments

  • Navaneeth Sen
    Navaneeth Sen over 1 year

    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?

    • Gert
      Gert over 13 years
      Are GUI applications allowed?
    • Navaneeth Sen
      Navaneeth Sen over 13 years
      No i want to do it from the command prompt
  • Navaneeth Sen
    Navaneeth Sen over 13 years
    Thanks for the reply, but i would like to know more about using fdisk and mkfs in getting this achieved.
  • Navaneeth Sen
    Navaneeth Sen over 13 years
    can you give me the commands i should use for achieving the same?
  • alex
    alex over 13 years
    @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?'
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    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).