LVM详细使用介绍
vg
-
vg卷组扩容
准备一个pv
[root@www ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
扩展vg的容量
使用vgextend 命令 vgextend vgname Device
[root@www ~]# vgextendtestvg /dev/sdb2
Volume group "testvg" successfully extended
[root@www ~]# vgs
Couldn't find device with uuid 2QpQ6S-B9Oz-7PB1-fIKo-Lhdw-h00t-3EtX00.
VG #PV #LV #SN Attr VSize VFree
VG 2 0 0wz-pn- 8.02g 8.02g
testvg 3 1 0 wz--n- 15.02g 10.02g
vg_centos 1 2 0wz--n- 24.51g 0
2. vg卷组的缩减
将要移除pv上的数据移动到其他pv上去
[root@www ~]# pvmove/dev/sdb1
/dev/sdb1: Moved: 0.1%
/dev/sdb1: Moved: 64.8%
/dev/sdb1: Moved: 100.0%
vgreduce命令缩减vg vgreduce vgname Device
[root@www ~]# vgreducetestvg /dev/sdb1
Removed "/dev/sdb1" from volume group "testvg"
3. 删除vg卷组
[root@www ~]# vgremove testvg
Volume group "testvg" successfully removed
lv
lv的扩展
首先确定lv所在的卷组的空间是不是足够多
1. 扩展物理边界
[root@www ~]# lvextend -L+2G /dev/testvg/testlv
Extending logical volume testlv to 7.00 GiB
Logical volume testlv successfully resized
2. 扩展逻辑边界
[root@www ~]# resize2fs/dev/testvg/testlv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/testvg/testlv is mountedon /mnt; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of/dev/testvg/testlv to 1835008 (4k) blocks.
The filesystem on /dev/testvg/testlv is now1835008 blocks long.
3. 验证lv扩展成功没
[root@www ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
23G 17G 4.2G 81% /
tmpfs 935M 0 935M 0% /dev/shm
/dev/sda1 485M 47M 414M 11% /boot
/dev/mapper/testvg-testlv
6.9G 140M 6.5G 3% /mnt
lv缩减
缩减lv之前一定要将其卸载并强行检测文件系统
[root@www ~]# umount/dev/testvg/testlv
[root@www ~]# fsck -f /dev/testvg/testlvfsck 是文件系统检测工具加上 –f 参数表示强制检测
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/testvg-testlv: 12/458752 files(0.0% non-contiguous), 64448/1835008 blocks
如果不检测文件系统在以后使用过程中可能会产生乱码
-
缩减逻辑卷
resizefs Device size
[root@www ~]# resize2fs/dev/testvg/testlv 5G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on/dev/testvg/testlv to 1310720 (4k) blocks.
2. 缩减物理卷
[root@www ~]# lvreduce -L5G /dev/testvg/testlv
WARNING: Reducing active logical volume to 5.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]:y
Reducing logical volume testlv to 5.00 GiB
Logical volume testlv successfully resized
3. 移除lv卷
a)卸载lv卷mount
b)使用lvremove Device移除lv卷
[root@www ~]# umount /mnt
[root@www ~]# lvremove/dev/testvg/testlv
Do you really want toremove active logical volume testlv? [y/n]: y
Logical volume"testlv" successfully removed
验证
[root@www ~]# lvs
Couldn't find device with uuid 2QpQ6S-B9Oz-7PB1-fIKo-Lhdw-h00t-3EtX00.
LV VG Attr LSize Pool Origin Data% Move LogCpy%Sync Convert
lv_root vg_centos -wi-ao--- 22.57g
lv_swap vg_centos -wi-ao--- 1.94g
注意
lvreduce –L [+|-]size Device 表示在原卷大小的基础上加或者减少多少空间
lvreduce –L size Device 表示直接将原卷扩大多少空间。
LVM裁减顺序是 LV——〉VG——〉PV
LVM扩容参考:http://blog.sina.com.cn/s/blog_497f74bc01011z55.html
Linux分区参考:http://jingyan.baidu.com/article/59a015e3a65909f79488653d.html
LVM 全面简介:http://blog.chinaunix.net/uid-20276248-id-92114.html
http://blog.sina.com.cn/s/blog_625651900101708z.html