1.基本概念:
物理卷(pv): 物理卷可以是硬盘,也可以是硬盘上的分区,使用如pvcreate /dev/sdb1来创建一个物理卷.卷组(vg): 卷组由物理卷组成,可以通过添加,删除物理卷来改变卷组的大小,卷组可以看作传统意义上的可以改变大小的硬盘.
逻辑卷(lv): 逻辑卷对卷组进行的重新划分,相当于传统意义上的可以自由改变大小的硬盘分区.
2.基本操作
创建pv
#pvcreate /dev/sdb2 /dev/sdb3
Physical volume"/dev/sdb2"successfully created
Physical volume"/dev/sdb3"successfully created
创建vg
#vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group"vg1"successfully created
激活vg
#vgchange -a y vg1
0 logical volume(s) in volume group"vg1"now active
向vg中追加pv
#vgextend vg1 /dev/sdb5
Volume group"vg1"successfully extended
从vg中移走pv(不推荐)
查看pv的使用情况
#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
查看vg的状态
#vgdisplay vg1
--- Volume group ---
VG Name vg1
SystemID
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
建立LV
# 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
格式化LV
# 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%) reservedforthesuperuser
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 LV
# mount /dev/vg1/lv1 /mnt
[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
扩展LV的大小
# 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
# 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/18forEXT2FS 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
ext2online /dev/vg1/lv1
ext2online v1.1.18 - 2001/03/18forEXT2FS 0.5b
ext2online: ext2_ioctl: No space left on deviceext2online: unable to resize /dev/mapper/vg1-lv1
减小LV
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