Linux parted command
The Linux parted command is a useful tool for managing disk partitions on a Linux system. It allows users to create, delete, resize, and modify partitions with ease. By using parted, you can effectively manage your disk space allocation and optimize the performance of your system. This command provides a flexible and powerful way to work with partitions, making it a valuable tool for system administrators and advanced users. With its versatile features and options, the Linux parted command is a handy utility for handling disk partitioning tasks efficiently.
parted Syntax:
parted [options] [device [command [parameters...]]]
Options:
Option | Description |
---|---|
-h, —help | Displays a help message and exits |
-l, —list | Lists partition layout on all devices |
-s, —script | Never prompts for user intervention |
-a, —align | Set alignment for new partitions |
-v, —version | Displays version information and exits |
Parameters:
Parameter | Description |
---|---|
device | Specifies the device to be partitioned |
command | Specifies the action to be taken on the device |
parameters | Additional parameters for the specified command |
parted Usage:
Create a new partition
parted /dev/sdb mkpart primary ext4 0% 100%
Create a new primary partition with ext4 filesystem from the beginning to the end of the disk.
Resize a partition
parted /dev/sdb resizepart 1 0 50%
Resize the first partition on /dev/sdb to use only the first 50% of the disk.
Check partition alignment
parted /dev/sdb align-check minimal 1
Check if the first partition on /dev/sdb is aligned properly with minimal alignment.
Set partition flag
parted /dev/sdb set 1 boot on
Set the boot flag on the first partition on /dev/sdb.
How do I use parted in Linux?
To use the parted command in Linux, execute the following command:
parted /dev/sdx
How do I list partitions with parted?
To list partitions using parted, run the following command:
parted -l
How do I create a new partition with parted?
To create a new partition using parted, follow this example:
parted /dev/sdx mkpart primary 1MiB 100MiB
How can I resize a partition with parted?
To resize a partition with parted, use the following command format:
parted /dev/sdx resizepart <partition_number> 1MiB 200MiB
How do I format a partition using parted?
To format a partition using parted, you can use the mkfs command. Here’s an example for formatting a partition as ext4:
mkfs.ext4 /dev/sdx1
How can I align partitions in parted?
To align partitions in parted for optimal performance, consider using the “align-check optimal” command. Here’s how you can do it:
parted /dev/sdx align-check optimal <partition_number>
How do I label a partition using parted?
To label a partition with a specific name using parted, you can use the “name” command. Here’s an example:
parted /dev/sdx name <partition_number> 'Data'
Applications of the parted command
- Managing disk partitions
- Creating, resizing, moving, and deleting disk partitions
- Setting partition labels and flags
- Viewing partition information
- Checking and fixing disk partition issues