YouTip LogoYouTip

Linux Comm Parted

[![Image 1: Linux Command Manual](#) Linux Command Manual](#) * * * ## 1. Overview of the parted Command parted is a powerful disk partitioning tool in Linux systems. It supports multiple partition table types (such as GPT and MBR) and can create, delete, resize, and manage disk partitions. Compared to the traditional fdisk, parted is particularly suitable for handling large-capacity disks (over 2TB) and modern partitioning needs. ### Main Features * **Interactive and Non-Interactive**: Supports both command-line direct operation and interactive operation modes * **Immediate Effect**: Most operations are written to the disk immediately without additional confirmation * **Multiple File System Support**: ext2/3/4, xfs, btrfs, fat, ntfs, etc. * **Non-destructive Resizing**: Can resize partitions without data loss (requires file system support) * * * ## 2. Installation and Basic Syntax ### Installing parted Most Linux distributions come with parted pre-installed. If installation is needed: # Debian/Ubuntu sudo apt install parted # CentOS/RHEL sudo yum install parted ### Basic Command Syntax ## Example parted [command ] ### Common Options | Option | Description | | --- | --- | | `-l` | List partition information for all block devices | | `-s` | Script mode (non-interactive) | | `-a` | Set alignment type (min/opt/none) | | `-f` | Suppress some warning messages | * * * ## 3. Interactive Operation Mode ### Entering Interactive Mode ## Example sudo parted /dev/sdX Replace `/dev/sdX` with your actual device name (e.g., `/dev/sda`) ### Common Commands in Interactive Mode **View Help** ## Example help **View Partition Table** ## Example print **Switch Units** ## Example unit GB # Switch to GB display unit MB # Switch to MB display **Create a New Partition** ## Example mkpart start position end position Example: ## Example mkpart primary ext4 1GB 10GB **Delete a Partition** ## Example rm **Resize a Partition** ## Example resizepart end position **Set Partition Flags** ## Example set on/off Common flags: `boot`, `lvm`, `raid`, `swap`, etc. **Exit** ## Example quit * * * ## 4. Common Operation Examples ### Example 1: View All Disk Partitions ## Example sudo parted -l Sample Output: Model: ATA ST1000DM010-2EP1 (scsi)Disk /dev/sda: 1000GBSector size (logical/physical): 512B/4096BPartition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 538MB 537MB fat32 boot, esp 2 538MB 1000GB 999GB ext4 ### Example 2: Create a New Partition Table (GPT Format) ## Example sudo parted /dev/sdb mklabel gpt ### Example 3: Create a Primary Partition (Non-Interactive) ## Example sudo parted -s/dev/sdb mkpart primary ext4 1MiB 10GiB ### Example 4: Resize a Partition ## Example sudo parted -s/dev/sdb resizepart 2 20GiB ### Example 5: Set the Boot Flag ## Example sudo parted -s/dev/sda set 1 boot on * * * ## 5. Advanced Features and Precautions ### 1. Partition Alignment Optimization Modern disks (especially SSDs) require correct partition alignment for optimal performance: ## Example sudo parted -a optimal /dev/sdb mkpart primary ext4 0%100% ### 2. Convert Partition Table Type ## Example sudo parted /dev/sdb mklabel msdos # Convert to MBR sudo parted /dev/sdb mklabel gpt # Convert to GPT ⚠️ Note: This will delete all partitions on the disk! ### 3. File System Operations parted only manages partitions; creating a file system requires an additional command: ## Example sudo mkfs.ext4 /dev/sdb1 ### 4. Precautions * **Data Security**: Partitioning operations may cause data loss, be sure to back up first * **Partition in Use**: Cannot modify mounted partitions * **Size Units**: Specify units explicitly (e.g., GB/MB), otherwise bytes are used by default * **GPT vs MBR**: Disks larger than 2TB must use the GPT partition table * * * ## 6. Comparison of parted vs fdisk/gdisk | Feature | parted | fdisk | gdisk | | --- | --- | --- | --- | | Interactive Mode | Supported | Supported | Supported | | Script Mode | Supported | Not Supported | Not Supported | | GPT Support | Yes | Limited Support | Yes | | Large Disk Support | Yes | No (MBR only) | Yes | | Immediate Write | Yes | No (requires w command) | No (requires w command) | | Resize Partition | Yes | No | No | [![Image 2: Linux Command Manual](#) Linux Command Manual](#)
← Linux Comm LspciLinux Comm Lsblk β†’