一、parted命令格式
用法格式:parted [选项] [设备] [指令]
parted命令分为交互模式和非交互模式,如果没有输入执行,则进入交互模式。
parted操作即刻生效,注意谨慎操作。
1.参数
参数 | 作用 |
---|---|
-h | 显示帮助信息 |
-l | 列出系统所有磁盘的分区情况 |
-s | 脚本模式,关闭交互模式 |
-v | 查看版本 |
2.指令
常用指令 | 作用 |
---|---|
mklabel或mktable | 创建分区表 |
mkpart | 创建分区 |
resizepart | 调整分区大小 |
rm | 删除分区 |
rescue | 恢复丢失的分区 |
name | 给指定的分区命名 |
p | 打印分区信息 |
q | 退出程序 |
h | 帮助信息 |
二、非交互模式的使用
1.创建GPT分区表
[root@work1 ~]# parted /dev/sdb 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
Information: You may need to update /etc/fstab.
[root@work1 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2.创建磁盘分区
[root@work1 ~]# parted /dev/sdb mkpart test01 0% 100MB
Information: You may need to update /etc/fstab.
[root@work1 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 99.6MB 98.6MB xfs test01
3.调整磁盘分区大小
[root@work1 ~]# parted /dev/sdb resizepart 1 200MB
Information: You may need to update /etc/fstab.
[root@work1 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 200MB 199MB xfs test01
4.命名磁盘分区名称
[root@work1 ~]# parted /dev/sdb name 1 test02
[root@work1 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 200MB 199MB xfs test02
5.删除磁盘分区
[root@work1 ~]# parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.
[root@work1 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags