Overview
parted, short for 'partition editor', is a powerful partition management tool designed to overcome the limitations of fdisk. While fdisk primarily supports MBR (Master Boot Record) style partition tables, parted supports both MBR and GPT (GUID Partition Table). This is essential for managing large storage devices over 2TB or partition structures in modern systems. Additionally, parted supports both interactive and non-interactive modes, making it convenient for use in scripts.
Key Features
The key features of the parted command are as follows:
- Supports both MBR and GPT partition tables.
- Can effectively manage large-capacity disks over 2TB.
- Supports both interactive and non-interactive modes.
- Provides various functions such as creating, deleting, resizing partitions, and creating file systems.
Differences from fdisk
fdisk and parted are both partition management tools, but they differ in the partition table types they support and their functionalities.
- fdisk: Specializes in MBR partition tables and may not properly handle disks larger than 2TB.
- parted: Supports both MBR and GPT partition tables and is suitable for managing large-capacity disks over 2TB.
Key Options
parted primarily operates either in non-interactive mode with specific options or by entering interactive mode and using internal commands.
1) 실행 옵션
Generated command:
Try combining the commands.
Description:
`parted` Executes the command.
Combine the above options to virtually execute commands with AI.
Interactive Mode Internal Commands
When parted is executed for a specific device (e.g., `sudo parted /dev/sda`), it enters interactive mode. These are the main commands available in this mode. Unlike fdisk, `parted` applies commands immediately, so caution is advised.
Key Internal Commands
In interactive mode, typing `help` will show a list of all commands.
- print: Prints the current disk's partition table.
- mklabel gpt | msdos: Creates a GPT or MBR partition label on the disk. All existing partitions will be deleted.
- mkpart: Creates a new partition. You must specify the partition type, file system type, and start/end locations.
- resizepart: Resizes an existing partition.
- rm: Deletes the partition with the specified number.
- quit: Exits parted. **Since parted applies commands immediately, using `quit` does not undo changes.**
Usage Examples
Learn the functions of the parted command through various usage examples. **parted applies commands immediately, so use it with caution.**
Display All Partition Information
sudo parted -l
Checks partition information for all disks connected to the system. Performs the same function as fdisk's `-l` option.
Create GPT Partition Label
sudo parted /dev/sdb mklabel gpt
Creates a GPT partition label on a new disk (`/dev/sdb`). This command deletes all existing partitions on the disk.
Create New Partition (Non-interactive Mode)
sudo parted -s /dev/sdb mkpart primary ext4 1MiB 10GiB
Creates a 10GB 'primary' partition using the ext4 file system on `/dev/sdb`. This is suitable for scripting in non-interactive mode.
Delete Partition
sudo parted /dev/sdb rm 2
Deletes partition number 2 on the `/dev/sdb` disk using the `rm` command.
Installation
parted is typically included by default in most Linux distributions. If the package is not present, you can install the `parted` package.
Debian/Ubuntu
sudo apt update
sudo apt install -y parted
RHEL/CentOS/Fedora
sudo dnf install -y parted
Arch Linux
sudo pacman -S --needed parted
Tips & Cautions
Here are some points to note when using the parted command.
Tips
- Unlike fdisk, parted applies changes immediately upon command input, so always back up your data and proceed with caution. The `mklabel` command, in particular, will delete all data on the disk.
- Using non-interactive mode (`-s`, `--script`) allows you to write scripts to automate partition tasks.
- After creating a partition, you must format the file system using the `mkfs` command. (e.g., `sudo mkfs.ext4 /dev/sdb1`)
- When specifying units in interactive mode, it is recommended to use binary prefixes like `GiB`, `MiB`. `GB` and `MB` denote decimal values, which can cause confusion.