扩盘操作LVM扩容操作-Centos7
Posted jerry-89
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了扩盘操作LVM扩容操作-Centos7相关的知识,希望对你有一定的参考价值。
生产环境要扩容,太久没试过LVM,记录一下走过的坑
[root@archive ~]# df -h #查看磁盘挂载,对/dev/mapper/vgnfs-lvdata进行扩容
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 909M 0 909M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 8.6M 911M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/vda2 39G 1.5G 38G 4% /
/dev/vda1 1014M 199M 816M 20% /boot
/dev/mapper/vgnfs-lvdata 290G 30G 261G 11% /nfs
tmpfs 184M 0 184M 0% /run/user/0
[root@archive ~]# fdisk /dev/vdc #分区新磁盘
参考:16TB以后磁盘挂载方法https://blog.csdn.net/eagle89/article/details/128010462
[root@archive ~]# pvcreate /dev/vdc1 #创建PV
Physical volume "/dev/vdc1" successfully created.
[root@archive ~]# vgdisplay
[root@archive ~]# vgextend vgnfs /dev/vdc1 #将新的pv加入到vgnfs组内
Volume group "vgnfs" successfully extended
[root@archive ~]# pvs #查看pv信息
[root@archive ~]# lvdisplay #查看LV信息
[root@archive ~]# lvextend -L +99G /dev/vgnfs/lvdata #将lvdata增加99G,这里少个+号会很坑
Size of logical volume vgnfs/lvdata changed from 290.00 GiB (74240 extents) to 389.00 GiB (99584 extents).
Logical volume vgnfs/lvdata successfully resized.
注:
虚拟机下LVM报错信息Insufficient free space
Insufficient free space: 51200 extents needed, but only 51199 available
要添加一块200G的磁盘到LVM中去,前面操作很容易就通过了
在lvextend -L +200G /dev/localhost/root 时报错,报错信息如下
Insufficient free space: 51200 extents needed, but only 51199 available
报错大概意思 是只有51199×4Mib/1024可用,无法扩展51200×4Mib。
计算了一下 51199×4Mib/1024 大概等于199.99GB
修改命令
lvextend -L +200G /dev/localhost/root
[root@archive ~]# xfs_growfs /dev/vgnfs/lvdata #同步文件系统
meta-data=/dev/mapper/vgnfs-lvdata isize=512 agcount=4, agsize=19005440 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=76021760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=37120, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 76021760 to 101974016
注:
问题描述
使用xfs_growfs命令在线扩容CentOS 8系统盘,出现以下错误信息。
xfs_growfs:/dev/vda1 is not a mounted XFS filesystem
问题原因
新旧版本的xfs_growfs
命令使用问题。新版的xfs_growfs
命令后面的参数需要为文件系统挂载点,而非文件系统本身。
解决方案
阿里云提醒您:
- 如果您对实例或数据有修改、变更等风险操作,务必注意实例的容灾、容错能力,确保数据安全。
- 如果您对实例(包括但不限于ECS、RDS)等进行配置与数据修改,建议提前创建快照或开启RDS日志备份等功能。
- 如果您在阿里云平台授权或者提交过登录账号、密码等安全信息,建议您及时修改。
- 系统盘默认挂载点为根目录,因此,执行以下命令即可。
说明:
- 您也可以运行
xfs_growfs --help
,查看当前版本xfs_growfs
的使用方法。 - 系统盘挂载点请以实际环境为准。
xfs_growfs /
系统显示类似如下。 - 您也可以运行
- 如果是扩容数据盘场景,例如数据盘挂载在
/mnt
目录,则执行以下命令即可。xfs_growfs /mnt
[root@archive ~]#
[root@archive ~]# df -h #扩容后查看
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 909M 0 909M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 8.6M 911M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/vda2 39G 1.5G 38G 4% /
/dev/vda1 1014M 199M 816M 20% /boot
/dev/mapper/vgnfs-lvdata 389G 30G 360G 8% /nfs
tmpfs 184M 0 184M 0% /run/user/0
LVM扩容是运维工作常有的活,记录一下,在使用lvextend扩容的时候,必须用到+号,否则会有下面的错误:
[root@archive ~]# lvextend -L 99G /dev/vgnfs/lvdata
New size given (25344 extents) not larger than existing size (74240 extents)
说明:最新指定的硬盘大小不大于原来分区大小,extend是进行扩大硬盘大小,这里指定的大小比原分区大小还要小,所以报错。这里如果需要增加lv的大小,是需要用+号进行指定的,这里要非常注意。
在扩容lv之后,会出现同步文件系统的操作,由于这里centos7使用了xfs的文件系统,是不能用resize2fs进行同步操作的。需要用到xfs_grows命令。说明:
如果使用xfs文件系统
xfs_growfs /dev/vgnfs/lvdata
如果使用ext4 ext3文件系统
resize2fs /dev/vgnfs/lvdata
CentOS7 基于lvm扩容根目录
Linux操作系统安装好之后,可以通过 df -h 命令查看磁盘挂载信息和空间使用率
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 60K 7.8G 1% /dev/shm tmpfs 7.8G 9.0M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/mapper/centos-root 46G 6.6G 40G 15% / /dev/sda1 197M 166M 32M 84% /boot tmpfs 1.6G 0 1.6G 0% /run/user/1000 tmpfs 1.6G 0 1.6G 0% /run/user/0
如上所示,磁盘根目录只有不到50G,根据实际业务需要将磁盘空间扩容到200G,如果是物理机只能增加磁盘,如果是虚拟机则可以直接扩容。
具体操作步骤如下
1.分区 fdisk命令
[root@localhost ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n #创建一个新分区
分区创建后需要将新的分区信息刷新到内核中,可执行两次,确保生效
[root@localhost ~]# partprobe
查看分区信息
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk 忖sda1 8:1 0 200M 0 part /boot 忖sda2 8:2 0 49.8G 0 part ?忖centos-root 253:0 0 45.8G 0 lvm / ?忖centos-swap 253:1 0 4G 0 lvm [SWAP] 忖sda3 8:3 0 150G 0 part sr0 11:0 1 1024M 0 rom [root@localhost ~]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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 Disk label type: dos Disk identifier: 0x000a3b4c Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 104857599 52222976 8e Linux LVM /dev/sda3 104857600 419430399 157286400 8e Linux LVM
2.格式化 /dev/sda3
[root@localhost ~]# mkfs.xfs /dev/sda3 meta-data=/dev/sda3 isize=512 agcount=4, agsize=9830400 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=39321600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=19200, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
3.创建物理卷pv
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 49.80 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 12749 Free PE 0 Allocated PE 12749 PV UUID 7EnsrT-fESl-zmbK-3F1p-Y3rH-QZIz-m9oe1T [root@localhost ~]# pvcreate /dev/sda3 WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sda3. Physical volume "/dev/sda3" successfully created. [root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size 49.80 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 12749 Free PE 0 Allocated PE 12749 PV UUID 7EnsrT-fESl-zmbK-3F1p-Y3rH-QZIz-m9oe1T --- Physical volume --- PV Name /dev/sda3 VG Name centos PV Size 150.00 GiB / not usable 4.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 38399 Free PE 0 Allocated PE 38399 PV UUID YRcEFb-fW4e-GOKO-jjK2-QGyS-SRQ7-Uv3ZQu
4.将物理卷添加到卷组vg
[root@localhost ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 49.80 GiB PE Size 4.00 MiB Total PE 12749 Alloc PE / Size 12749 / 49.80 GiB Free PE / Size 0 / 0 VG UUID chkr0E-Tgym-oiZ3-3fsp-Fe4C-3EOT-fcZGiL [root@localhost ~]# vgextend centos /dev/sda3 Volume group "centos" successfully extended [root@localhost ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size <199.80 GiB PE Size 4.00 MiB Total PE 51148 Alloc PE / Size 12749 / 49.80 GiB Free PE / Size 38399 / <150.00 GiB VG UUID chkr0E-Tgym-oiZ3-3fsp-Fe4C-3EOT-fcZGiL
5.扩容逻辑卷lv
[root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID sFhcD2-fltF-S1sY-p3Gu-OR2j-Entv-HJ1u0f LV Write Access read/write LV Creation host, time localhost, 2018-11-24 00:21:24 +0800 LV Status available # open 2 LV Size 4.00 GiB Current LE 1024 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID VB75Pk-eCAN-gZtR-HboO-PBNF-1Kf9-Esw3dX LV Write Access read/write LV Creation host, time localhost, 2018-11-24 00:21:24 +0800 LV Status available # open 1 LV Size 45.80 GiB Current LE 11725 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@localhost ~]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 45.80 GiB (11725 extents) to <195.80 GiB (50124 extents). Logical volume centos/root successfully resized. [root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID sFhcD2-fltF-S1sY-p3Gu-OR2j-Entv-HJ1u0f LV Write Access read/write LV Creation host, time localhost, 2018-11-24 00:21:24 +0800 LV Status available # open 2 LV Size 4.00 GiB Current LE 1024 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID VB75Pk-eCAN-gZtR-HboO-PBNF-1Kf9-Esw3dX LV Write Access read/write LV Creation host, time localhost, 2018-11-24 00:21:24 +0800 LV Status available # open 1 LV Size <195.80 GiB Current LE 50124 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
6.重新识别分区
[root@localhost ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3001600 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=12006400, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5862, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 12006400 to 51326976 [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 60K 7.8G 1% /dev/shm tmpfs 7.8G 9.0M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/mapper/centos-root 196G 6.6G 190G 4% / /dev/sda1 197M 166M 32M 84% /boot tmpfs 1.6G 0 1.6G 0% /run/user/1000 tmpfs 1.6G 0 1.6G 0% /run/user/0
通过 df -h 命令可以看到根目录已成功扩容到200G,且扩容后无需重启机器,不得不说,lvm确认强。
以上是关于扩盘操作LVM扩容操作-Centos7的主要内容,如果未能解决你的问题,请参考以下文章
基于CentOS 6 系统创建逻辑卷LVM,执行扩容,缩减,删除等操作