LVM(Logical Volume Manager) 是基于内核的一种逻辑卷管理器,适合大存储设备,并允许动态的调整文件系统的大小。
LVM 的概念示意图:
流程:首先将一块或者多块硬盘创建成 PV,之后创建一个新的卷组(VG),把 PV 加入到卷组(GV)里面,如果我们要使用多大 LV,就从 VG 里面里面提取多大的空间(随机的),如上图所示。
创建LVM分区实例:
这里我们使用 sdb,sdc 这两块为 1G 的硬盘作为实验。创建一个为 test_vg 的卷组,然后从该卷组中创建出分别为 500M 和 600M 的逻辑卷。
- [[email protected]~]# fdisk -l
- Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
- Units = sectors of 1 * 512 = 512 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectors
- Units = sectors of 1 * 512 = 512 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- [[email protected]~]# pvcreate /dev/sdb /dev/sdc
- Physical volume "/dev/sdb" successfully created.
- Physical volume "/dev/sdc" successfully created.
- [[email protected]~]# pvdisplay /dev/sdb /dev/sdc
- "/dev/sdb" is a new physical volume of "1.00 GiB"
- --- NEW Physical volume ---
- PV Name /dev/sdb
- VG Name
- PV Size 1.00 GiB
- Allocatable NO
- PE Size 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID TTLiRU-NAEM-7irI-ghgc-gbaT-vwv6-dvV3kQ
- "/dev/sdc" is a new physical volume of "1.00 GiB"
- --- NEW Physical volume ---
- PV Name /dev/sdc
- VG Name
- PV Size 1.00 GiB
- Allocatable NO
- PE Size 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID m8QdiJ-wYN6-JSsd-AGGB-M1oC-jkf5-5OpDcU
- [[email protected]~]# vgcreate test_vg /dev/sdb /dev/sdc
- Volume group "test_vg" successfully created
- [[email protected]~]# vgdisplay
- --- Volume group ---
- VG Name test_vg
- 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 1.99 GiB
- PE Size 4.00 MiB
- Total PE 510
- Alloc PE / Size 0 / 0
- Free PE / Size 510 / 1.99 GiB
- VG UUID BfM0C3-IxyK-IwGG-eODI-ilnv-GOkK-b mNso4
- [[email protected]~]# lvcreate -L 500M -n test_web test_vg
- Logical volume "test_web" created.
- [[email protected]~]# lvcreate -L 600M -n test_data test_vg
- Logical volume "test_data" created.
- [[email protected]~]# lvdisplay
- ......(省略部分)
- --- Logical volume ---
- LV Path /dev/test_vg/test_web
- LV Name test_web
- VG Name test_vg
- LV UUID R2ky1r-KQ0O-5dU1-23KV-9j5c-r3dx-bbzvCX
- LV Write Access read/write
- LV Creation host, time dianel, 2017-04-26 16:09:56 +0800
- LV Status available
- # open 0
- LV Size 500.00 MiB
- Current LE 125
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 8192
- Block device 253:2
- --- Logical volume ---
- LV Path /dev/test_vg/test_data
- LV Name test_data
- VG Name test_vg
- LV UUID poSaRr-46UO-qZzB-TJnJ-kIUY-7XzP-TKZhdZ
- LV Write Access read/write
- LV Creation host, time dianel, 2017-04-26 16:10:14 +0800
- LV Status available
- # open 0
- LV Size 600.00 MiB
- Current LE 150
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 8192
- Block device 253:3
- [[email protected]~]# mkfs.xfs -f /dev/test_vg/test_data
- [[email protected]~]# mkfs.xfs -f /dev/test_vg/test_web
- [[email protected]~]# mkdir -p /test/{web,data}
- [[email protected]~]# mount /dev/test_vg/test_data /test/data/
- [[email protected]~]# mount /dev/test_vg/test_web /test/web/
- [[email protected]~]# mount
- .....
- /dev/mapper/test_vg-test_data on /test/data type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
- /dev/mapper/test_vg-test_web on /test/web type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
- [[email protected]~]# df -h
- /dev/mapper/test_vg-test_data 597M 31M 567M 6% /test/data
- /dev/mapper/test_vg-test_web 497M 26M 472M 6% /test/web
修改 LVM 分区容量
- [[email protected]data]# lvextend -L +500M /dev/test_vg/test_data
- Size of logical volume test_vg/test_data changed from 600.00 MiB (150 extents) to 1.07 GiB (275 extents).
- Logical volume test_vg/test_data successfully resized.
- #查看LV已经扩展完成
- [[email protected]data]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- test_data test_vg -wi-ao---- 1.07g
- test_web test_vg -wi-ao---- 500.00m
- #但是文件系统并没有变化
- [[email protected]data]# df -h
- Filesystem Size Used Avail Use% Mounted on
- .....
- /dev/mapper/test_vg-test_data 597M 31M 567M 6% /test/data
- /dev/mapper/test_vg-test_web 497M 26M 472M 6% /test/web
- #调整文件系统
- [[email protected]data]# xfs_growfs /dev/test_vg/test_data
- [[email protected]data]# df -h
- Filesystem Size Used Avail Use% Mounted on
- ......
- /dev/mapper/test_vg-test_data 1.1G 31M 1.1G 3% /test/data
- /dev/mapper/test_vg-test_web 497M 26M 472M 6% /test/web
- #新添加了两块为分别为1G的硬盘
- [[email protected]~]# fdisk -l
- Disk /dev/sdd: 1073 MB......
- Disk /dev/sde: 1073 MB......
- #之前的卷组
- [[email protected]~]# vgdisplay test_vg
- --- Volume group ---
- VG Name test_vg
- ......
- VG Size 1.99 GiB
- PE Size 4.00 MiB
- Total PE 510
- Alloc PE / Size 400 / 1.56 GiB
- Free PE / Size 110 / 440.00 MiB
- #创建PV
- [[email protected]~]# pvcreate /dev/sde /dev/sdd
- Physical volume "/dev/sde" successfully created.
- Physical volume "/dev/sdd" successfully created.
- #扩展VG
- [[email protected]~]# vgextend test_vg /dev/sdd
- Volume group "test_vg" successfully extended
- [[email protected]~]# vgextend test_vg /dev/sde
- Volume group "test_vg" successfully extended
- #现在的的VG
- [[email protected]~]# vgdisplay test_vg
- --- Volume group ---
- VG Name test_vg
- ......
- VG Size 3.98 GiB
- Total PE 1020
- Free PE / Size 620 / 2.42 GiB
- [[email protected]~]# umount /dev/test_vg/test_data
- [[email protected]~]# umount /dev/test_vg/test_web
- ++++++++++++++++++
- [[email protected]~]# lvremove /dev/test_vg/test_data
- Do you really want to remove active logical volume test_vg/test_data? [y/n]: y
- Logical volume "test_data" successfully removed
- [[email protected]~]# lvremove /dev/test_vg/test_web
- Do you really want to remove active logical volume test_vg/test_web? [y/n]: y
- Logical volume "test_web" successfully removed
- #删除卷组
- [[email protected]~]# vgremove test_vg
- Volume group "test_vg" successfully removed
- ++++++++++++++++++++++
- [[email protected]~]# pvremove /dev/sdd /dev/sde
- Labels on physical volume "/dev/sdd" successfully wiped.
- Labels on physical volume "/dev/sde" successfully wiped.
2017/4/26 18:03:01
来源: http://www.bubuko.com/infodetail-2250392.html