
关于逻辑卷的处理主要包括如下的几个概念:
PV是指实际的物理卷,但每个物理卷由一定数量的PE构成,PE通常为4M大小,因此PV的大小通常都是4M的整数倍。
VG是虚拟卷组,每个VG创建时由一系列的物理PV构成,实际上VG中是由所有PV中的PE构成,也VG也称为是PE池。
LV实际上是在VG之上的实现,LVM实际是从VG(PE池)中取出一定数量的PE构成逻辑卷,每个PE实际上只归属一个LVM。
由以上的分析可知,逻辑卷的实现实际上只是在实际磁盘和逻辑卷之间添加了一个中间层,通过中间层实现对物理资源的软件分配。逻辑卷的大小是可以调整的。但需要注意只是卷调整是无意义的,还要调整文件系统的大小。
PV1 ... PVn
|
VG(实现对PV中PE资源的软件管理)
/ | \
LV0 LV1 LV2
客户端使用LVM过程中并没有PV、PE、VG这些概念,对于客户端而言只有LVM。因此PV、VG、PE是逻辑卷内部的概念。关于逻辑卷的管理还是需要三步处理:
创建物理卷, 采用pvcreate创建,可通过pvdisplay查看pv的信息。
创建虚拟卷组,采用命令vgcreate创建,可通过vgdisplay查看vg的信息。
最后是创建逻辑卷,采用lvcreate创建,可通过lvdisplay查看逻辑卷的信息。
通过逻辑卷的处理能较好的实现磁盘的动态扩展,相比传统的分区磁盘管理要方便不少。
点击(此处)折叠或打开
- [root@Gong-Computer ~]# pvcreate /dev/sdd
- Physical volume "/dev/sdd" successfully created
- [root@Gong-Computer ~]# pvcreate /dev/sde
- Physical volume "/dev/sde" successfully created
- [root@Gong-Computer ~]# pvscan
- PV /dev/sdd lvm2 [8.00 GiB]
- PV /dev/sde lvm2 [8.00 GiB]
- Total: 2 [16.00 GiB] / in use: 0 [0 ] / in no VG: 2 [16.00 GiB]
- [root@Gong-Computer ~]# pvdisplay --没有添加到vg时无pe信息
- "/dev/sdd" is a new physical volume of "8.00 GiB"
- --- NEW Physical volume ---
- PV Name /dev/sdd
- VG Name
- PV Size 8.00 GiB
- Allocatable NO
- PE Size 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID Bxqi5f-aDvN-RaYW-CJQa-2PbH-VvMF-umrTAM
- "/dev/sde" is a new physical volume of "8.00 GiB"
- --- NEW Physical volume ---
- PV Name /dev/sde
- VG Name
- PV Size 8.00 GiB
- Allocatable NO
- PE Size 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID p00Ba0-iWBb-oVhZ-kwiy-yXEc-khNX-sKkazU
- [root@Gong-Computer ~]# vgcreate mylvmvg /dev/sdd /dev/sde --创建VG
- Volume group "mylvmvg" successfully created
- [root@Gong-Computer ~]# vgdisplay ---查看VG
- --- Volume group ---
- VG Name mylvmvg
- 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 15.99 GiB
- PE Size 4.00 MiB
- Total PE 4094
- Alloc PE / Size 0 / 0
- Free PE / Size 4094 / 15.99 GiB
- VG UUID T11gb0-MYs3-Yvym-4bVz-8ABy-8DlF-H1hS3V
- [root@Gong-Computer ~]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sdd
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 2047 ----添加到VG后,存在PE的信息
- Free PE 2047
- Allocated PE 0
- PV UUID Bxqi5f-aDvN-RaYW-CJQa-2PbH-VvMF-umrTAM
- --- Physical volume ---
- PV Name /dev/sde
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 2047
- Free PE 2047
- Allocated PE 0
- PV UUID p00Ba0-iWBb-oVhZ-kwiy-yXEc-khNX-sKkazU
- [root@Gong-Computer ~]# lvcreate -L 2G mylvmvg ---创建逻辑卷
- Logical volume "lvol0" created
- [root@Gong-Computer ~]# lvcreate -L 2G mylvmvg
- Logical volume "lvol1" created
- [root@Gong-Computer ~]# lvcreate -L 2G mylvmvg
- Logical volume "lvol2" created
- [root@Gong-Computer ~]# lvdisplay
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol0
- VG Name mylvmvg
- LV UUID 5EmUJa-E4QB-OcQ6-uAuE-QXls-0dYQ-1OfZjm
- LV Write Access read/write
- LV Status available
- # open 1
- LV Size 2.00 GiB
- Current LE 512
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:0
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol1
- VG Name mylvmvg
- LV UUID ZEC6l3-y6GT-xRVf-8I7T-z7v3-KEgu-6yHsPS
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 2.00 GiB
- Current LE 512
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:1
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol2
- VG Name mylvmvg
- LV UUID xk1AMT-iHEj-TnLB-DLD0-AIoD-BSQa-NXZ7UV
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 2.00 GiB
- Current LE 512
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:2
- [root@Gong-Computer ~]# ll /dev/mylvmvg/ --新创建的卷是一个软连接对象
- total 0
- lrwxrwxrwx 1 root root 7 Sep 7 22:48 lvol0 -> ../dm-0
- lrwxrwxrwx 1 root root 7 Sep 7 23:03 lvol1 -> ../dm-1
- lrwxrwxrwx 1 root root 7 Sep 7 23:03 lvol2 -> ../dm-2
- [root@Gong-Computer ~]# ll /dev/d
- [root@Gong-Computer ~]# mkfs.ext3 /dev/mylvmvg/lvol0 ---格式化创建好的逻辑卷,格式化之后可以进行逻辑卷的使用
- mke2fs 1.41.12 (17-May-2010)
- Filesystem label=
- OS type: Linux
- Block size=4096 (log=2)
- Fragment size=4096 (log=2)
- Stride=0 blocks, Stripe width=0 blocks
- 131072 inodes, 524288 blocks
- 26214 blocks (5.00%) reserved for the super user
- First data block=0
- Maximum filesystem blocks=536870912
- 16 block groups
- 32768 blocks per group, 32768 fragments per group
- 8192 inodes per group
- Superblock backups stored on blocks:
- 32768, 98304, 163840, 229376, 294912
- Writing inode tables: done
- Creating journal (16384 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 27 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- [root@Gong-Computer ~]# mount /dev/mylvmvg/lvol0 /mnt/nfs/ ----挂载文件
- [root@Gong-Computer ~]# ll /mnt/nfs/
- total 16
- drwx------ 2 root root 16384 Sep 7 22:48 lost+found
- [root@Gong-Computer ~]# lvextend -L +1G /dev/mylvmvg/lvol0 ---扩展逻辑卷大小
- Extending logical volume lvol0 to 3.00 GiB
- Logical volume lvol0 successfully resized
- [root@Gong-Computer ~]# resize2fs -f /dev/mylvmvg/lvol0 ---调整文件系统的大小
- resize2fs 1.41.12 (17-May-2010)
- Resizing the filesystem on /dev/mylvmvg/lvol0 to 786432 (4k) blocks.
- The filesystem on /dev/mylvmvg/lvol0 is now 786432 blocks long.
- [root@Gong-Computer ~]# lvextend -L +1G /dev/mylvmvg/lvol0
- Extending logical volume lvol0 to 4.00 GiB
- Logical volume lvol0 successfully resized
- [root@Gong-Computer ~]# resize2fs -f /dev/mylvmvg/lvol0
- resize2fs 1.41.12 (17-May-2010)
- Filesystem at /dev/mylvmvg/lvol0 is mounted on /mnt/nfs; on-line resizing required
- old desc_blocks = 1, new_desc_blocks = 1
- Performing an on-line resize of /dev/mylvmvg/lvol0 to 1048576 (4k) blocks.
- The filesystem on /dev/mylvmvg/lvol0 is now 1048576 blocks long.
- [root@Gong-Computer ~]# df
- Filesystem 1K-blocks Used Available Use% Mounted on
- /dev/sda1 20158332 2937880 16196452 16% /
- tmpfs 177736 272 177464 1% /dev/shm
- /dev/sda2 15118728 9544700 4806028 67% /opt
- /dev/sda5 14262192 9214364 4323348 69% /usr
- /dev/sdb1 2086912 32928 2053984 2% /mnt/sdb1
- /dev/sdb2 2064208 3072 1956280 1% /mnt/sdb2
- /dev/sdc1 3844848 73244 3576296 3% /mnt/sdc1
- /dev/sdc2 1942528 32928 1909600 2% /mnt/sdc2
- .host:/ 252926972 119266328 133660644 48% /mnt/hgfs
- /dev/mapper/mylvmvg-lvol0
- 4128448 69692 3849056 2% /mnt/nfs ---实际的逻辑卷文件
- [root@Gong-Computer ~]# vgdisplay
- --- Volume group ---
- VG Name mylvmvg
- System ID
- Format lvm2
- Metadata Areas 2
- Metadata Sequence No 6
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 3
- Open LV 1
- Max PV 0
- Cur PV 2
- Act PV 2
- VG Size 15.99 GiB
- PE Size 4.00 MiB
- Total PE 4094
- Alloc PE / Size 2048 / 8.00 GiB
- Free PE / Size 2046 / 7.99 GiB
- VG UUID T11gb0-MYs3-Yvym-4bVz-8ABy-8DlF-H1hS3V
- [root@Gong-Computer ~]#
- [root@Gong-Computer ~]#
- [root@Gong-Computer ~]# lvextend -L +2G /dev/mylvmvg/lvol0 ---改变了卷的大小
- Extending logical volume lvol0 to 6.00 GiB
- Logical volume lvol0 successfully resized
- [root@Gong-Computer ~]# df ---文件系统的大小未改变
- Filesystem 1K-blocks Used Available Use% Mounted on
- /dev/sda1 20158332 2937884 16196448 16% /
- tmpfs 177736 272 177464 1% /dev/shm
- /dev/sda2 15118728 9544700 4806028 67% /opt
- /dev/sda5 14262192 9214364 4323348 69% /usr
- /dev/sdb1 2086912 32928 2053984 2% /mnt/sdb1
- /dev/sdb2 2064208 3072 1956280 1% /mnt/sdb2
- /dev/sdc1 3844848 73244 3576296 3% /mnt/sdc1
- /dev/sdc2 1942528 32928 1909600 2% /mnt/sdc2
- .host:/ 252926972 119266328 133660644 48% /mnt/hgfs
- /dev/mapper/mylvmvg-lvol0
- 4128448 69692 3849056 2% /mnt/nfs
- [root@Gong-Computer ~]# resize2fs -f /dev/mylvmvg/lvol0 ---更改文件系统的大小
- resize2fs 1.41.12 (17-May-2010)
- Filesystem at /dev/mylvmvg/lvol0 is mounted on /mnt/nfs; on-line resizing required
- old desc_blocks = 1, new_desc_blocks = 1
- Performing an on-line resize of /dev/mylvmvg/lvol0 to 1572864 (4k) blocks.
- The filesystem on /dev/mylvmvg/lvol0 is now 1572864 blocks long.
- [root@Gong-Computer ~]# pvcreate /dev/sdf --- 创建新的pv
- Physical volume "/dev/sdf" successfully created
- [root@Gong-Computer ~]# vgextend mylvmvg /dev/sdf ---扩展vg
- Volume group "mylvmvg" successfully extended
- [root@Gong-Computer ~]# vgdisplay
- --- Volume group ---
- VG Name mylvmvg
- System ID
- Format lvm2
- Metadata Areas 3
- Metadata Sequence No 8
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 3
- Open LV 1
- Max PV 0
- Cur PV 3
- Act PV 3
- VG Size 23.99 GiB
- PE Size 4.00 MiB
- Total PE 6141
- Alloc PE / Size 2560 / 10.00 GiB
- Free PE / Size 3581 / 13.99 GiB
- VG UUID T11gb0-MYs3-Yvym-4bVz-8ABy-8DlF-H1hS3V
- [root@Gong-Computer ~]# lvextend -L +2G /dev/mylvmvg/lvol0
- Extending logical volume lvol0 to 8.00 GiB
- Logical volume lvol0 successfully resized
- [root@Gong-Computer ~]# resize2fs -f /dev/mylvmvg/lvol0
- resize2fs 1.41.12 (17-May-2010)
- Filesystem at /dev/mylvmvg/lvol0 is mounted on /mnt/nfs; on-line resizing required
- old desc_blocks = 1, new_desc_blocks = 1
- Performing an on-line resize of /dev/mylvmvg/lvol0 to 2097152 (4k) blocks.
- The filesystem on /dev/mylvmvg/lvol0 is now 2097152 blocks long.
- [root@Gong-Computer ~]# df
- Filesystem 1K-blocks Used Available Use% Mounted on
- /dev/sda1 20158332 2937892 16196440 16% /
- tmpfs 177736 272 177464 1% /dev/shm
- /dev/sda2 15118728 9544700 4806028 67% /opt
- /dev/sda5 14262192 9214364 4323348 69% /usr
- /dev/sdb1 2086912 32928 2053984 2% /mnt/sdb1
- /dev/sdb2 2064208 3072 1956280 1% /mnt/sdb2
- /dev/sdc1 3844848 73244 3576296 3% /mnt/sdc1
- /dev/sdc2 1942528 32928 1909600 2% /mnt/sdc2
- .host:/ 252926972 119274456 133652516 48% /mnt/hgfs
- /dev/mapper/mylvmvg-lvol0
- 8256952 70200 7767388 1% /mnt/nfs
- [root@Gong-Computer ~]#
- [root@Gong-Computer ~]# vgdisplay
- --- Volume group ---
- VG Name mylvmvg
- System ID
- Format lvm2
- Metadata Areas 3
- Metadata Sequence No 9
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 3
- Open LV 1
- Max PV 0
- Cur PV 3
- Act PV 3
- VG Size 23.99 GiB
- PE Size 4.00 MiB
- Total PE 6141
- Alloc PE / Size 3072 / 12.00 GiB
- Free PE / Size 3069 / 11.99 GiB
- VG UUID T11gb0-MYs3-Yvym-4bVz-8ABy-8DlF-H1hS3V
- [root@Gong-Computer ~]# lvdisplay
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol0
- VG Name mylvmvg
- LV UUID 5EmUJa-E4QB-OcQ6-uAuE-QXls-0dYQ-1OfZjm
- LV Write Access read/write
- LV Status available
- # open 1
- LV Size 8.00 GiB
- Current LE 2048
- Segments 3
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:0
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol1
- VG Name mylvmvg
- LV UUID ZEC6l3-y6GT-xRVf-8I7T-z7v3-KEgu-6yHsPS
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 2.00 GiB
- Current LE 512
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:1
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol2
- VG Name mylvmvg
- LV UUID xk1AMT-iHEj-TnLB-DLD0-AIoD-BSQa-NXZ7UV
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 2.00 GiB
- Current LE 512
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:2
- [root@Gong-Computer ~]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sdd
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes (but full)
- PE Size 4.00 MiB
- Total PE 2047
- Free PE 0
- Allocated PE 2047
- PV UUID Bxqi5f-aDvN-RaYW-CJQa-2PbH-VvMF-umrTAM
- --- Physical volume ---
- PV Name /dev/sde
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 2047
- Free PE 1022
- Allocated PE 1025
- PV UUID p00Ba0-iWBb-oVhZ-kwiy-yXEc-khNX-sKkazU
- --- Physical volume ---
- PV Name /dev/sdf
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 2047
- Free PE 2047
- Allocated PE 0
- PV UUID lh0ZmH-5pta-2k2c-DqyR-r3D5-MLbA-fyfF2j
- 通过上述的操作就实现了逻辑卷的管理,实现了文件系统的动态扩展,这是磁盘分区无法完成的任务。
- 删除逻辑卷的处理按照相反的操作进行。
- [root@Gong-Computer ~]# umount /mnt/nfs/
- [root@Gong-Computer ~]# lvremove /dev/mylvmvg/lvol0 --删除逻辑卷
- Can't remove open logical volume "lvol0"
- [root@Gong-Computer ~]# lvremove /dev/mylvmvg/lvol0
- Do you really want to remove active logical volume lvol0? [y/n]: y
- Logical volume "lvol0" successfully removed
- [root@Gong-Computer ~]#
- [root@Gong-Computer ~]# lvremove /dev/mylvmvg/lvol1
- Can't remove open logical volume "lvol1"
- [root@Gong-Computer ~]# lvremove /dev/mylvmvg/lvol2
- Do you really want to remove active logical volume lvol2? [y/n]: y
- Logical volume "lvol2" successfully removed
- [root@Gong-Computer ~]# vgreduce mylvmvg /dev/sdf ---减少vg中的pv
- Removed "/dev/sdf" from volume group "mylvmvg"
- [root@Gong-Computer ~]# vgscan
- Reading all physical volumes. This may take a while...
- Found volume group "mylvmvg" using metadata type lvm2
- [root@Gong-Computer ~]# vgdisplay
- --- Volume group ---
- VG Name mylvmvg
- System ID
- Format lvm2
- Metadata Areas 2
- Metadata Sequence No 12
- 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 15.99 GiB
- PE Size 4.00 MiB
- Total PE 4094
- Alloc PE / Size 512 / 2.00 GiB
- Free PE / Size 3582 / 13.99 GiB
- VG UUID T11gb0-MYs3-Yvym-4bVz-8ABy-8DlF-H1hS3V
- [root@Gong-Computer ~]# pvremove /dev/sdf --删除pv
- Labels on physical volume "/dev/sdf" successfully wiped
- [root@Gong-Computer ~]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sdd
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 2047
- Free PE 1535
- Allocated PE 512
- PV UUID Bxqi5f-aDvN-RaYW-CJQa-2PbH-VvMF-umrTAM
- --- Physical volume ---
- PV Name /dev/sde
- VG Name mylvmvg
- PV Size 8.00 GiB / not usable 4.00 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 2047
- Free PE 2047
- Allocated PE 0
- PV UUID p00Ba0-iWBb-oVhZ-kwiy-yXEc-khNX-sKkazU
- [root@Gong-Computer ~]# vgdisplay
- --- Volume group ---
- VG Name mylvmvg
- System ID
- Format lvm2
- Metadata Areas 2
- Metadata Sequence No 12
- 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 15.99 GiB
- PE Size 4.00 MiB
- Total PE 4094
- Alloc PE / Size 512 / 2.00 GiB
- Free PE / Size 3582 / 13.99 GiB
- VG UUID T11gb0-MYs3-Yvym-4bVz-8ABy-8DlF-H1hS3V
- [root@Gong-Computer ~]# lvdisplay
- --- Logical volume ---
- LV Name /dev/mylvmvg/lvol1
- VG Name mylvmvg
- LV UUID ZEC6l3-y6GT-xRVf-8I7T-z7v3-KEgu-6yHsPS
- LV Write Access read/write
- LV Status available
- # open 0
- LV Size 2.00 GiB
- Current LE 512
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 256
- Block device 253:1
- [root@Gong-Computer ~]#
- [root@Gong-Computer ~]# vgreduce mylvmvg /dev/sde
- Removed "/dev/sde" from volume group "mylvmvg"
- [root@Gong-Computer ~]#
- [root@Gong-Computer ~]# pvremove /dev/sde
- Labels on physical volume "/dev/sde" successfully wiped
- [root@Gong-Computer ~]# vgremove mylvmvg
- Do you really want to remove volume group "mylvmvg" containing 1 logical volumes? [y/n]: y
- Do you really want to remove active logical volume lvol1? [y/n]: y
- Logical volume "lvol1" successfully removed
- Volume group "mylvmvg" successfully removed
- [root@Gong-Computer ~]# pvremove /dev/sdd
- Labels on physical volume "/dev/sdd" successfully wiped
- [root@Gong-Computer ~]#