扩展逻辑卷:(支持在线扩展)
[root@linuxidc ~]# lvextend -L +30G /dev/vg0/lv0
Size of logical volume vg0/lv0 changed from 80.00 GiB (20480 extents) to 110.00 GiB (28160 extents).
Logical volume lv0 successfully resized.##o扩展成功
[root@linuxidc ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv0 vg0 -wi-ao---- 110.00g
[root@linuxidc ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 94G 3.2G 90G 4% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 489M 84K 489M 1% /dev/shm
tmpfs 489M 7.1M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda5 19G 33M 19G 1% /testdir
##lv已经扩展成功了,但是我们文件系统中的大小没加大,所以我么还需要处理下。
[root@linuxidc ~]# resize2fs /dev/vg0/lv0 ##通过此命令让文件系统容量确实增大
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv0 is mounted on /lvmtest; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 14
The filesystem on /dev/vg0/lv0 is now 28835840 blocks long.
[root@linuxidc ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 94G 3.2G 90G 4% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 489M 84K 489M 1% /dev/shm
tmpfs 489M 7.1M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda5 19G 33M 19G 1% /testdir
/dev/sda1 473M 153M 321M 33% /boot
tmpfs 98M 16K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg0-lv0 109G 60M 104G 1% /lvmtest ### ok显示现在已经是110G
缩减逻辑卷:(不支持在线扩展,必须先卸载)
确保缩减后的空间可以存储原来所有数据。并且在缩减前先要进行强制检查,确保文件系统处于一致状态
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 [root@linuxidc ~]# umount /lvmtest/##卸载
[root@linuxidc ~]# e2fsck -f /dev/vg0/lv0 ##强行检查文件系统
e2fsck 1.42.9 (28-Dec-2013)
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/lv0: 12/7208960 files (0.0% non-contiguous), 500575/28835840 blocks
[root@linuxidc ~]# resize2fs /dev/vg0/lv0 5G ##缩减逻辑空间到5G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 1310720 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 1310720 blocks long.
[root@linuxidc ~]# lvreduce -L 5G /dev/vg0/lv0 ##缩减逻辑空间到5G
WARNING: Reducing active logical volume to 5.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv0? [y/n]: y #输入y同意
Size of logical volume vg0/lv0 changed from 110.00 GiB (28160 extents) to 5.00 GiB (1280 extents).
Logical volume lv0 successfully resized.##缩减成功
[root@linuxidc ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv0 vg0 -wi-a----- 5.00g ##查看lv已经变成5G大小了
[root@linuxidc ~]# mount /dev/vg0/lv0 /lvmtest/##重新挂载我么的文件系统
[root@linuxidc ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 94G 3.2G 90G 4% /
devtmpfs 475M 0 475M 0% /dev
tmpfs 489M 84K 489M 1% /dev/shm
tmpfs 489M 7.1M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda5 19G 33M 19G 1% /testdir
/dev/sda1 473M 153M 321M 33% /boot
tmpfs 98M 16K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg0-lv0 4.8G 33M 4.6G 1% /lvmtest
[root@linuxidc ~]# cd /lvmtest/
[root@linuxidc lvmtest]# ls
lost+found lvmtest1#####测试看ok没有问,数据没损坏。