Introduction
Linux
In-houseparted
Commands are a multi-functional tool for creating, modifying, and managing disk partitions. It supports traditionalMBR
(Master Boot Record: Master Boot Record) and modernGPT
(GUID Partition Table: GUID Partition Table) Partition scheme.
The main reasons for disk partitioning
Optimal performance: Proper partition management can improve system speed and responsiveness. For example, separating operating system files from user data, or placing frequently accessed data on faster sections on disk can improve performance.
Data Organization: Partitioning allows users to isolate data based on type, purpose, or importance. For example, system files, personal data, and backup files can be placed in separate partitions to ensure better organization and faster data retrieval.
Data Security: By isolating sensitive or critical data in its own partition, you can reduce the risk of being affected by system crashes, malware, or corrupted software on other partitions.
Backup and Restore: Partitioning makes backup data more direct. Instead of backing up the entire drive, you can focus on specific partitions. This makes the recovery process faster and is more targeted when data is lost.
Dual boot and system upgrade: A separate partition is crucial for those who want to run multiple operating systems or test new software versions. This allows users to have multiple operating system versions or settings without interfering with their main system.
Main features
Create, delete, resize, and move partitions.
use
GPT
Supports large disk sizes (>2 TB).Can handle various file systems such as
ext4、NTFS、FAT32
wait.Suitable for interactive and non-interactive modes.
grammar
parted [options] [device] [command [arguments]]
device
: The target disk, for example:/dev/sda
,/dev/nvme0n1
command
: Specific operations, such as creating or resizing partitions.
Common options and subcommands
-l, --list
: List the partition layouts on all block devices-a <alignment-type>, --align <alignment-type>
: Set the alignment for newly created partitionsalign-check <type> <partition>
: Alignment check,type
Type is:minimal
oroptimal
mklabel <label-type>
: Create a new partition tablemkpart [part-type name fs-type] [start] [end]
: Create a new partitionprint [print-type]
: Display partition tablerescue [start] [end]
: Rescue and restore lost partitionsresizepart [partition] [end]
:Reallocate partition sizerm [partition]
: Delete the partitionselect [device]
: Select the device, select the device as the current device to be edited. The equipment should usually beLinux
Hard disk device, but if necessary it can be a partition, a software raid device, or an LVM logical volume.set [partition] [flag] [state]
: Set the partition flag and status
Example usage
Start Parted in interactive mode
sudo parted /dev/sdX
Start Parted in non-interactive mode
sudo parted /dev/sdX mklabel gpt
View partition table
sudo parted /dev/sdX print
Create a partition table
Choose GPT (recommended for modern systems) or MBR
sudo parted /dev/sdX mklabel gpt
sudo parted /dev/sdX mklabel msdos
Create a partition
Create a primary partition
sudo parted /dev/sdX mkpart primary ext4 0% 50%
primary
: Partition typeext4
: File system type0%
: Start position (start of disk)50%
: End location (50% of disk space)
Format partition
sudo mkfs.ext4 /dev/sdX1
Reassign partition size
Resize the partition to 80% of the disk:
sudo parted /dev/sdX resizepart 1 80% # 1 represents the partition number
Delete a partition
sudo parted /dev/sdX rm 1 # 1 represents the partition number
Interactive mode example
sudo parted /dev/sdX (parted) mklabel gpt (parted) mkpart primary ext4 1MiB 100% (parted) print (parted) quit
Align partitions
sudo parted /dev/sdX mkpart primary ext4 1MiB 100% --align optimal
Check partition
sudo parted /dev/sdX check 1
Setting bootable flags
Mark the partition as bootable
sudo parted /dev/sdX set 1 boot on
Change the name of the partition
sudo parted /dev/sdX name 1 MyPartition
Create a full disk partition
sudo parted /dev/sdX mklabel gpt sudo parted /dev/sdX mkpart primary ext4 0% 100%
Script partition creation
To achieve automation, run commands without interaction
sudo parted /dev/sdX --script mklabel gpt sudo parted /dev/sdX --script mkpart primary ext4 1MiB 50%
The main similarities and similarities between MBR and GPT
Features | MBR | GPT |
---|---|---|
Maximum disk size | 2 TB | >9 ZB |
Maximum number of partitions | 4 main partitions | Unlimited (default is 128) |
compatibility | Old system | Modern system |
redundancy | No backup table | There is a backup table |
The above is the detailed content of the operating guide for using parted for disk partitioning in Linux. For more information about Linux parted disk partitioning, please follow my other related articles!