逻辑卷LVM是建立在物理存储设备之上的一个抽象层,LVM使存储虚拟化,不会受限于物理磁盘的大小,可以组合多个物理磁盘,也可以在线对其逻辑卷的大小进行追加。
[root@orcl11g test]# pvcreate /dev/sda{5,6,7,8,9}
Physical volume "/dev/sda3" successfully created
Physical volume "/dev/sda5" successfully created
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
Physical volume "/dev/sda8" successfully created
Physical volume "/dev/sda9" successfully created
[root@orcl11g test]# pvscan
PV /dev/sda3 lvm2 [980.53 MB]
PV /dev/sda5 lvm2 [1.92 GB]
PV /dev/sda6 lvm2 [1.92 GB]
PV /dev/sda7 lvm2 [1.92 GB]
PV /dev/sda8 lvm2 [1.92 GB]
PV /dev/sda9 lvm2 [2.37 GB]
Total: 6 [10.99 GB] / in use: 0 [0 ] / in no VG: 6 [10.99 GB]
[root@orcl11g test]# pvdisplay
"/dev/sda3" is a new physical volume of "980.53 MB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 980.53 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dJ3j0L-wDWq-1Bfa-zkpG-yTbG-eoNa-4FrjGP
"/dev/sda5" is a new physical volume of "1.92 GB"
--- NEW Physical volume ---
PV Name /dev/sda5
VG Name
PV Size 1.92 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID nZnZfR-K5aH-v0MK-Vgfm-ZFY3-O1pK-fa5m1V
后续的省略
移除其中的一个物理卷
[root@orcl11g test]# pvremove /dev/sda3
Labels on physical volume "/dev/sda3" successfully wiped
[root@orcl11g test]# vgcreate -s 8M vg0 /dev/sda{5,6,7,8}
Volume group "vg0" successfully created
[root@orcl11g test]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg0" using metadata type lvm2
[root@orcl11g test]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 4
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 4
Act PV 4
VG Size 7.66 GB
PE Size 8.00 MB
Total PE 980
Alloc PE / Size 0 / 0
Free PE / Size 980 / 7.66 GB
VG UUID RUxe0R-XVBe-IJe5-rz4D-IX00-30k5-YWG1gb
添加某个物理卷到卷组:
[root@orcl11g test]# vgextend vg0 /dev/sda9
Volume group "vg0" successfully extended
移除卷组
[root@orcl11g test]# vgremove vg0
Volume group "vg0" successfully removed
创建逻辑卷,一个卷组可以分开创建两个逻辑卷。
[root@orcl11g test]# lvcreate -L 8G -n lv0 vg0
Logical volume "lv0" created
[root@orcl11g test]# lvcreate -L 2G -n lv1 vg0
Logical volume "lv1" created
移除某个逻辑卷
[root@orcl11g test]# lvremove /dev/vg0/lv1
Do you really want to remove active logical volume "lv1"? [y/n]: y
Logical volume "lv1" successfully removed
格式化逻辑卷
[root@orcl11g test]# mkfs -t ext3 /dev/vg0/lv0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
增加逻辑卷的大小
[root@orcl11g test]# lvextend -L +2G /dev/vg0/lv0
Extending logical volume lv0 to 10.00 GB
Logical volume lv0 successfully resized
当在mount阶段对其逻辑卷容量尽量修改时,需要使用Resize2fs使其修改马上生效,不然df看见的还是原来的size
[root@orcl11g test]# resize2fs /dev/vg0/lv0
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg0/lv0 to 2621440 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 2621440 blocks long.
减少逻辑卷的大小。(不过个人在虚拟机环境下测试后无法正常resize,superblock被损坏)
[root@orcl11g test]# lvreduce -L -2G /dev/vg0/lv0
WARNING: Reducing active logical volume to 8.00 GB
减少完后还是把这2G用lvextend追加进去
挂载逻辑卷
[root@orcl11g test]# mount /dev/vg0/lv0 /db
[root@orcl11g test]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 3.8G 3.0G 657M 83% /
/dev/sda1 99M 13M 82M 14% /boot
tmpfs 440M 0 440M 0% /dev/shm
none 440M 104K 440M 1% /var/lib/xenstored
/dev/mapper/vg0-lv0 9.9G 147M 9.4G 2% /db
[@more@]来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25362835/viewspace-1059284/ ,如需转载,请注明出处,否则将追究法律责任。