How do I create new partitions and format my hard drive in parted?

27,944

First, make sure you understand the difference between primary, extended and logical partitions. To create a logical partition, you first need to create the extended partition that will contain it. If there's only one partition on a drive, there's no point in not making it primary. Below I'll give instructions for a logical partition; creating a primary partition is similar, only simpler, so you should be able to figure it out.

Parted isn't the easiest tool for a straightforward task, a dedicated partitioning tool such as cfdisk or even fdisk may be easier to apprehend. But here goes (untested, make sure you understand what's going on and don't proceed blindly if you see error messages). You'll need to enter the size of the device when creating the partition (parted displays it).

/dev/sdb
mklabel msdos
mkpart extended 0 123456
mkpart logical 0 123455

Then run mkfs.ext3 /dev/sdb5 outside Parted.

If you choose to use cfdisk, you should be able to navigate its menu-driven interface. If you prefer fdisk, the sequence of instructions is:

n             create partition
e             extended
1             number (1–4)
<return>      accept default start
<return>      accept default end
n             create partition
l             logical
<return>      accept default start
<return>      accept default end
p             show the current table, review it
w             write changes
q             exit
Share:
27,944
Naftuli Kay
Author by

Naftuli Kay

Updated on September 18, 2022

Comments

  • Naftuli Kay
    Naftuli Kay over 1 year

    I'm somewhat new to working with commandline tools when dealing with partitioning, so you'll have to excuse my newness.

    I'm basically trying to create a new logical partition on /dev/sdb and would like to install ext3 on it. How would I do this, step by step, in parted? It's a brand-new hard drive with absolutely nothing on it.

  • Kromey
    Kromey about 13 years
    Out of curiosity, why do you advocate creating an extended+logical partition, over simply creating a primary partition? If you're just putting one big partition across the entire disk and thus don't need 5+ partitions (as made possible by the extended partition) I just don't see any point to doing it this way over just mkpart primary 0 123456. Not trying to start a discussion on this, just seeking clarification of your answer.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 13 years
    @Kromey: I don't advocate a logical partition, I'm just focusing on it because that's what the question requested. In fact I advocated using a primary partition; hopefully my edit makes this a bit clearer.
  • Kromey
    Kromey about 13 years
    Sorry, I must have mis-read both question and answer, unless your edit was to add the "not" in front of "making it primary".
  • Lennart Rolland
    Lennart Rolland almost 10 years
    I love fdisk as much as the next guy, but please be aware that it is on its way to becoming legacy due to a lack of support for many modern partition table formats (read GPT). I think parted and cfdisk handle this better.
  • grochmal
    grochmal over 7 years
    That is incorrect, parted does not build the root inodes of a filesystem.