实验目的:
理解LVM(逻辑卷管理器),添加、删除和调整LVM大小。
实验环境:
操作系统:RedHat Enterprise Linux 5 (RHEL5)
相关软件:lvm2-2.02.16-3.el5
实验步骤:
注:在前面我们建立了3个PV分别是“/dev/hda5 /dev/hda6 /dev/hda7 ”
(内容参见)
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
RHEL5的LVM应用实例(LVM调整大小和删除)
内容版权声明:除非注明,否则皆为本站原创文章。