LVM 逻辑卷的扩容/缩容

LVM 逻辑卷的扩容/缩容

[1] 创建逻辑卷
[root@hyperStor ~]# vgs //查看当前卷组
VG #PV #LV #SN Attr VSize VFree
vg0 2 2 0 wz--n- 698.38g 98.29g
[root@hyperStor ~]# lvcreate -L 2GB -n lv1 vg0 //在卷组vg0上建立2GB的逻辑卷lv1
Logical volume "lv1"created
[root@hyperStor ~]# lvs |grep lv1
lv1 vg0 -wi-a- 2.00g
[root@hyperStor ~]# mkfs.ext4 /dev/vg0/lv1 > /dev/null 2>& 1 //格式化lv1
[root@hyperStor ~]# mkdir /lv1
[root@hyperStor ~]# mount /dev/vg0/lv1 /lv1 //挂载lv1到/lv1目录下
[root@hyperStor ~]# df -H |grep lv1 //查看挂载状态
/dev/mapper/vg0-lv12.2G 71M 2.0G 4% /lv1
[root@hyperStor ~]# mount |grep lv1
/dev/mapper/vg0-lv1on /lv1typeext4 (rw)
[root@hyperStor ~]# dd if=/dev/zero of=/lv1/test1 bs=100M count=5 //想/lv1中写入500M数据
5+0 records in
5+0 records out
524288000 bytes (524 MB) copied, 1.92862 s, 272 MB/s
[root@hyperStor ~]# du -sh /lv1/* //查看文件状态
16K/lv1/lost+found
500M/lv1/test1

[2] lvextend命令扩容lv1到3GB
//将lv1扩到3GB,如果是从2GB到5GB,则为lvextend -L +3GB
[root@hyperStor ~]# lvextend  -L 3GB -n  /dev/vg0/lv1
  Extending logical volume lv1 to 3.00 GiB
  Logical volume lv1 successfully resized
[root@hyperStor ~]# lvs |grep lv1  //查看当前逻辑卷大小,已经为3GB
  lv1            vg0  -wi-ao  3.00g                           
[root@hyperStor ~]# df -H |grep lv1  //查看文件系统状态,发现文件系统仍没有扩容
/dev/mapper/vg0-lv1    2.2G  595M  1.5G  30% /lv1
[root@hyperStor ~]# resize2fs  /dev/vg0/lv1  //调整文件系统大小
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg0/lv1 is mounted on /lv1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg0/lv1 to 786432 (4k) blocks.
The filesystem on /dev/vg0/lv1 is now 786432 blocks long.
[root@hyperStor ~]# df -H |grep lv1  //重新查看文件系统大小,成功在线扩容到3GB
/dev/mapper/vg0-lv1    3.2G  595M  2.5G  20% /lv1
[root@hyperStor ~]# lvs |grep lv1
  lv1            vg0  -wi-ao  3.00g                           
[root@hyperStor ~]# du -sh /lv1/*    //查看数据是否完整
16K/lv1/lost+found
501M/lv1/test1

[3] lvreduce 缩容,不可“在线”操作 lv1:3GB-->1GB
[root@hyperStor ~]# umount /lv1/      //卸载文件系统
[root@hyperStor ~]# mount |grep lv1|wc -l  //查看是否成功卸载
0
[root@hyperStor ~]# lvs |grep lv1  //查看当前lv1 状态
  lv1            vg0  -wi-a-  3.00g                           
[root@hyperStor ~]# e2fsck -f /dev/vg0/lv1  //进行磁盘检查
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/vg0/lv1: 12/196608 files (0.0% non-contiguous), 157501/786432 blocks
[root@hyperStor ~]# resize2fs  /dev/vg0/lv1  1G  //调整文件系统
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg0/lv1 to 262144 (4k) blocks.
The filesystem on /dev/vg0/lv1 is now 262144 blocks long.
[root@hyperStor ~]# lvs |grep lv1    //查看lv1 大小,未变
  lv1            vg0  -wi-a-  3.00g                           
[root@hyperStor ~]# lvreduce -L 1GB /dev/vg0/lv1  //通过lvduce命令进行缩容
  WARNING: Reducing active logical volume to 1.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv1? [y/n]: y
  Reducing logical volume lv1 to 1.00 GiB
  Logical volume lv1 successfully resized
[root@hyperStor ~]# lvs |grep lv1  //再次查看lv1大小,减少
  lv1            vg0  -wi-a-  1.00g                           
[root@hyperStor ~]# mount /dev/vg0/lv1  /lv1/  //重新挂载
[root@hyperStor ~]# df -H |grep lv1  //查看当前状态
/dev/mapper/vg0-lv1    1.1G  595M  410M  60% /lv1
[root@hyperStor ~]# du -sh /lv1/* //查看数据情况
16K/lv1/lost+found
501M/lv1/test1

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/19191.html