yum provides "/*/pvcreate" #根据命令pvcreate搜索软件包 yum install -y lvm2 #安装lvm工具 partprobe #更新分区表 vgremove #删除卷组 pvcreate #创建物理卷 pvs 或者 pvdisplay #查看物理卷 vgcreate #创建卷组 vgs 或者 vgdisplay #查看卷组 lvcreate #创建逻辑卷 lvs 或者 lvdisplay #查看逻辑卷 lvresize -L #扩容逻辑卷指定逻辑卷的大小 e2fsck -f #检查磁盘错误 r esize2fs #更新磁盘信息 xfs_growfs #XFS文件系统更新磁盘信息 vgextend #扩容卷组
PV(physical volume)即物理卷,就是物理磁盘,可以通过fdisk -l 查看操作系统有几块硬盘
VG(volume group)即卷组,就是一组物理磁盘的组合,里面可以有一块硬盘也可以有多块硬盘
LV(logical volume)及逻辑卷,就是在VG(指定的物理磁盘组)里面划分出来的
可以说成是PV就是硬盘,而VG就是管理硬盘的操作系统,而LV就是操作系统分出来的各个分区.
PV->VG->LV-> 文件系统使用(挂载到某个目录)
1.PV pvcreate :根据物理盘,创建pv pvscan :查询目前系统里的pv pvdisplay:显示pv的状态 pvremove:将pv属性移除 2.VG vgcreate:创建vg vgscan:查找当前系统里面的vg vgdisplay:显示当前系统vg的状态 vgextend:给vg添加额外的pv vgreduce:在vg内删除pv vgchange:设置vg是否是启动状态(active) vgremove:删除一个vg 3.LV lvcreate:创建lv lvscan:查询当前系统的lv lvdisplay:显示lv的属性 lvextend:给lv添加容量 lvredurce:给lv减少容量 lvremove:删除一个lv lvresize:对lv大小的容量进行调整
下面用一个实例进行相关的说明
1、查看目前机器中的物理卷
root@pve107:/dev/mapper# pvdisplay --- Physical volume --- PV Name /dev/nvme0n1p3 VG Name pve PV Size 1.09 TiB / not usable <4.57 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 286031 Free PE 0 Allocated PE 286031 PV UUID OnFbfV-nlH5-9FHZ-yQbg-Ed3s-IYMA-pcwEkP --- Physical volume --- PV Name /dev/sda1 VG Name pve PV Size <1.82 TiB / not usable <4.09 MiB Allocatable yes PE Size 4.00 MiB Total PE 476931 Free PE 198401 Allocated PE 278530 PV UUID OlKxiJ-a9xY-Z9B7-PsJ7-uGWP-jFL3-C1Xhjj
2、查看对应的卷组
root@pve107:/dev/mapper# vgdisplay --- Volume group --- VG Name pve System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 11 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 2.91 TiB PE Size 4.00 MiB Total PE 762962 Alloc PE / Size 564561 / 2.15 TiB Free PE / Size 198401 / 775.00 GiB VG UUID xh2x4j-B6OA-4HoT-WbfG-Y3yk-yd4r-XNEWsu
3、查看目前分区情况
root@pve107:/dev/mapper# lvdisplay --- Logical volume --- LV Path /dev/pve/swap LV Name swap VG Name pve LV UUID F8FfzL-2vPa-xxxxfd-meHS-NgpQe7 LV Write Access read/write LV Creation host, time proxmox, 2020-10-14 18:17:59 +0800 LV Status available # open 2 LV Size 8.00 GiB Current LE 2048 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/pve/root LV Name root VG Name pve LV UUID cm1sAU-nLD9-ZxxxFn-1YGU-mkXg-t4SNGx LV Write Access read/write LV Creation host, time proxmox, 2020-10-14 18:17:59 +0800 LV Status available # open 1 LV Size 1.17 TiB Current LE 307200 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Name data VG Name pve LV UUID tGoJcb-Tb5s-lCxxxx1il8-RCY0-VoANVw LV Write Access read/write LV Creation host, time proxmox, 2020-10-14 18:17:59 +0800 LV Pool metadata data_tmeta LV Pool data data_tdata LV Status available # open 0 LV Size 977.36 GiB Allocated pool data 0.00% Allocated metadata 0.20% Current LE 250205 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:4
4、查看目前系统磁盘空间占用情况
root@pve107:/dev/mapper# df -h Filesystem Size Used Avail Use% Mounted on udev 63G 0 63G 0% /dev tmpfs 13G 1.4G 12G 11% /run /dev/mapper/pve-root 1.2T 94G 1.1T 9% / tmpfs 63G 49M 63G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 63G 0 63G 0% /sys/fs/cgroup /dev/nvme0n1p2 511M 312K 511M 1% /boot/efi /dev/fuse 30M 16K 30M 1% /etc/pve tmpfs 13G 0 13G 0% /run/user/0
5、 创建pv
root@pve107:/dev/mapper# pvcreate /dev/sde1 WARNING: ext4 signature detected on /dev/sde1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sde1. Physical volume "/dev/sde1" successfully created.
root@pve107:/dev/mapper# pvdisplay
--- Physical volume ---
PV Name /dev/nvme0n1p3
VG Name pve
PV Size 1.09 TiB / not usable <4.57 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 286031
Free PE 0
Allocated PE 286031
PV UUID OnFbfV-nlH5-9xxxxx-Ed3s-IYMA-pcwEkP
--- Physical volume ---
PV Name /dev/sda1
VG Name pve
PV Size <1.82 TiB / not usable <4.09 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 476931
Free PE 198401
Allocated PE 278530
PV UUID OlKxiJ-a9xY-xxxxsJ7-uGWP-jFL3-C1Xhjj
"/dev/sde1" is a new physical volume of "1.00 TiB"
--- NEW Physical volume --- (新创建的)
PV Name /dev/sde1
VG Name
PV Size 1.00 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID FUe3oA-Rhch-qASr-xxxx-ICOx-SPm5-qplsHk
可以看到标红的为新创建的
root@pve107:/dev/mapper# pvscan PV /dev/nvme0n1p3 VG pve lvm2 [1.09 TiB / 0 free] PV /dev/sda1 VG pve lvm2 [<1.82 TiB / 775.00 GiB free] PV /dev/sde1 lvm2 [1.00 TiB] Total: 3 [3.91 TiB] / in use: 2 [2.91 TiB] / in no VG: 1 [1.00 TiB]
6、创建vg
root@pve107:/dev/mapper# vgcreate kycx-data /dev/sde1 Volume group "kycx-data" successfully created root@pve107:/dev/mapper# vgdisplay --- Volume group --- VG Name kycx-data (新添加的) 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 <1024.00 GiB PE Size 4.00 MiB Total PE 262143 Alloc PE / Size 0 / 0 Free PE / Size 262143 / <1024.00 GiB VG UUID J6RHFO-xz3S-xxxxOk-6yOe-YRvr-p9Pk5Q --- Volume group --- VG Name pve System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 11 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 2.91 TiB PE Size 4.00 MiB Total PE 762962 Alloc PE / Size 564561 / 2.15 TiB Free PE / Size 198401 / 775.00 GiB VG UUID xh2x4j-BxxxxWbfG-Y3yk-yd4r-XNEWsu
root@pve107:/dev/mapper# pvscan
PV /dev/sde1 VG kycx-data lvm2 [<1024.00 GiB / <1024.00 GiB free]
PV /dev/nvme0n1p3 VG pve lvm2 [1.09 TiB / 0 free]
PV /dev/sda1 VG pve lvm2 [<1.82 TiB / 775.00 GiB free]
Total: 3 [3.91 TiB] / in use: 3 [3.91 TiB] / in no VG: 0 [0 ]
7、给新建的vg 扩容
root@pve107:/dev/mapper# pvcreate /dev/sdb1 WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: WARNING: Invalid input ‘‘. WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created. root@pve107:/dev/mapper# pvscan PV /dev/sde1 VG kycx-data lvm2 [<1024.00 GiB / <1024.00 GiB free] PV /dev/nvme0n1p3 VG pve lvm2 [1.09 TiB / 0 free] PV /dev/sda1 VG pve lvm2 [<1.82 TiB / 775.00 GiB free] PV /dev/sdb1 lvm2 [<1.82 TiB] Total: 4 [<5.73 TiB] / in use: 3 [3.91 TiB] / in no VG: 1 [<1.82 TiB] root@pve107:/dev/mapper# vgextend kycx-data /dev/sdb1 Volume group "kycx-data" successfully extended root@pve107:/dev/mapper# vgdisplay kycx-data --- Volume group --- VG Name kycx-data System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size <2.82 TiB (发现vg的容量变大) PE Size 4.00 MiB Total PE 739074 Alloc PE / Size 0 / 0 Free PE / Size 739074 / <2.82 TiB VG UUID J6RHFO-xz3S-Vsqxxxxvr-p9Pk5Q
8、创建lv 并挂载
root@pve107:/dev/mapper# lvscan ACTIVE ‘/dev/pve/swap‘ [8.00 GiB] inherit ACTIVE ‘/dev/pve/root‘ [1.17 TiB] inherit ACTIVE ‘/dev/pve/data‘ [977.36 GiB] inherit root@pve107:/dev/mapper# lvcreate -n kycx-test -L 2000G kycx-data Logical volume "kycx-test" created. root@pve107:/dev/mapper# lvscan ACTIVE ‘/dev/kycx-data/kycx-test‘ [1.95 TiB] inherit ACTIVE ‘/dev/pve/swap‘ [8.00 GiB] inherit ACTIVE ‘/dev/pve/root‘ [1.17 TiB] inherit ACTIVE ‘/dev/pve/data‘ [977.36 GiB] inherit root@pve107:/dev/mapper#
9、创建目录 对逻辑卷进行挂载
root@pve107:~# mkdir kycx-dir107 root@pve107:~# mkfs -t ext4 /dev/kycx-data/kycx-test mke2fs 1.44.5 (15-Dec-2018) Creating filesystem with 524288000 4k blocks and 131072000 inodes Filesystem UUID: 1e0ce787-5d83-4616-82d2-0906438e7d54 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000 Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting info root@pve107:~/kycx-dir107# mount /dev/kycx-data/kycx-test /root/kycx-dir107 root@pve107:~/kycx-dir107# df -h Filesystem Size Used Avail Use% Mounted on udev 63G 0 63G 0% /dev tmpfs 13G 1.4G 12G 11% /run /dev/mapper/pve-root 1.2T 94G 1.1T 9% / tmpfs 63G 52M 63G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 63G 0 63G 0% /sys/fs/cgroup /dev/nvme0n1p2 511M 312K 511M 1% /boot/efi /dev/fuse 30M 16K 30M 1% /etc/pve tmpfs 13G 0 13G 0% /run/user/0 /dev/mapper/kycx--data-kycx--test 2.0T 81M 1.9T 1% /root/kycx-dir107
10、删除逻辑卷
root@pve107:~# lvremove -f /dev/kycx-data/kycx-test Logical volume kycx-data/kycx-test contains a filesystem in use. -- 因为挂载了目录所以需要要解除挂载 umount /dev/kycx-data/kycx-test root@pve107:~# lvremove -f /dev/kycx-data/kycx-test Logical volume "kycx-test" successfully removed
root@pve107:~# lvdisplay --- Logical volume --- LV Path /dev/pve/swap LV Name swap VG Name pve LV UUID F8FfzL-2vPa-TuiB-0j6v-qwfd-meHS-NgpQe7 LV Write Access read/write LV Creation host, time proxmox, 2020-10-14 18:17:59 +0800 LV Status available # open 2 LV Size 8.00 GiB Current LE 2048 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/pve/root LV Name root VG Name pve LV UUID cm1sAU-nLD9-Zobj-7SFn-1YGU-mkXg-t4SNGx LV Write Access read/write LV Creation host, time proxmox, 2020-10-14 18:17:59 +0800 LV Status available # open 1 LV Size 1.17 TiB Current LE 307200 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Name data VG Name pve LV UUID tGoJcb-Tb5s-lCn5-3GsT-1il8-RCY0-VoANVw LV Write Access read/write LV Creation host, time proxmox, 2020-10-14 18:17:59 +0800 LV Pool metadata data_tmeta LV Pool data data_tdata LV Status available # open 0 LV Size 977.36 GiB Allocated pool data 0.00% Allocated metadata 0.20% Current LE 250205 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:4 #新创建的 lv 被删除
11、删除 卷组
root@pve107:~# vgremove /dev/kycx-data Volume group "kycx-data" successfully removed root@pve107:~# vgdisplay --- Volume group --- VG Name pve System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 11 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 2.91 TiB PE Size 4.00 MiB Total PE 762962 Alloc PE / Size 564561 / 2.15 TiB Free PE / Size 198401 / 775.00 GiB VG UUID xh2x4j-B6OA-4HoT-WbfG-Y3yk-yd4r-XNEWsu