# GNU Parted

Not to be confused with Gparted, a frontend for GNU parted.

GNU Parted is a program for creating and manipulating partition tables.

## Installation

Install parted from the official repositories.

## Using GNU Parted

Parted has two modes: command line and interactive. Parted should always be started with:

        # parted device

where `device` is the hard disk device to edit (for example `/dev/sda`).

Note: If you omit the DEVICE argument, Parted will attempt to guess which device you want.

In command line mode, this is followed by one or more commands. For example:

        # parted /dev/sda mklabel gpt mkpart P1 ext3 1MiB 8MiB

Note: Options (like --help) can only be specified on the command line.

In interactive mode, commands are entered one at a time at a prompt, and modify the disk immediately. For example:

        (parted) mklabel gpt
        (parted) mkpart P1 ext3 1MiB 8MiB

Note: *Some abbreviations are allowed. For example, you can type “p” instead of “print”, and “u” instead of “units”.

- If you do not give a parameter to a command, Parted will prompt you for it. For example:

        (parted) mklabel
        New disk label type? gpt

- Parted will always warn you before doing something that is potentially dangerous, unless the command is one of those that is inherently dangerous (viz., rm, mklabel and mkpart). Since many partitioning systems have complicated constraints, Parted will usually do something slightly different to what you asked. (For example, create a partition starting at 10.352Mb, not 10.4Mb) If the calculated values differ too much, Parted will ask you for confirmation.

## Command line options

When used from the command line, Parted supports the following syntax:

        # parted [option] device [command [argument]]

Available options and commands follow. For detailed explanations of the use of Parted commands, see Command explanations. Options begin with a hyphen, commands do not:

Options:

- ‘-h’
  - ‘--help’
    - display a help message
- ‘-s’
  - ‘--script’
    - never prompt the user
- ‘-a alignment-type’
  - ‘--align alignment-type’
    - Set alignment for newly created partitions, valid alignment types are: none, cylinder, minimal and optimal.
- ‘-v’
  - ‘--version’
    - display the version

## Command list

### align-check

Usage:

    align-check align-type n

Determine whether the starting sector of partition n meets the disk's selected alignment criteria. align-type must be ‘minimal’, ‘optimal’ or an abbreviation. When in script mode, if the partition does not meet the alignment requirement, exit with status 1; otherwise (including on older kernels for which alignment data is not available), continue processing any remaining commands. Without --script, print either ‘N aligned’ or ‘N not aligned’.

Example:

                 (parted) align-check minimal 1
                 1 aligned

### disk_set

Usage: disk_set flag state

Changes a flag on the disk. A flag can be either “on” or “off”. Some or all of these flags will be available, depending on what disk label you are using:

`pmbr_boot`

    (GPT) - this flag enables the boot flag on the GPT's protective MBR partition.

The disk's flags are displayed by the print command on the "Disk Flags:" line. They are also output as the last field of the disk information in machine mode.

                 (parted) disk_set pmbr_boot on

Result: Set the PMBR's boot flag.

### help

Usage:

    help [command]

Prints general help, or help on a command.

Example:

                 (parted) help mklabel

Result: Print help for the mklabel command.

### mklabel

Usage:

    mklabel label-type

Creates a new disk label, of type label-type. The new disk label will have no partitions. This command (normally) will not technically destroy your data, but it will make it basically unusable, and you will need to use the rescue command (see Related information) to recover any partitions. Parted works on all partition tables. 1

`label-type` must be one of these supported disk labels:

- bsd
- loop (raw disk access)
- gpt
- mac
- msdos
- pc98
- sun

Example:

                 (parted) mklabel msdos

Result: Create an MS-DOS disk label. This is still the most common disk label for PCs.

### mkpart

Usage:

    mkpart [part-type fs-type name] start end

Creates a new partition, without creating a new file system on that partition. This is useful for creating partitions for file systems (or LVM, etc.) that Parted does not support. You may specify a file system type, to set the appropriate partition code in the partition table for the new partition. fs-type is required for data partitions (i.e., non-extended partitions). start and end are the offset from the beginning of the disk, that is, the “distance” from the start of the disk.

