LVM的容量调整可以在多个环节进行调整,比如:可以在物理卷上,VG上,以及LV上,都可以进行容量的扩展,这也是LVM它的一个优势所在。
1:添加新的PV
[root@rhel5 ~]# fdisk -l /dev/sdb #可以看见已经新添加了一个分区/dev/sdb7
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 83 Linux
/dev/sdb2 38 99 498015 5 Extended
/dev/sdb5 38 50 104391 83 Linux
/dev/sdb6 51 63 104391 83 Linux
/dev/sdb7 64 76 104391 83 Linux
[root@rhel5 ~]# pvcreate /dev/sdb7 #创建新的PV
Physical volume "/dev/sdb7" successfully created
[root@rhel5 ~]# pvdisplay #确人PV是否创建成功
--- NEW Physical volume ---
PV Name /dev/sdb7
VG Name
PV Size 101.94 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID nFMTQH-0HIm-G80S-8jwt-rJU4-8i2z-0fBv8A
2:添加PV到VG卷组中
[root@rhel5 ~]# vgextend vg1 /dev/sdb7 #将PV /dev/sdb7添加到之前已经存在的卷组vg1中
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "vg1" successfully extended
[root@rhel5 ~]# pvdisplay #如下可以看见已经添加成功
--- Physical volume ---
PV Name /dev/sdb5
VG Name vg1
PV Size 101.94 MB / not usable 1.94 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 25
Free PE 0
Allocated PE 25
PV UUID YASLH1-FyGQ-AJKz-Ik4h-H4NG-XLUw-sc7Fyx
--- Physical volume ---
PV Name /dev/sdb6
VG Name vg1
PV Size 101.94 MB / not usable 1.94 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 25
Free PE 25
Allocated PE 0
PV UUID iPEY0d-JpT6-UuKz-0Bte-DBQF-7lrM-NnKm1u
--- Physical volume ---
PV Name /dev/sdb7
VG Name vg1
PV Size 101.94 MB / not usable 1.94 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 25
Free PE 25
Allocated PE 0
PV UUID nFMTQH-0HIm-G80S-8jwt-rJU4-8i2z-0fBv8A
3:将新的LVM磁盘(/dev/sdb7)的容量添加到逻辑卷lvm1中
[root@rhel5 ~]# lvdisplay #添加之前的容量是100M
--- Logical volume ---
LV Name /dev/vg1/lvm1
VG Name vg1
LV UUID 2MntF2-QRj1-MxEk-S30r-v55v-CjJO-KTqL67
LV Write Access read/write
LV Status available
# open 1
LV Size 100.00 MB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
[root@rhel5 ~]#
[root@rhel5 ~]# lvextend -L +100M /dev/vg1/lvm1 #给lvm1添加100M的容量
Extending logical volume lvm1 to 200.00 MB
Logical volume lvm1 successfully resized
[root@rhel5 ~]# lvdisplay #可以查看容量已经由之前的100M增加到200M
--- Logical volume ---
LV Name /dev/vg1/lvm1
VG Name vg1
LV UUID 2MntF2-QRj1-MxEk-S30r-v55v-CjJO-KTqL67
LV Write Access read/write
LV Status available
# open 1
LV Size 200.00 MB
Current LE 50
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
[root@rhel5 ~]# resize2fs -f /dev/vg1/lvm1 #如果不做这一步, LV的容量没有真正的加入进LV卷中,因为相关信息写入到了磁盘超级块中
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg1/lvm1 is mounted on /mnt; on-line resizing required
Performing an on-line resize of /dev/vg1/lvm1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lvm1 is now 204800 blocks long.
4:挂载使用
[root@rhel5 ~]# mount /dev/vg1/lvm1 /mnt
mount: /dev/vg1/lvm1 already mounted or /mnt busy
mount: according to mtab, /dev/mapper/vg1-lvm1 is already mounted on /mnt
LVM 的卸载过程,与创建立过程相反
删除LV-->删除VG-->删除PV
卸载LVM以后,之前前的LVM的分区应用fdisk转换成其它类型的文件系统,当普通分区使用。
一.删除LV
[root@rhel5 ~]# umount /dev/vg1/lvm1 #先卸载lv,因为无法删除正在使用的lv
[root@rhel5 ~]# lvremove /dev/vg1/lvm1
Do you really want to remove active logical volume "lvm1"? [y/n]: y
Logical volume "lvm1" successfully removed
[root@rhel5 ~]# lvdisplay #确认lv已经被删除
二.删除VG
[root@rhel5 ~]# vgchange -a n vg1 #使卷组中的卷不可用
0 logical volume(s) in volume group "vg1" now active
[root@rhel5 ~]# vgremove vg1 #删除卷组
/dev/cdrom: open failed: Read-only file system
Volume group "vg1" successfully removed
[root@rhel5 ~]# vgdisplay #确认已经删除
三.删除PV
[root@rhel5 ~]# pvremove /dev/sdb5 /dev/sdb6 /dev/sdb7 #删除PV
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Labels on physical volume "/dev/sdb5" successfully wiped
Labels on physical volume "/dev/sdb6" successfully wiped
Labels on physical volume "/dev/sdb7" successfully wiped
[root@rhel5 ~]# pvdisplay #确认pv已经被成功清除
[root@rhel5 ~]# mount /dev/sdb5 /mnt
mount: you must specify the filesystem type
所要使用分区/dev/sdb5 ,/dev/sdb6 ,/dev/sdb7 ,必须格式化
[root@rhel5 ~]# mkfs -t exte /dev/sdb5 #格式化分区
[root@rhel5 ~]# mount /dev/sdb5 /mnt #挂载后就可以使用该分区了
命令说明:
pvcreate (创建物理卷)
pvdisplay (显示物理卷信息)
pvscan (扫描物理卷)
pvremove (删除物理卷)
vgcreate (创建卷组)
vgdisplay (显示卷组信息)
vgscan (扫描卷组)
vgextend (扩展卷组) vgextend vg1 /dev/sdb7 (把物理卷/dev/sdb7 加到vg1卷组中)
vgreduce (删除卷组中的物理卷)
vgreduce vg1 /dev/sdb7 (把物理卷/dev/sdb7 从卷组vg1中删除)
vgremove (删除卷组)
vgremove vg1 (删除卷组vg1)
lvcreate (创建逻辑卷)
lvdisplay (显示逻辑卷信息)
lvscan (扫描逻辑卷)
lvextend (扩展逻辑卷) lvextend -l +5G /dev/vg1/lvm1 (扩展逻辑卷/dev/vg1/lvm1 5个G)
lvreduce (减少LV大小) lvreduce -L-50M /dev/vg1/lvm1,调整lvm1分区大小,减小50M
lvremove (删除逻辑卷)