记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux主机扩容homelv的方法,其他扩容lv的方法也是类似,欢迎大家评论留言,本次操作是在线扩容homelv,其他扩容lv的方法也类似。(以下是扩容homelv的操作,均在试验机上操作,并且在实际工程环境中有验证过,目前配置过的OS有centos7.7)。
一、主机环境:
1、系统版本:
root@xuhs:/root>cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
root@xuhs:/root>
2、系统环境中分区、pv、vg、lv如下:
root@xuhs:/root>lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
homelv hdvg -wi-ao---- <1.19g
rootlv hdvg -wi-ao---- <12.22g
swaplv hdvg -wi-ao---- 2.00g
tmplv hdvg -wi-ao---- <1.19g
varloglv hdvg -wi-ao---- <1.19g
varlv hdvg -wi-ao---- <1.19g
root@xuhs:/root>
root@xuhs:/root>pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 hdvg lvm2 a-- <18.97g 0
root@xuhs:/root>
root@xuhs:/root>vgs
VG #PV #LV #SN Attr VSize VFree
hdvg 1 6 0 wz--n- <18.97g 0
root@xuhs:/root>
root@xuhs:/root>fdisk -l
......
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
......
二、操作:
1、因为整个/dev/sdb都要划分给homelv,我们直接创建pv:
root@xuhs:/root>pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 hdvg lvm2 a-- <18.97g 0
root@xuhs:/root>
root@xuhs:/root>pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
root@xuhs:/root>
root@xuhs:/root>pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 hdvg lvm2 a-- <18.97g 0
/dev/sdb lvm2 --- 10.00g 10.00g
2、创建vg:
root@xuhs:/root>vgs
VG #PV #LV #SN Attr VSize VFree
hdvg 1 6 0 wz--n- <18.97g 0
root@xuhs:/root>
root@xuhs:/root>vgextend hdvg /dev/sdb
Volume group "hdvg" successfully extended
root@xuhs:/root>
root@xuhs:/root>vgs
VG #PV #LV #SN Attr VSize VFree
hdvg 2 6 0 wz--n- <28.94g <9.97g
3、创建lv,本次扩容homelv,扩容其他lv也是同样的方法,如下:
root@xuhs:/root>lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
homelv hdvg -wi-ao---- <1.19g
rootlv hdvg -wi-ao---- <12.22g
swaplv hdvg -wi-ao---- 2.00g
tmplv hdvg -wi-ao---- <1.19g
varloglv hdvg -wi-ao---- <1.19g
varlv hdvg -wi-ao---- <1.19g
root@xuhs:/root>
root@xuhs:/root>lvextend -L +8G /dev/hdvg/homelv
Size of logical volume hdvg/homelv changed from <1.19 GiB (38 extents) to <9.19 GiB (294 extents).
Logical volume hdvg/homelv successfully resized.
root@xuhs:/root>
root@xuhs:/root>lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
homelv hdvg -wi-ao---- <9.19g
rootlv hdvg -wi-ao---- <12.22g
swaplv hdvg -wi-ao---- 2.00g
tmplv hdvg -wi-ao---- <1.19g
varloglv hdvg -wi-ao---- <1.19g
varlv hdvg -wi-ao---- <1.19g
以上我们可以看出已经成功扩容了homelv。
4、这时我们通过df -h查看还是显示扩容前的大小,需要使用xfs_growfs生效配置,操作如下:
root@xuhs:/root>df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.0M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/hdvg-rootlv 13G 5.2G 7.1G 43% /
/dev/sda1 1014M 171M 844M 17% /boot
/dev/mapper/hdvg-homelv 1.2G 33M 1.2G 3% /home
/dev/mapper/hdvg-varlv 1.2G 230M 977M 20% /var
/dev/mapper/hdvg-tmplv 1.2G 33M 1.2G 3% /tmp
/dev/mapper/hdvg-varloglv 1.2G 34M 1.2G 3% /var/log
tmpfs 98M 0 98M 0% /run/user/0
root@xuhs:/root>
root@xuhs:/root>xfs_growfs /dev/hdvg/homelv
meta-data=/dev/mapper/hdvg-homelv isize=512 agcount=4, agsize=77824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=311296, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 311296 to 2408448
root@xuhs:/root>
5、再次使用df -h查看后显示正常,现象如下:
root@xuhs:/root>df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.0M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/hdvg-rootlv 13G 5.2G 7.1G 43% /
/dev/sda1 1014M 171M 844M 17% /boot
/dev/mapper/hdvg-homelv 9.2G 34M 9.2G 1% /home
/dev/mapper/hdvg-varlv 1.2G 230M 977M 20% /var
/dev/mapper/hdvg-tmplv 1.2G 33M 1.2G 3% /tmp
/dev/mapper/hdvg-varloglv 1.2G 34M 1.2G 3% /var/log
tmpfs 98M 0 98M 0% /run/user/0
三、xfs_growfs命令
1、xfs_growfs是用来干什么?
root@xuhs:/root>man xfs_growfs
NAME
xfs_growfs, xfs_info - expand an XFS filesystem
DESCRIPTION
xfs_growfs expands an existing XFS filesystem (see xfs(5)). The mount-point argument is the pathname of the directory where the filesystem is
mounted. The filesystem must be mounted to be grown (see mount(8)). The existing contents of the filesystem are undisturbed, and the added
space becomes available for additional file storage.
xfs_growfs也就是说是扩展XFS文件系统用的,使用xfs_growfs这个命令,文件系统的现有内容不会受到干扰。感兴趣的朋友可以自己去研究一下。
2、语法:
xfs_growfs [ 参数 ] mount-point
如:
xfs_growfs /dev/hdvg/homelv
中间的一些参数我们可以省略,感兴趣的朋友可以自己去研究。