Linux下LVM的配置详解
- - BlogJava-qileilove LVM是Logical Volume Manager(逻辑卷管理器)的简写,它为主机提供了更高层次的磁盘存储管理能力. LVM可以帮助系统管理员为应用与用户方便地分配存储空间. 在LVM管理下的逻辑卷可以按需改变大小或添加移除. 另外,LVM可以为所管理的逻辑卷提供定制的命名标识. 因此,使用LVM主要是方便了对存储系统的管理,增加了系统的扩展性.
[root@redhat ~]# pvcreate /dev/hdb1 /dev/hdb2 Physical volume “/dev/hdb1″ successfully created Physical volume “/dev/hdb2″ successfully created [root@redhat ~]# pvscan PV /dev/hdb1 lvm2 [95.95 MB] PV /dev/hdb2 lvm2 [95.98 MB] Total: 2 [191.92 MB] / in use: 0 [0 ] / in no VG: 2 [191.92 MB] [root@redhat ~]# pvdisplay — NEW Physical volume — PV Name /dev/hdb1 VG Name PV Size 95.95 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 2Ni0Tx-oeSy-zGUP-t7KG-Fh22-0BUi-iyPhhQ — NEW Physical volume — PV Name /dev/hdb2 VG Name PV Size 95.98 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 2XLXfY-V3L2-Mtsl-79U4-ovuJ-YaQf-YV9qHs |
[root@redhat ~]# vgcreate vg0 /dev/hdb1 /dev/hdb2 Volume group “vg0″ successfully created [root@redhat ~]# vgscan Reading all physical volumes. This may take a while… Found volume group “vg0″ using metadata type lvm2 [root@redhat ~]# vgdisplay — Volume group — VG Name vg0 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 184.00 MB PE Size 4.00 MB /*分配的块的大小默认为4M*/ Total PE 46 Alloc PE / Size 0 / 0 Free PE / Size 46 / 184.00 MB VG UUID kL5CGk-5Odk-r3PK-9q0A-s94h-OHv4-BojBnH增加VG容量到1TB的方法: vgcreate -s 16M vg0 /dev/hdb1 /dev/hdb2 |
[root@redhat ~]# lvcreate -L 184M -n data vg0 Logical volume “data” created [root@redhat ~]# lvscan ACTIVE ‘/dev/vg0/data’ [184.00 MB] inherit [root@redhat ~]# lvdisplay — Logical volume — LV Name /dev/vg0/data VG Name vg0 LV UUID HNKO5d-yRre-qVnP-ZT8D-fXir-XTeM-r6WjDX LV Write Access read/write LV Status available # open 0 LV Size 184.00 MB Current LE 46 Segments 2 Allocation inherit Read ahead sectors 0 Block device 253:0 |
[root@redhat ~]# umount /dev/vg0/data [root@redhat ~]# pvcreate /dev/hdb3 Physical volume “/dev/hdb3″ successfully created [root@redhat ~]# pvscan PV /dev/hdb1 VG vg0 lvm2 [92.00 MB / 0 free] PV /dev/hdb2 VG vg0 lvm2 [92.00 MB / 0 free] PV /dev/hdb3 lvm2 [95.98 MB] Total: 3 [279.98 MB] / in use: 2 [184.00 MB] / in no VG: 1 [95.98 MB] |
[root@redhat ~]# vgextend vg0 /dev/hdb3 Volume group “vg0″ successfully extended [root@redhat ~]# vgdisplay — Volume group — VG Name vg0 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 276.00 MB PE Size 4.00 MB Total PE 69 Alloc PE / Size 46 / 184.00 MB Free PE / Size 23 / 92.00 MB VG UUID kL5CGk-5Odk-r3PK-9q0A-s94h-OHv4-BojBnH |
[root@redhat ~]# df 文件系统 1K-块 已用 可用 已用% 挂载点 /dev/hda3 7625092 2219468 5012032 31% / /dev/hda1 101086 10006 85861 11% /boot tmpfs 150108 0 150108 0% /dev/shm /dev/mapper/vg0-data 273569 6168 256097 3% /mnt/lvm [root@redhat ~]# umount /mnt/lvm |
[root@redhat ~]# pvscan 查看pv的情况 PV /dev/hdb1 lvm2 [95.95 MB] PV /dev/hdb2 lvm2 [95.98 MB] PV /dev/hdb3 lvm2 [95.98 MB] Total: 3 [287.90 MB] / in use: 0 [0 ] / in no VG: 3 [287.90 MB] [root@redhat ~]# pvremove /dev/hdb1 /dev/hdb2 /dev/hdb3 Attempt to close device ‘/dev/cdrom’ which is not open. Labels on physical volume “/dev/hdb1″ successfully wiped Labels on physical volume “/dev/hdb2″ successfully wiped Labels on physical volume “/dev/hdb3″ successfully wiped |