(parted) mkpart xfs 2048s 100%
(parted)
其中不需要指明分区类型是主分区还是逻辑分区,GPT分区只有一种分区格式,如果是msdos(mbr)才需要指明。可以使用 rm 分区号 命令删除分区,使用 quit 命令退出当前分区模式,至此parted命令进行GPT分区已完成;格式化分区和挂载分区与上面fdisk分区中的方式一样。
七、使用逻辑卷
首先我们需要将物理设备(可以是物理磁盘/dev/sdb、也可以是物理分区/dev/sdb1)格式化为PV(物理卷),在此我们使用 parted -l 命令查看我们有哪些可供使用的物理设备:
[root@localnat201 ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1049kB 1075MB 1074MB primary xfs 启动
2 1075MB 32.2GB 31.1GB primary lvm
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 标志
1 1049kB 21.5GB 21.5GB xfs
错误: /dev/sdc: unrecognised disk label
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/cl-swap: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 2147MB 2147MB linux-swap(v1)
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/cl-root: 29.0GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 29.0GB 29.0GB xfs
这里我们抛开已经做过分区和已经存在的物理卷的一些设备,其中/dev/sdb和/dev/sdc这两个物理磁盘是需要我们关注的。我们可以看到/dev/sdb这块磁盘已经有了一个分区,分区号是1也就是/dev/sdb1分区(gpt分区表只展示分区号,只要将磁盘名称拼上分区号就是分区名称),而/dev/sdc磁盘并没有做过分区。所以我们首先需要使用 pvcreate 命令将/dev/sdb1和/dev/sdc格式化成PV:
[root@localnat201 ~]# pvcreate /dev/sdb1 /dev/sdc
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdc" successfully created.
[root@localnat201 ~]#
这里可以看到创建成功了,其中pvcreate是创建命令,后面参数是需要初始化的物理设备,多个设备之间使用空格分隔。我们可以使用 pvdisplay 命令或者 pvs 命令查看已经存在的PV信息:
[root@localnat201 ~]# pvcreate /dev/sdb1 /dev/sdc
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdc" successfully created.
[root@localnat201 ~]# clear
[root@localnat201 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name cl
PV Size <29.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 7423
Free PE 1
Allocated PE 7422
PV UUID KdNi7s-YftA-YY9W-hK7a-PHw1-j7n2-ln4cLg
"/dev/sdc" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID AbmsNB-2NUK-IxJA-QYY7-N81f-avOz-wyMKiR
"/dev/sdb1" is a new physical volume of "<20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID sts9D4-P47z-Qrj2-WaWX-9wEU-o8jo-Y70xgb
[root@localnat201 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <29.00g 4.00m
/dev/sdb1 lvm2 --- <20.00g <20.00g
/dev/sdc lvm2 --- 20.00g 20.00g
如果有需要我们也可以使用 pvremove 命令删除物理卷:
[root@localnat201 ~]# pvremove /dev/sdc
Labels on physical volume "/dev/sdc" successfully wiped.
[root@localnat201 ~]#