`part-type` is one of ‘primary’, ‘extended’ or ‘logical’, and may be specified only with ‘msdos’ or ‘dvh’ partition tables. A name must be specified for a ‘gpt’ partition table. Neither part-type nor name may be used with a ‘sun’ partition table.

`fs-type` must be one of these supported file systems:

- ext2
- fat16, fat32
- hfs, hfs+, hfsx
- linux-swap
- NTFS
- reiserfs
- ufs

Example:

                 (parted) mkpart logical 0.0 692.1

Result: Create a logical partition that will contain an ext2 file system. The partition will start at the beginning of the disk, and end 692.1 megabytes into the disk.

### name

Usage:

    name number name

Sets the name for the partition number (GPT, Mac, MIPS and PC98 only). The name can be placed in quotes. Example:

                 (parted) name 2 'Secret Documents'

Result: Set the name of partition 2 to `Secret Documents'.

### print

Usage: print [number]

Displays the partition table on the device parted is editing, or detailed information about a particular partition.

Example:

                 (parted) print

Result:

                 Disk geometry for /dev/sda: 0.000-2445.679 megabytes
                 Disk label type: msdos
                 Minor    Start       End     Type      Filesystem  Flags
                 1          0.031    945.000  primary   fat32       boot, lba
                 2        945.000   2358.562  primary   ext2
                 3       2358.562   2445.187  primary   linux-swap
                 (parted) print 1
                 Minor: 1
                 Flags: boot, lba
                 File System: fat32
                 Size:            945.000Mb (0%)
                 Minimum size:     84.361Mb (0%)
                 Maximum size:   2445.679Mb (100%)

### quit

Usage:

    quit

Quits Parted.

It is only after Parted exits that the Linux kernel knows about the changes Parted has made to the disks. However, the changes caused by typing your commands will probably be made to the disk immediately after typing a command. However, the operating system's cache and the disk's hardware cache may delay this.

### rescue

Usage:

    rescue start end

Rescue a lost partition that used to be located approximately between `start` and `end`. If such a partition is found, Parted will ask you if you want to create a partition for it. This is useful if you accidently deleted a partition with parted's rm command, for example. Example:

    (parted) rescue
             Start? 0
             End? 8056
             Information: A ext3 primary partition was found at 0.031MB ->
             8056.030MB.  Do you want to add it to the partition table?
             Yes/No/Cancel? y

Result: The partition found by `resuce` is restored.

### rm

Usage:

    rm number

Removes the partition with number `number`. If you accidently delete a partition with this command, use mkpart to recover it. Also, you can use the gpart program (see Related information) to recover damaged disk labels.

Note for msdos disk labels: if you delete a logical partition, all logical partitions with a larger partition number will be renumbered. For example, if you delete a logical partition with a partition number of 6, then logical partitions that were number 7, 8 and 9 would be renumbered to 6, 7 and 8 respectively. This means, for example, that you have to update `/etc/fstab`.

Example:

                 (parted) rm 3

Result: Remove partition 3.

### select

Usage:

    select device

Selects the device, `device`, for Parted to edit. The device can be a Linux hard disk device, a partition, a software RAID device or LVM logical volume.

Example:

                 (parted) select /dev/sdb

Result: Select /dev/sdb (the slave device on the first ide controller on Linux) as the device to edit.

### set

Usage:

    set number flag state

Changes a flag on the partition with number number. A flag can be either “on” or “off”. Some or all of these flags will be available, depending on what disk label you are using:

- ‘bios_grub’

  (GPT) - Enable this to record that the selected partition is a GRUB BIOS partition.

- ‘legacy_boot’

  (GPT) - this flag is used to tell special purpose software that the GPT partition may be bootable.

- ‘boot’

  (Mac, MS-DOS, PC98) - should be enabled if you want to boot off the partition. The semantics vary between disk labels. For MS-DOS disk labels, only one partition can be bootable. :If you are installing LILO on a partition that partition must be bootable. For PC98 disk labels, all ext2 partitions must be bootable (this is enforced by Parted).

- ‘lba’

  (MS-DOS) - this flag can be enabled to tell MS DOS, MS Windows 9x and MS Windows ME based operating systems to use Linear (LBA) mode.

- ‘root’

  (Mac) - this flag should be enabled if the partition is the root device to be used by Linux.

- ‘swap’

  (Mac) - this flag should be enabled if the partition is the swap device to be used by Linux.

- ‘hidden’

  (MS-DOS, PC98) - this flag can be enabled to hide partitions from Microsoft operating systems.

- ‘raid’

  (MS-DOS) - this flag can be enabled to tell linux the partition is a software RAID partition.

- ‘LVM’

  (MS-DOS) - this flag can be enabled to tell linux the partition is a physical volume.

- ‘PALO’

  (MS-DOS) - this flag can be enabled so that the partition can be used by the Linux/PA-RISC boot loader, palo.

- ‘PREP’

  (MS-DOS) - this flag can be enabled so that the partition can be used as a PReP boot partition on PowerPC PReP or IBM RS6K/CHRP hardware.

- ‘DIAG’

  (MS-DOS) - Enable this to indicate that a partition can be used as a diagnostics / recovery partition.

The print command displays all enabled flags for each partition.

Example:

                 (parted) set 1 boot on

Result: Set the ‘boot’ flag on partition 1.

### unit

Usage:

    unit unit

Selects the current default unit that Parted will use to display locations and capacities on the disk and to interpret those given by the user if they are not suffixed by an unit.

`unit` may be one of:

- ‘s’

  sector (n bytes depending on the sector size, often 512)

- ‘B’

  byte

- ‘KiB’

  kibibyte (1024 bytes)

- ‘MiB’

  mebibyte (1048576 bytes)

- ‘GiB’

  gibibyte (1073741824 bytes)

- ‘TiB’

  tebibyte (1099511627776 bytes)

- ‘kB’

  kilobyte (1000 bytes)

- ‘MB’

  megabyte (1000000 bytes)

- ‘GB’

  gigabyte (1000000000 bytes)

- ‘TB’

  terabyte (1000000000000 bytes)

- ‘%’

  percentage of the device (between 0 and 100)

- ‘cyl’

  cylinders (related to the BIOS CHS geometry)

- ‘chs’

  cylinders, heads, sectors addressing (related to the BIOS CHS geometry)

- ‘compact’

  This is a special unit that defaults to megabytes for input, and picks a unit that gives a compact human readable representation for output.

The default unit apply only for the output and when no unit is specified after an input number. Input numbers can be followed by an unit (without any space or other character between them), in which case this unit apply instead of the default unit for this particular number, but CHS and cylinder units are not supported as a suffix. If no suffix is given, then the default unit is assumed. Parted will compute sensible ranges for the locations you specify (e.g. a range of +/- 500 MB when you specify the location in “G”, and a range of +/- 500 KB when you specify the location in “M”) and will select the nearest location in this range from the one you wrote that satisfies constraints from both the operation, the filesystem being worked on, the disk label, other partitions and so on. Use the sector unit “s” to specify exact locations (if they do not satisfy all constraints, Parted will ask you for the nearest solution). Note that negative numbers count back from the end of the disk, with “-1s” pointing to the last sector of the disk.

Note: As of parted-2.4, when you specify start and/or end values using IEC binary units like “MiB”, “GiB”, “TiB”, etc., parted treats those values as exact, and equivalent to the same number specified in bytes (i.e., with the “B” suffix), in that it provides no “helpful” range of sloppiness. Contrast that with a partition start request of “4GB”, which may actually resolve to some sector up to 500MB before or after that point. Thus, when creating a partition, you should prefer to specify units of bytes (“B”), sectors (“s”), or IEC binary units like “MiB”, but not “MB”, “GB”, etc.
Categories:

- File systems
- System recovery