您的位置:首页 > 运维架构 > Linux

RHEL6.5缩小、扩容逻辑卷

2016-09-20 15:51 162 查看
一、测试环境

1.1、安装平台: vmware workstation 12
操作系统:CentOS release 6.5 (Final) x86_64
关闭iptables、关闭selinux

二、原有磁盘信息

2.1、查看挂载情况:
[root@manager ~]# df -HT
Filesystem                    Type   Size  Used Avail Use% Mounted on
/dev/mapper/vg1-lv1           ext4   5.3G  145M  4.9G   3% /test1
/dev/mapper/vg1-lv2           ext4    11G  158M  9.9G   2% /test2

2.2、查看目录文件情况:
[root@manager test1]# ll
total 16
-rw-r--r-- 1 root root     0 Aug 12 14:55 a1
-rw-r--r-- 1 root root     0 Aug 12 14:55 a2
-rw-r--r-- 1 root root     0 Aug 12 14:55 a3
-rw-r--r-- 1 root root     0 Aug 12 14:55 a4
-rw-r--r-- 1 root root     0 Aug 12 14:55 a5
-rw-r--r-- 1 root root     0 Aug 12 14:55 a6
-rw-r--r-- 1 root root     0 Aug 12 14:55 a7
-rw-r--r-- 1 root root     0 Aug 12 14:55 a8
-rw-r--r-- 1 root root     0 Aug 12 14:55 a9
drwx------ 2 root root 16384 Aug 12 14:51 lost+found

[root@manager test2]# ll
total 16
-rw-r--r-- 1 root root     0 Aug 12 14:56 a1
-rw-r--r-- 1 root root     0 Aug 12 14:56 a2
-rw-r--r-- 1 root root     0 Aug 12 14:56 a3
-rw-r--r-- 1 root root     0 Aug 12 14:56 a4
-rw-r--r-- 1 root root     0 Aug 12 14:56 a5
-rw-r--r-- 1 root root     0 Aug 12 14:56 a6
-rw-r--r-- 1 root root     0 Aug 12 14:56 a7
-rw-r--r-- 1 root root     0 Aug 12 14:56 a8
-rw-r--r-- 1 root root     0 Aug 12 14:56 a9
drwx------ 2 root root 16384 Aug 12 14:51 lost+found

2.3、查看卷组和逻辑卷:
[root@manager ~]# vgs
VG       #PV #LV #SN Attr   VSize  VFree
VolGroup   1   1   0 wz--n- 57.70g    0
vg1        1   2   0 wz--n- 19.99g 4.99g

[root@manager ~]# lvs
LV       VG       Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
LogVol00 VolGroup -wi-ao---- 57.70g
lv1      vg1      -wi-ao----  5.00g
lv2      vg1      -wi-ao---- 10.00g


三、缩小、扩容逻辑卷

本次目的为缩小lv2的空间,并将压缩后的空间用来扩容LV1

3.1、卸载LV2挂载目录:
[root@manager ~]# umount /test2

3.2、运行e2fsck命令,该命令是用来检查逻辑卷是否有问题:(注:参数-f是遇见错误直接修复不提示。)

[root@manager ~]# e2fsck -f /dev/vg1/lv2
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/vg1/lv2: 20/655360 files (0.0% non-contiguous), 79663/2621440 blocks

3.3、缩小的文件系统大小为8G:
[root@manager ~]# resize2fs /dev/vg1/lv2 8G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg1/lv2 to 2097152 (4k) blocks.
The filesystem on /dev/vg1/lv2 is now 2097152 blocks long.

3.4、缩小逻辑卷LV2空间为8G:
[root@manager ~]# lvreduce -L 8G /dev/vg1/lv2
WARNING: Reducing active logical volume to 8.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv2? [y/n]: y
Reducing logical volume lv2 to 8.00 GiB
Logical volume lv2 successfully resized

再次查看卷组和逻辑卷情况:
[root@manager ~]# lvs
LV       VG       Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
LogVol00 VolGroup -wi-ao---- 57.70g
lv1      vg1      -wi-ao----  5.00g
lv2      vg1      -wi-a-----  8.00g
[root@manager ~]# vgs
VG       #PV #LV #SN Attr   VSize  VFree
VolGroup   1   1   0 wz--n- 57.70g    0
vg1        1   2   0 wz--n- 19.99g 6.99g

3.5、挂载逻辑卷LV2到test2查看文件情况:
[root@manager ~]# mount /dev/vg1/lv2 /test2
[root@manager test2]# ll
total 16
-rw-r--r-- 1 root root     0 Aug 12 14:56 a1
-rw-r--r-- 1 root root     0 Aug 12 14:56 a2
-rw-r--r-- 1 root root     0 Aug 12 14:56 a3
-rw-r--r-- 1 root root     0 Aug 12 14:56 a4
-rw-r--r-- 1 root root     0 Aug 12 14:56 a5
-rw-r--r-- 1 root root     0 Aug 12 14:56 a6
-rw-r--r-- 1 root root     0 Aug 12 14:56 a7
-rw-r--r-- 1 root root     0 Aug 12 14:56 a8
-rw-r--r-- 1 root root     0 Aug 12 14:56 a9
drwx------ 2 root root 16384 Aug 12 14:51 lost+found

由以上可以看到缩小逻辑卷LV2后,文件内容仍然一样,并未丢失;缩小逻辑卷成功。

3.6、扩容逻辑卷LV1:
[root@manager ~]# lvs
LV       VG       Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
LogVol00 VolGroup -wi-ao---- 57.70g
lv1      vg1      -wi-ao----  5.00g
lv2      vg1      -wi-ao----  8.00g

(1)扩容到10G:
[root@manager ~]# lvextend -L 10G /dev/vg1/lv1
Extending logical volume lv1 to 10.00 GiB
Logical volume lv1 successfully resized

[root@manager ~]# lvdisplay
--- Logical volume ---
LV Path                /dev/vg1/lv1
LV Name                lv1
VG Name                vg1
LV UUID                RT9iu0-mhDi-clg9-8N2H-rJ1G-feuE-WUQOoa
LV Write Access        read/write
LV Creation host, time manager.example.com, 2016-08-12 14:24:15 +0800
LV Status              available
# open                 1
LV Size                10.00 GiB
Current LE             2560
Segments               2
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

(2)扩容后,我们使用df命令查看/test1目录的大小;发现尽管逻辑卷已经扩容,但是逻辑卷所挂载的分区并没有扩容。
[root@manager ~]# df -HT
Filesystem                    Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol00 ext4    61G  3.6G   55G   7% /
tmpfs                         tmpfs  314M     0  314M   0% /dev/shm
/dev/sda1                     ext4   305M   41M  249M  15% /boot
/dev/mapper/vg1-lv1           ext4   5.3G  145M  4.9G   3% /test1
/dev/mapper/vg1-lv2           ext4   8.5G  158M  7.9G   2% /test2

(3)执行resize2fs刷新挂载分区扩容:
[root@manager ~]# resize2fs /dev/vg1/lv1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg1/lv1 is mounted on /test1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg1/lv1 to 2621440 (4k) blocks.
The filesystem on /dev/vg1/lv1 is now 2621440 blocks long.

看到LV1所挂载的分区已经变大:
[root@manager ~]# df -HT
/dev/mapper/vg1-lv1           ext4    11G  147M  9.9G   2% /test1
/dev/mapper/vg1-lv2           ext4   8.5G  158M  7.9G   2% /test2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息