linux parted 实用程序

GNU parted 实用程序还用于查看现有分区表、更改现有分区的大小或者从可用空间或者另外硬盘驱动器添加分区。
此实用程序比 fdisk 实用程序更先进。
它支持更多的磁盘标签类型并提供另外的命令。
分开的语法是:

# parted [option] [device_name] [command [argument]]

以交互方式使用 parted 一次输入一个命令。
仅包含设备作为调用交互模式的参数。
例子:

# parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

在 (parted) 提示符下,输入命令或者键入 help 以查看可用命令的列表。
通过键入 help 和命令来获取有关特定命令的其他帮助。
例子:

重命名分区

仅在 GPT 分区的情况下支持将分区重命名为新名称。
请按照以下步骤操作:

(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start  End    Size   Type     File system   Name       Flags
 1      512B   200MB  200MB  gpt                    oldpart
(parted) name 1 'newpart'
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start  End    Size   Type     File system   Name       Flags
 1      512B   200MB  200MB  gpt                    newpart

使用 parted 创建新分区

以下示例使用 mklabel 命令创建一个新的分区表。
磁盘标签类型必须是以下之一:aix、amiga、bsd、dvh、gpt、mac、msdos、pc98、sun 或者 loop。

# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? Yes

使用 mkpart 子命令创建一个新分区。
我们将创建大小为 200MB 的 ext4 分区。

(parted) mkpart
Partition name?  []? newpart                                             
File system type?  [ext2]? ext4                                          
Start? 0                                                                 
End? 200MB                                                              
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                        
(parted) print                                                          
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End    Size   File system  Name     Flags
 1      17.4kB  200MB  200MB               newpart
(parted)

注意:主分区、逻辑分区和扩展分区是 msdos 分区表的分区类型。
在 gpt 分区表的情况下,分区类型用作分区名称。

欢迎来到之路教程(on itroad-com)

列出分区

要列出现有分区和存储设备,请使用“parted -l”命令。

# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  21.5GB  20.4GB  primary               lvm
 ....

设置分区表类型

使用 mklabel 子命令更改分区表类型。
支持的分区表有:aix、amiga、bsd、dvh、gpt、mac、msdos、pc98、sun、loop。
例如将分区类型更改为 gpt :

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? Yes
日期:2020-09-17 00:14:40 来源:oir作者:oir