parted

Note: from a personal point-of-view, I use gdisk over parted; gdisk lets you examine changes more closely, while parted commands will often not ask for prompts.

Syntax:

parted [options] [device [command [options …] …]

Options:

  • -l - list partition layouts on all block devices
  • -a or –alignment - set alignment type for newly created partitions
    • none - use the minimum amount allowed by the disk type
    • cylinder - align partitions to cylinders
    • minimal - use minimum alignment as given by the disk topology information
    • optimal - use optimum alignment as given by the disk topology information

Commands:

  • [device] - block device to use; if none given, uses first block device
  • [command [options]]
    • print - display the partition table
    • mkpart part-type [fs-type] start end - create a new partition of type primary, logical, or extended, beginning at start and ending at end. Default unit is megabytes.
    • align-check type partition - check if partition satisifies the alignment contraint of type
    • mklabel lable-type - create a new disklabel / partition table of label-type. fex: bsd, gpt, msdos
    • name partition name - set the name of partition to name - supported by GPT, but not MBR
    • resizepart start end - set the end position of partition – this does not modify the filesystem on the partition
    • rm partition - delete the partition
    • select device - choose device as the current one to edit
    • set partition flag state - set the flag on a partition: boot, root, swap, hidden, raid, lvm, legacy_boot, etc. State should be either 'on' or 'off'.
    • unit unit - set unit as the display type; fex: 's' for sectors, 'B' for bytes, 'kB', 'MB', 'GB', 'TB', '%' of device size
    • toggle partition flag - toggle the state of flag on a partition

Display the partition table of /dev/sdc:

parted /dev/sdc print

Create a new, empty partition table on a device with GPT. Note that this will remove all existing partitions.

parted /dev/sdc mklabel gpt

Sample walkthrough

Final format: 1 MB boot partition used by GRUB, a 128 MB partition for the kernel and GRUB2 cnofig, mounted by OS as /boot, a 2 GB swap partition, and the remaining space for the root partition, mounted at /.

Wipe the partition table, create a 2MB primary partition used by GRUB2 (not /boot), starting at the 1st MB and ending at the 2nd, name it grub, and set the bios_grub label on:

parted /dev/sdc mklabel gpt
parted /dev/sdc mkpart primary 1 3 unit MB name 1 grub set 1 bios_grub on
parted /dev/sdc mkpart primary 3 131 name 2 boot
parted /dev/sdc mkpart primary 131 2179 name 3 swap