分类: LINUX
2008-05-29 11:50:06
#pvcreate /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
#vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group "vg1" successfully created
#vgchange -a y vg1
0 logical volume(s) in volume group "vg1" now active
#vgextend vg1 /dev/sdb5
Volume group "vg1" successfully extended
#pvdisplay /dev/sdb1
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg1
PV Size 48.00 MB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 12
Free PE 12
Allocated PE 0
PV UUID ncdQHn-wRWW-pCJR-2siv-SXSY-vCxq-FBfWrw
#vgdisplay vg1
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 2
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 192.00 MB
PE Size 4.00 MB
Total PE 48
Alloc PE / Size 0 / 0
Free PE / Size 48 / 192.00 MB
VG UUID Qzd9qI-5oeA-23b9-FLls-W2Ra-739g-vw36XW
# lvcreate -L100M -nlv1 vg1
Logical volume "lv1" created
lvdisplay
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID ezmFx2-svKD-EVNV-rZxY-HS6P-vnd3-Q9KKOR
LV Write Access read/write
LV Status available
# open 0
LV Size 100.00 MB
Current LE 25
Segments 3
Allocation inherit
Read ahead sectors 0
Block device 253:2
# mkfs.ext3 -b 4096 /dev/vg1/lv1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
25600 inodes, 25600 blocks
1280 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=29360128block group
32768 blocks per group, 32768 fragments per group
25600 inodes per groupWriting inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# mount /dev/vg1/lv1 /mnt
查看当前系统分区情况,我们可以看到现在lv1的大小是100M
[root@ha1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3451040 2644664 631068 81% /
/dev/sda1 101086 9181 86686 10% /boot
none 127988 0 127988 0% /dev/shm
/dev/mapper/vg1-lv1 99184 4152 89912 5% /mnt
# lvextend -L50M /dev/vg1/lv1
Rounding up size to full physical extent 52.00 MB
New size given (13 extents) not larger than existing size (25 extents)
lvextend: Add space to a logical volume
这个错误是说新的大小比以前的要小,索引不能扩展,我们指定的新的大小必须大于原来的大小.或者用+50M来增加大小.
比如
# lvextend -L120M /dev/vg1/lv1
Extending logical volume lv1 to 120.00 MB
Logical volume lv1 successfully resized
#lvextend -L+20M /dev/vg1/lv1
Extending logical volume lv1 to 120.00 MB
Logical volume lv1 successfully resized
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3451040 2644668 631064 81% /
/dev/sda1 101086 9181 86686 10% /boot
none 127988 0 127988 0% /dev/shm
/dev/mapper/vg1-lv1 99184 4152 89912 5% /mnt
# ext2online /dev/vg1/lv1
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3451040 2644668 631064 81% /
/dev/sda1 101086 9181 86686 10% /boot
none 127988 0 127988 0% /dev/shm
/dev/mapper/vg1-lv1 119664 4152 110392 4% /mnt
如果LV所在的VG空间不够的话,在进行lvextend时并不会表现出来,只有在ext2online的时候才会有提示:
ext2online /dev/vg1/lv1
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
ext2online: ext2_ioctl: No space left on deviceext2online: unable to resize /dev/mapper/vg1-lv1
我们说了LV是可以动态调整大小的,既然可以扩展,当然可以减小了.可以使用lvreduce来进行这个操作.
lvreduce -L-50M /dev/vg1/lv1
Rounding up size to full physical extent 48.00 MB
WARNING: Reducing active and open logical volume to 92.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv1? [y/n]: y
Reducing logical volume lv1 to 92.00 MB
Logical volume lv1 successfully resized
同样,也需要使用ext2online来使更改生效.
减小lv具有一定的风险,一般情况下不要减小lv