Support >
  About independent server >
  Common operations on Linux disk partitioning tool Parted
Common operations on Linux disk partitioning tool Parted
Time : 2024-11-26 14:02:38
Edit : Jtti

parted can be used to manage Linux system disk partitions. It can be used to create, delete, resize, format, and list disk partitions. parted supports a variety of partition forms, such as MBR and GPT. Multiple file system and disk operations can also be supported.

parted use requires first running in the terminal and setting up the disk device:

sudo parted /dev/sdX

Where /dev/sdX is the disk you want to operate on (for example, /dev/sda or /dev/sdb).

If you want to view parted's help information:

sudo parted --help

To view the partition table of a disk:

(parted) print

The partition table of the current disk is displayed, including the partition size, type, and file system.

parted is used to select disks and run the mkpart command before creating a new partition. You can specify the type, name, start, and end locations of the partition. For example:

(parted) mkpart primary ext4 0GB 20GB

primary specifies the partition type, which can be either primary or logical.

ext4 is the file system type for the specified partition (ext4 in this example). parted supports many file system types such as ext4, fat32, ntfs, etc.

0GB is the starting location of the partition.

20GB is the end location of the partition.

To modify the current partition size, use the resizepart command. For example, to resize the /dev/sda1 partition:

(parted) resizepart 1 30GB

1: indicates the partition number you want to adjust.

30GB: The end location of the new partition, the size of the partition will be changed to 30GB.

When resizing a partition, ensure that the data on the partition is not corrupted. Before performing this operation, you are advised to back up important data.

To delete a partition on a disk, use the rm command. Example:

(parted) rm 1

1 indicates the number of the partition to be deleted.

parted allows you to set partition flags (for example, to set a partition as a boot partition). Use the set command to set the flag.

(parted) set 1 boot on

Explanation:

1: indicates the partition number.

boot: indicates that the partition is set to boot.

on: enables the flag.

Common partition signs include:

boot: Set it to the boot partition.

root: Set it to the root file system partition.

swap: Set it to the swap partition.

Before you can start creating a GPT or MBR partition table, you usually need to create a partition table. MBR or GPT partition table is available.

Create a GPT partition table:

(parted) mklabel gpt

Create MBR partition table:

(parted) mklabel msdos

Creating a partitioned table will erase all data on the disk, so make sure you have backed up important data before you do this.

parted allows you to choose how partitions are aligned. You can select optimize to automatically align partitions or specify a specific alignment.

(parted) align-check optimal 1

optimal: Checks whether partitions are aligned to optimize disk performance.

1: checks the first partition.

While parted is primarily used for partition management, it does not provide the ability to format partitions. To format a partition, use the mkfs command. For example, to format the ext4 file system:

sudo mkfs.ext4 /dev/sda1

After partitioning, run the quit command to exit parted.

(parted) quit

Example action: Use parted to create a GPT partition table and add partitions

Launch parted and select disk:

sudo parted /dev/sda

Create a GPT partition table:

(parted) mklabel gpt

To create a new partition (for example, a 20GB ext4 partition) :

(parted) mkpart primary ext4 0GB 20GB

Print partition table information:

(parted) print

Exit parted:

(parted) quit

parted is a powerful and flexible disk partition management tool that supports MBR and GPT partition tables and can perform a variety of common partition operations, such as creating, deleting, and resizing partitions. You need to be careful when using parted because some operations, such as creating a new partitioned table, can erase data from the disk, so be sure to back up important data before doing so.

Common parted commands include:

print: View the disk partition table

mkpart: creates a new partition

resizepart: resizes the partition size

rm: deletes a partition

mklabel: Create partition table (GPT or MBR)

set: Sets the partition flag

In combination with other tools, such as mkfs for formatting, it can help you efficiently manage disk partitions in Linux systems.

JTTI-Defl
JTTI-COCO
JTTI-Selina
JTTI-Ellis
JTTI-Eom