Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present
Creating new GPT entries.
# 查看交互式菜单 Command (? forhelp): ? b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu
# 查看 LVM 磁盘分区ID:8e00 Command (? forhelp): l 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM # LVM ID a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS a585 Midnight BSD Vinum a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS a903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+ af01 Apple RAID af02 Apple RAID offline af03 Apple label af04 AppleTV recovery af05 Apple Core Storage be00 Solaris boot 00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2 bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5 c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p fd00 Linux RAID
Press the <Enter> key to see more codes: q
# 创建 LVM 磁盘分区,这块100G的数据盘只分1个区。 Command (? forhelp): n Partition number (1-128, default 1): First sector (34-209715166, default = 2048) or {+-}size{KMGTP}: Last sector (2048-209715166, default = 209715166) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): 8e00 # LVM ID Changed type of partition to 'Linux LVM'
Command (? forhelp): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully.
# 查看挂载盘分区 $ lsblk /dev/sdb NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part
2.开始创建 LVM
对 /dev/sdb1 分区创建 PV
2.1创建 PV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ pvcreate /dev/sdb1 WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created.
# 查看 PV $ pvdisplay /dev/sdb1 "/dev/sdb1" is a new physical volume of "<100.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 # PV 名称 VG Name # 目前并没有属于任何一个 VG PV Size <100.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID JI5A2a-t1QI-reDu-xcjN-LYww-2vEV-JztpeD
$ vgcreate -s 16M data_vg /dev/sdb1 Volume group "data_vg" successfully created
# 查看 VG $ vgdisplay data_vg --- Volume group --- VG Name data_vg # VG 名称 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 99.98 GiB PE Size 16.00 MiB # 单个 PE 大小 Total PE 6399 # PE 总数量 Alloc PE / Size 0 / 0 # 已分配的 PE 数量,目前并没有分配 Free PE / Size 6399 / 99.98 GiB # 未分配的 PE 数量 VG UUID n0ptd5-HvHG-nx2c-3xCh-lXyZ-VILG-V2pwJB
2.3 创建 LV:
-n:LV 的名称
-l:后面可以接 PE 的个数,通过 vgdisplay 查看未分配的 PE 数量来指定。
-L:后面接容量,单位可以是 M,G,T 等,要注意的是,最小单位为 PE,因此这个数量必须要是 PE 的倍数,若不相符,系统会自行计算最相近的容量。
# # /etc/fstab # Created by anaconda on Mon Aug 29 06:28:22 2022 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/myvg-root / xfs defaults 0 0 UUID=393c612c-13ed-41ce-b368-90465a19be08 /boot xfs defaults 0 0 UUID=16ba12c1-be58-485f-bbbb-62ea9facd1ff /data xfs defaults 0 0
$ lvremove /dev/mapper/data_vg-data_lv Do you really want to remove active logical volume data_vg/data_lv? [y/n]: y Logical volume "data_lv" successfully removed #移除 VG
Partition table scan: MBR: protective BSD: not present APM: not present GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? forhelp): ? b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu
Command (? forhelp): t Partition number (1-2): 1 Current type is 'Linux LVM' Hex code or GUID (L to show codes, Enter = 8300): # 默认值 Changed type of partition to 'Linux filesystem'
Command (? forhelp): t Partition number (1-2): 2 Current type is 'Linux LVM' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem'
Command (? forhelp): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully.
Partition table scan: MBR: protective BSD: not present APM: not present GPT: present
Found valid GPT with protective MBR; using GPT.
# 先查看下当前磁盘的分区 Command (? forhelp): p Disk /dev/sdb: 419430400 sectors, 200.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 8F764B92-2199-492F-A3F4-6A90CEF70C05 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 419430366 Partitions will be aligned on 2048-sector boundaries Total free space is 209717214 sectors (100.0 GiB)
Number Start (sector) End (sector) Size Code Name 1 2048 209715166 100.0 GiB 8E00 Linux LVM # 仅有一个分区1
# 创建新分区 Command (? forhelp): n Partition number (2-128, default 2): # 分区编号,默认 First sector (34-419430366, default = 209715200) or {+-}size{KMGTP}: # 起始扇区,默认从未分区部分的首部开始 Last sector (209715200-419430366, default = 419430366) or {+-}size{KMGTP}: # 结束扇区,默认到未分区部分的尾部 Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): 8e00 # 分区 ID :8e00 是 LVM 格式分区 ID Changed type of partition to 'Linux LVM'
# 保存写入分区表 Command (? forhelp): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot. The operation has completed successfully.
# 先查看操作系统下有哪些 VG $ vgscan Reading volume groups from cache. Found volume group "data_vg" using metadata type lvm2 # 将要扩容的 VG Found volume group "myvg" using metadata type lvm2
# 查看 VG $ vgdisplay data_vg --- Volume group --- VG Name data_vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 # PV 数量增加了 Act PV 2 VG Size <199.97 GiB # VG 总容量增加了 PE Size 16.00 MiB Total PE 12798 Alloc PE / Size 6399 / 99.98 GiB Free PE / Size 6399 / 99.98 GiB # 未分配的 PE 数量增加了 VG UUID n0ptd5-HvHG-nx2c-3xCh-lXyZ-VILG-V2pwJB