parted Information

parted is a Lynux program that partitions disks. parted works on MBR and GPT partitions. Type man parted in a command window to see all the options for parted.

Open a superuser command window to call parted.

parted can be used interactively or can be called from scripts. The following can be issued in interactive mode, after typing parted in a command window.

Useful commands

select /dev/sdb
Select the drive to be partitioned.
rm n
Remove a partion by number. The partiion will be removed from the currently selected drive.
mktable type
Create the partition table for the current drive. Type can be either msdos or gpt.
unit type
Set the default unit. Type can be: kB = Kilobytes = 1000 bytes; KiB = Kibibytes = 1024 bytes; MB, MiB, GB, GiB; s = sectors; b = bytes. The most useful are s and MiB. The default is kB and it is not very useful. I recommend using MiB.
mkpart type start end
If the partition table is msdos, then type can be primary, extended or logical. If the partition table is gpt, then type is just a name that can have any value. The start and end values are in the default unit. Another unit can be used by adding one of the aabove unit types after the number.
print
Display the partition information for the current drive.
quit
Quit!

There is always a default disk. Be sure to select the disk you want, or you might edit the boot disk by mistake.

Help for any command can be listed with m

View a video on partitioning with parted.

Scripting with parted

Create a script file with parted commands. Each command must specify the disk to use.

parted /dev/sdc mkpart primary 1MiB 3.99MiB
parted /dev/sdc unit MiB print

Run the script from a superuser command window:

./myParted.sh

The output of the command will look something like

Information: You may need to update /etc/fstab.

Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdc: 20.0MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start    End      Size     File system  Name   Flags
 1      1.00MiB  3.99MiB  2.99MiB               primary

Redirect the output of the script to a text file with

./myParted.sh > myParted.out.txt