[root@longtestlvm ~]# pvdisplay "/dev/vdc" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name /dev/vdc VG Name PV Size 20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID avPba4-Z0J5-bhWC-4poS-x5oG-qt4P-4xUJnn
"/dev/vdb" is a new physical volume of "20.00 GiB" --- NEW Physical volume --- PV Name /dev/vdb VG Name PV Size 20.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID exRn9W-AQKP-7rTc-EwAf-YtsK-MW0O-HHJ0sk
[root@longtestlvm ~]# vgdisplay --- Volume group --- VG Name vglong System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 0 / 0 Free PE / Size 10238 / 39.99 GiB VG UUID 4flIRX-1oVR-MBy5-I2YT-gY2R-Eqaf-PmFq7b
[root@longtestlvm ~]# lvdisplay --- Logical volume --- LV Path /dev/vglong/lvlong LV Name lvlong VG Name vglong LV UUID x7iFjg-QSem-vzfu-jAkV-V0lI-50P3-tHD3Hz LV Write Access read/write LV Creation host, time longtestlvm, 2021-10-12 14:00:09 +0800 LV Status available # open 0 LV Size 30.00 GiB Current LE 7680 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 252:0
[root@longtestlvm ~]# mkfs.ext4 /dev/vglong/lvlong mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1966080 inodes, 7864320 blocks 393216 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=2155872256 240 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000
Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
挂载磁盘
1 2 3
[root@longtestlvm mnt]# mkdir longtestlvm
[root@longtestlvm mnt]# mount /dev/mapper/vglong-lvlong /mnt/longtestlvm/
[root@longtestlvm ~]# lvextend -L +4G /dev/vglong/lvlong Size of logical volume vglong/lvlong changed from 30.00 GiB (7680 extents) to 34.00 GiB (8704 extents). Logical volume vglong/lvlong successfully resized.
resize逻辑卷
1 2 3 4 5
[root@longtestlvm ~]# resize2fs /dev/vglong/lvlong resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/vglong/lvlong is mounted on /mnt/longtestlvm; on-line resizing required old_desc_blocks = 4, new_desc_blocks = 5 The filesystem on /dev/vglong/lvlong is now 8912896 blocks long.
[root@longtestlvm ~]# resize2fs /dev/vglong/lvlong 10G resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/vglong/lvlong to 2621440 (4k) blocks. The filesystem on /dev/vglong/lvlong is now 2621440 blocks long.
[root@longtestlvm ~]# lvresize -L 10G /dev/vglong/lvlong WARNING: Reducing active logical volume to 10.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vglong/lvlong? [y/n]: y Size of logical volume vglong/lvlong changed from 34.00 GiB (8704 extents) to 10.00 GiB (2560 extents). Logical volume vglong/lvlong successfully resized.
[root@longtestlvm ~]# vgdisplay --- Volume group --- VG Name vglong System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 10 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 2560 / 10.00 GiB Free PE / Size 7678 / 29.99 GiB VG UUID 4flIRX-1oVR-MBy5-I2YT-gY2R-Eqaf-PmFq7b
删除
1 2 3 4 5 6 7 8 9 10 11
[root@longtestlvm ~]# lvremove /dev/vglong/lvlong Do you really want to remove active logical volume vglong/lvlong? [y/n]: y Logical volume "lvlong" successfully removed
[root@longtestlvm ~]# vgremove vglong Volume group "vglong" successfully removed
[root@longtestlvm ~]# pvremove /dev/vdb /dev/vdc /dev/vdd Labels on physical volume "/dev/vdb" successfully wiped. Labels on physical volume "/dev/vdc" successfully wiped. Labels on physical volume "/dev/vdd" successfully wiped.
迁移
1
[root@longtestlvm ~]# pvmove /dev/vdb /dev/vdc
一些其他的内容
disk相关命令 fdisk 、 mkfs 、du 、 df 、dump2fs
一些问题记录
已经将某个物理磁盘加入到 vg 中后,再将该物理盘进行分区
1 2 3 4 5 6 7 8 9
[root@longtestlvm ~]# pvs WARNING: Device for PV cSASFg-dS4S-lrIP-hD3V-aJSR-EnzC-5bYp4B not found or rejected by a filter. Couldn't find device with uuid cSASFg-dS4S-lrIP-hD3V-aJSR-EnzC-5bYp4B. PV VG Fmt Attr PSize PFree /dev/vdb vglong lvm2 a-- <20.00g <20.00g /dev/vdc vglong lvm2 a-- <20.00g <20.00g /dev/vdd1 lvm2 --- 100.00m 100.00m /dev/vdd2 lvm2 --- 100.00m 100.00m [unknown] vglong lvm2 a-m <20.00g <20.00g
解决办法:
1 2 3 4 5 6 7 8 9 10
[root@longtestlvm ~]# vgreduce --removemissing vglong --force Volume group "vglong" is already consistent.