The usage of parted in command line and interactive mode
Parted is a program used to manipulate disk partitions, usually for partitions with a regular size of more than 2T, and can also be used for planning small partitions; it supports a variety of partition table formats, including MS-DOS (MBR) and GPT;, which is useful for creating space for new operating systems, reorganizing disk usage, and copying data to new hard disks; the operation of the parted command takes effect in real time, and you should be careful every step of the operation.
Parted has two modes: command line and interactive
In interactive mode, enter one command at a time (command completion is supported), and then modify the disk immediately
Interaction can be disabled using the "- s" option
All operations of parted take effect in real time.
MBR and GPT are incompatible and cannot be converted into each other.
Usage: parted [OPTIONs] [DEVICE [COMMANDs [PARAMETER...]...]]
Interactive mode: parted [DEVICE]
Command line mode: parted [OPTIONs] DEVICE COMMANDs PARAMETER
Options:
-l,-- list: lists all partition layouts on all block devices
-s,-- script: avoid interaction with users; that is, turn off interaction
Subcommands: abbreviations are supported and case-insensitive (after version 2.4, the following commands have been removed: check, cp, mkfs, mkpartfs, move, resize)
Command line COMMAND
Print [devices | free | list | all |]: displays the partition table, including available devices, free space, all found partitions, or specific partitions
Unit UNIT: setting default unit
UNIT
S: sector (n bytes, depending on sector size, usually 512)
B: byte
KiB: kilobytes (1024 bytes)
MiB: megabytes (1048576 bytes)
GiB:gibibyte (1073741824 bytes)
TiB:tebibyte (1099511627776 bytes)
KB: kilobytes (1000 bytes)
MB: megabytes (1000000 bytes)
GB: gigabytes (1000000000 bytes)
TB: megabytes (1000000000000 bytes)
%: percentage of devices (between 0 and 100)
Cyl: cylindrical (related to BIOS CHS geometry)
Chs: cylindrical, head, sector addressing (related to BIOS CHS geometry)
Compact: this is a special unit, the default input is megabytes, and select a unit to represent the output in a compact readable format
Mklabel, mktable LABEL_TYPE: create a new partition table
LABEL_TYPE:
"aix", "amiga", "bsd", "dvh", "gpt", "loop", "mac", "msdos", "pc98", "sun"
Mkpart PART_TYPE [NAME] [FILESYSTEM_TYPE] START END [UNIT]: create a new partition (which can indicate the file system), indicating the starting location (the default unit is M)
PART_TYPE
"primary", "extended", "logical"
FILESYSTEM_TYPE
"btrfs", "ext2", "ext3", "ext4", "fat16", "fat32", "hfs", "hfs+", "linux-swap", "ntfs", "reiserfs", "xfs"
START,END: specifies the start / end position of the partition (offset from the beginning of the disk); its value can be integer or decimal, with the suffix UNIT
Supported UNIT: "s" (sectors), "B" (bytes), "kB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "%" (percentage of device size), "compact", "- 1s" points to the last sector of the disk (a negative number is counted from the end of the disk)
Note: the parted command does not modify the / etc/fstab file; after the partition is created, the / etc/fstab file needs to be modified manually
Resizepart PART_NUMBER END: modify the location where the partition ends; that is, modify the partition size (does not modify any file systems that exist in the partition)
Rm PART_NUMBER: deleting partition
Note about 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 partition number 6, logical partitions numbered 7, 8, and 9 will be renumber to 6, 7, and 8, respectively; for example, this means that you must update the / etc/fstab file
Set PART_NUMBER TYPE STATUS: setting partition type and status
Disk_set TYPE STATUS: changing partition type and state
TYPE
"boot", "root", "swap", "hidden", "raid", "lvm", "lba", "legacy_boot", "palo"
STATUS
"on", "off"
Toggle PART TYPE: toggle partition type (append)
TYPE
Root:Linux root file system; this TYPE (Mac) should be enabled if the partition is the root device to be used by Linux
Swap:Linux swap (Mac)
Legacy_boot: used to inform proprietary software that this GPT partition is bootable (GPT)
Boot: boot from this partition (Mac, MS-DOS, PC98)
Bios_grub: enable it to record that the selected partition is a GRUB BIOS partition (GPT)
Raid: soft RAID (MS-DOS)
LVM:LVM PV (MS-DOS)
Msftdata: used to identify the partition (GPT) that contains the Microsoft file system (NTFS or FAT)
Msftres: used to identify the "Microsoft reserved partition" used by Windows, note that this flag (MS-DOS,GPT) should not normally be set on Windows file system partitions (partitions that contain NTFS or FAT file systems)
Irst: identifies Intel Quick start Technology Partition (MS-DOS, GPT)
Esp: identifies the UEFI system partition; on GPT, it is the boot alias (MS-DOS, GPT)
Hidden: identified to hide partitions from the Microsoft operating system (MS-DOS, PC98)
DIAG: enable it to indicate that a partition can be used as a diagnostic / recovery partition (MS-DOS)
Name PART_NUMBER NAME: sets / changes partition names; this COMMAND applies only to Mac, PC98, and GPT partition tables, with names enclosed in quotation marks
Rescue START END: rescue the missing partition between START and END; if the partition is found, the split will ask you if you want to create an entry for it in the partition table.
Interactive COMMAND: in interactive mode, enter one command at a time (command completion is supported), and then modify the disk immediately
Enter interactive: parted [DEVICE]
DEVICE: indicates the block device to be operated; the default is the first
Select DEVICE: select the specified block device as the current device to operate (default is / dev/sda); the device should usually be a Linux hard disk device, or it can be a partition, soft RAID device, or LVM logical volume
Unit UNIT: setting default unit
UNIT
"s" (sectors), "B" (bytes), "kB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "%" (percentage of device size), "cyl" (cylinders), "chs" (cylinders, heads, sectors), "compact"
S: sector (n bytes, depending on sector size, usually 512)
Q, qu, qui, quit: exit Interactive parted; only after Parted exits will the Linux kernel know what changes Parted has made to disk
Help [COMMAND]: displays help information for a COMMAND; uses it in interactive mode
Example of parted command
Create a MBR partition table
# parted-s / dev/sdb mklabel msdos
Create a GPT partition table
# parted-s / dev/sdb mklabel gpt
Create a partition on the partition table and create a file system
# parted-s / dev/sdb mkpart primary ext4 0.0%
Create a gpt partition and allocate all the space of the hard disk to this partition. The file system is ext4.
# parted-s / dev/sdb mklabel gpt mkpart primary ext4 0.0%
Activate the partition
# parted-s / dev/sdb set 1 boot on
Set the partition name
# parted / dev/sdb name 1 'DATA_DISK'
Delete partition
# parted / dev/sdb rm 1
View available partitions
# parted / dev/sdb print devices