parted partition in GPT format

  • fdisk partition tool, its partition format is MBR, and its characteristic is that it can be divided into 4 primary partitions at most, and the disk size cannot exceed 2T.
  • The GPT partition format breaks through these limitations. It has no main partition, extended partition, and logical partition. It can be divided into up to 128 partitions on a single disk, supports partitions larger than 2T, and the maximum volume can reach 18EB.

Common functions of parted tools:

  • After entering parted on the command line, enter the interactive mode of the parted command. Type help to display help information. The following is a brief introduction to the commonly used functions
  1. check simply checks the filesystem. It is recommended to check the file system with other commands, such as fsck
  2. help display help information
  3. mklabel creates a partition table, that is, whether to use msdos (MBR) or gpt, or other ways to partition the table
  4. mkfs creates a filesystem. This command does not support the ext3 format, so it is recommended not to use it. It is best to use parted to partition the partition, then exit the parted interactive mode, and use other commands to partition, such as: mkfs.ext3
  5. mkpart creates a new partition.
  • 格式:mkpart PART-TYPE [FS-TYPE] START END
  • The main types of PART-TYPE are primary (primary partition), extended (extended partition), logical (logical area). Extended partition and logical partition are only for msdos.
  • fs-type file system type, mainly fs32, NTFS, ext2, ext3, etc.
  • start end The start and end position of the partition.
  1. mkpartfs builds partitions and their filesystems. The ext3 filesystem is not currently supported, so it is not recommended to use this feature. Finally, after the partition is divided, exit parted, and then use other commands to create a file system.
  2. print outputs partition information. This function has 3 options,
  • free Displays all information about the disk and displays the remaining space on the disk
  • number Displays information about the specified partition
  • all show all disk information
  1. resize Resize the specified partition. The current support for ext3 format is not very good, so it is not recommended to use this function.
  2. rescue restores accidentally deleted partitions. If you accidentally delete a partition with parted's rm command, you can recover it through the rescue function. When restoring, you need to give the start and end positions of the partition. Then parted will search within the given range and prompt to restore the partition.
  3. rm deletes the partition.
  • Command format rm number
    • Such as: rm 3 is to delete the partition numbered 3
  1. select Selects a device. After entering the parted command, press Enter directly to enter the interactive mode. If there are multiple hard disks, you need to use select to select the hard disk to be operated. Such as: select /dev/sdb
  2. set sets the flag. Change the flag for the specified partition number. The signs are usually as follows: boot hidden raid lvm and so on. boot is the boot partition, hidden is the hidden partition, raid is the soft raid, and lvm is the logical partition.
  • Such as: set 3 boot on set partition number 3 as the boot partition
  • Note: The above contents are commonly used functions of parted. Since the tool currently does not support ext3 very well, some functions cannot be applied, such as move (moving partition) and resize.

An example of the parted partition function.

  1. Use the command mode to create a gpt type file partition table for /dev/sdb, and divide it into 500G partitions. Then create an ext3 filesystem for that partition. And mount the partition under the /test folder.
parted /dev/sdb mklabel —创建分区表
parted /dev/sdb mkpart ext3 0 500000 —创建500G分区/dev/sdb1
mkfs.ext3 /dev/sdb1 —-将分区/dev/sdb1格式化成ext3格式文件系统
mount /dev/sdb1 /test —将/dev/sdb1 挂载在/test下
  • If you want the system to automatically mount /dev/sdb1, you need to manually edit the /etc/fstab file. And add the following content at the end of the file: /dev/sdb1 /test ext3 defaults 0 0 2. Create an interactive partition with a size of 4G. Since 500G of /dev/sdb1 has been created, the re-created partition is /dev/sdb2
parted /dev/sdb mkpart swap 500000 504000 —创建4G分区/dev/sdb2
mkswap /dev/sdb2 —-将/dev/sdb2创建为交换分区
swapon /dev/sdb2 —-激活/dev/sdb2
  • If you want the system to automatically mount the /dev/sdb2 swap partition, you need to manually edit the /etc/fstab file. and add the following at the end of the file: /dev/sdb2 swap swap defaults 0 0
  1. Recover accidentally deleted partitions (also refer to the testdisk command). Since parted writes directly to the disk, once a partition is accidentally deleted, it is recommended to use rescue immediately. The following is an example to understand the recovery process.
parted /dev/sdb mkpart ext3 504000 514000 —-创建10G分区/dev/sdb3
mkfs.ext3 /dev/sdb3 —将/dev/sdb3格式化成ext3文件系统。
parted /dev/sdb rm 3 —-删除/dev/sdb3
parted /dev/sdb rescue 504000 514000 —依照屏幕提示,输入yes即可恢复被误删除分区

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325442107&siteId=291194637