实验目的:
理解LVM(逻辑卷管理器),添加、删除和调整LVM大小。
实验环境:
操作系统:RedHat Enterprise Linux 5 (RHEL5)
相关软件:lvm2-2.02.16-3.el5
实验步骤:
注:在前面我们建立了3个PV分别是“/dev/hda5 /dev/hda6 /dev/hda7 ”
(内容参见http://www.linuxidc.com/Linux/2010-10/29418.htm)
1. 增大LVM
为VG添加新的PV使其增加容量
[root@linux tmp]# vgextend vg1 /dev/hda7
Volume group “vg1” successfully extended
显示VG信息
[root@linux tmp]# vgdisplay
— Volume group —
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 252.00 MB
PE Size 4.00 MB
Total PE 63
Alloc PE / Size 45 / 180.00 MB
Free PE / Size 18 / 72.00 MB
VG UUID GOysUz-Fyeu-ttE0-R3UE-ra3Z-s1dM-l4QZ7n
为LV增加容量
[root@linux tmp]# lvextend -L +50M /dev/vg1/lv1
Rounding up size to full physical extent 52.00 MB
Extending logical volume lv1 to 252.00 MB
Logical volume lv1 successfully resized
显示LV信息
[root@linux tmp]# lvdisplay /dev/vg1/lv1
— Logical volume —
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID PkCxki-KweE-AcpE-r1KO-cguR-mxUm-xvPP0n
LV Write Access read/write
LV Status available
# open 1
LV Size 252.00 MB
Current LE 63
Segments 3
Allocation inherit
Read ahead sectors 0
Block device 253:3
在线格式化新加的LV,让其可以正常使用
[root@linux tmp]# resize2fs /dev/vg1/lv1
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg1/lv1 is mounted on /tmp/lvm; on-line resizing required
Performing an on-line resize of /dev/vg1/lv1 to 258048 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 258048 blocks long.
查看挂载点的信息
[root@linux tmp]# df -h /tmp/lvm/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 244M 6.1M 226M 3% /tmp/lvm
2. 减小LV容量
释放LV容量150M
[root@linux tmp]# reduce -L -150M /dev/vg1/lv1
Rounding up size to full physical extent 148.00 MB
WARNING: Reducing active and open logical volume to 104.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv1? [y/n]: y
Reducing logical volume lv1 to 104.00 MB
Logical volume lv1 successfully resized
查看LV信息
[root@linux tmp]# lvdisplay /dev/vg1/lv1
— Logical volume —
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID PkCxki-KweE-AcpE-r1KO-cguR-mxUm-xvPP0n
LV Write Access read/write
LV Status available
# open 1
LV Size 104.00 MB
Current LE 26
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:3
删除VG中的容量100M的分区“/dev/hda6”
[root@linux tmp]# vgreduce vg1 /dev/hda6
Removed “/dev/hda6” from volume group “vg1”
显示VG信息
[root@linux tmp]# vgdisplay vg1
— Volume group —
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 17
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 152.00 MB
PE Size 4.00 MB
Total PE 38
Alloc PE / Size 24 / 96.00 MB
Free PE / Size 14 / 56.00 MB
VG UUID GOysUz-Fyeu-ttE0-R3UE-ra3Z-s1dM-l4QZ7n
删除PV“/dev/hda6”
[root@linux tmp]# pvremove /dev/hda6
Labels on physical volume “/dev/hda6” successfully wiped
显示PV信息
[root@linux tmp]# pvdisplay
— Physical volume —
PV Name /dev/hda5
VG Name vg1
PV Size 101.94 MB / not usable 1.94 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 25
Free PE 1
Allocated PE 24
PV UUID jSaI8a-D2B3-5HSA-LkPT-hQ1v-gut6-yY10t6
— Physical volume —
PV Name /dev/hda7
VG Name vg1
PV Size 54.88 MB / not usable 2.88 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 13
Free PE 13
Allocated PE 0
PV UUID KLBWkX-l694-Yagy-BdHf-RkJ2-2NIC-ltGty0
3. 删除所有的LVM
取消挂载的分区
[root@linux tmp]# umount /tmp/lvm/
删除LV
[root@linux tmp]# lvremove /dev/vg1/lv1
Do you really want to remove active logical volume “lv1”? [y/n]: y
Logical volume “lv1” successfully removed
删除VG
[root@linux tmp]# vgremove vg1
Volume group “vg1” successfully removed
删除PV
[root@linux tmp]# pvremove /dev/hda5 /dev/hda7
Labels on physical volume “/dev/hda5” successfully wiped
Labels on physical volume “/dev/hda7” successfully wiped
删除物理分区的方法是使用“fdisk”命令
[root@linux tmp]# fdisk /dev/hda
纤细信息显示如下
Command (m for help): d
Partition number (1-7): 7
Command (m for help): d
Partition number (1-6): 6
Command (m for help): d
Partition number (1-5): 5
Command (m for help): p
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 16 128488+ 83 Linux
/dev/hda2 17 7665 61440592+ 8e Linux LVM
/dev/hda3 7666 7796 1052257+ 82 Linux swap / Solaris
/dev/hda4 7797 9729 15526822+ 5 Extended
Command (m for help):
实验总结:
LVM的建立和删除,增加容量和容量减小是一个互逆的过程。
RHCE_LAB(6)RHEL5的LVM应用实例(LVM调整大小和删除)——结束