Linux LVM扩容和缩容

Posted Cyber Security

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux LVM扩容和缩容相关的知识,希望对你有一定的参考价值。

将原硬盘上的LVM分区/dev/mapper/RHEL-Data由原来的60G扩展到80G

Step1:将LVData扩容+20G,如下图:

[[email protected] data]# lvextend -L +20G /dev/RHEL/Data
Size of logical volume RHEL/Data changed from 60.00 GiB (15360 extents) to 80.00 GiB (20480 extents).
Logical volume RHEL/Data successfully resized.
[[email protected] data]#

Step2:检查LV,如下图:

[[email protected] data]# e2fsck -f /dev/RHEL/Data
e2fsck 1.42.9 (28-Dec-2013)
/dev/RHEL/Data is mounted.
e2fsck: Cannot continue, aborting.

[[email protected] data]#

Step3:重新定义分区大小,如下图:

[[email protected] ~]# resize2fs /dev/RHEL/Data
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/RHEL/Data    //EXT4的扩容使用 resize2fs 
Couldn‘t find valid filesystem superblock.
[[email protected] ~]#

[[email protected] ~]# xfs_growfs /dev/RHEL/Data                                                               //XFS扩容使用xfs_growfs
meta-data=/dev/mapper/RHEL-Data isize=256 agcount=4, agsize=3932160 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=15728640, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=7680, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 15728640 to 20971520
[[email protected] ~]#

Step4:查看扩容后的分区容量,如下图:

[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.5M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 3.5G 41G 8% /
/dev/sda1 497M 164M 333M 33% /boot
/dev/mapper/centos-home 22G 33M 22G 1% /home
tmpfs 393M 0 393M 0% /run/user/1000
/dev/mapper/RHEL-Data 80G 21G 60G 26% /data                 //从原来60G扩展到了80G 

将原硬盘上的LVM分区/dev/mapper/RHEL-Data由原来的80G扩展到60G

e2fsck -f /dev/RHEL/Data  #检查磁盘错误 (针对ext4执行)

resize2fs /dev/RHEL/Data  60G #更新逻辑卷信息(针对ext4执行)

lvresize -L 20G /dev/RHEL/Data  #重新设定大小

注意:XFS文件系统不支持缩容。

 
































以上是关于Linux LVM扩容和缩容的主要内容,如果未能解决你的问题,请参考以下文章

ProxmoxVE删除local-lvm给local扩容,第二硬盘存放虚拟机

什么是逻辑卷管理器lvm?lvm设备的管理

centos lvm 扩容

Linux系统LVM(卷)部署-扩容-缩容-快照-删除

磁盘管理-lvm介绍

磁盘管理-lvm介绍