大家好,欢迎来到IT知识分享网。
LVM磁盘扩容
一、基本概念熟悉
LVM是 Logical Volume Manager(逻辑卷管理)它是Linux环境下对磁盘分区进行管理的一种机制。
LVM 的核心概念有:
- 物理卷 (PV): 一块物理硬盘, 或者硬盘上的一个分区. 也就是底层的物理存储设备.
- 卷组 (VG): 多个 PV 组成的一个存储池, 相当于一块虚拟大硬盘.
- 逻辑卷 (LV): 从 VG 之中划分, 相当于一个虚拟分区
二、LVM扩容
Linux操作系统运行一段时间后,磁盘空间不足,需进行扩容。现将扩容过程进行记录。
1. 记录扩容前磁盘使用情况
查看磁盘分区情况:
[root@PAGL-FXQ-TEST ~]# fdisk -l Disk /dev/vda: 1099.5 GB, 76 bytes, 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: 0x000a9d54 Device Boot Start End Blocks Id System /dev/vda1 * 2048 83 Linux /dev/vda2 8e Linux LVM Disk /dev/mapper/centos-root: 2181.0 GB, 92 bytes, 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 /dev/mapper/centos-swap: 16.9 GB, bytes, 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 /dev/vdb: 1099.5 GB, 76 bytes, 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: 0x3cfffab4 Device Boot Start End Blocks Id System /dev/vdb1 2048 83 Linux
查看pv、vg、lv 情况(清楚pv的剩余情况;vg的名称和剩余情况;lv名称和剩余情况)
[root@PAGL-FXQ-TEST ~]# pvs PV VG Fmt Attr PSize PFree /dev/vda2 centos lvm2 a-- <1023.00g 0 /dev/vdb1 centos lvm2 a-- <1024.00g 0 [root@PAGL-FXQ-TEST ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- <2.00t 0 [root@PAGL-FXQ-TEST ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 1.98t swap centos -wi-ao---- 15.75g
列出所有块设备的基本信息,包括设备名、大小和挂载点等
[root@PAGL-FXQ-TEST ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 4.4G 0 rom /mnt/cdrom vda 252:0 0 1T 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 1023G 0 part ├─centos-root 253:0 0 2T 0 lvm / └─centos-swap 253:1 0 15.8G 0 lvm [SWAP] vdb 252:16 0 1T 0 disk └─vdb1 252:17 0 1024G 0 part └─centos-root 253:0 0 2T 0 lvm /
查看磁盘空间占用情况(知道根分区空间占93%,空间严重不足)
[root@PAGL-FXQ-TEST ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 16G 0 16G 0% /dev tmpfs 16G 9.3M 16G 1% /dev/shm tmpfs 16G 1.5G 15G 10% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/mapper/centos-root 2.0T 1.9T 148G 93% / /dev/vda1 1014M 202M 813M 20% /boot tmpfs 3.2G 52K 3.2G 1% /run/user/0 /dev/sr0 4.4G 4.4G 0 100% /mnt/cdrom
2. 虚拟机添加磁盘
3. 添加磁盘后检查
可以看出多了/dev/vdc磁盘,如下:
[root@PAGL-FXQ-TEST ~]# fdisk -l Disk /dev/vda: 1099.5 GB, 76 bytes, 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: 0x000a9d54 Device Boot Start End Blocks Id System /dev/vda1 * 2048 83 Linux /dev/vda2 8e Linux LVM Disk /dev/mapper/centos-root: 2181.0 GB, 92 bytes, 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 /dev/mapper/centos-swap: 16.9 GB, bytes, 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 /dev/vdb: 1099.5 GB, 76 bytes, 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: 0x3cfffab4 Device Boot Start End Blocks Id System /dev/vdb1 2048 83 Linux Disk /dev/vdc: 2199.0 GB, 52 bytes, 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
4.将新硬盘分区初始化
[root@PAGL-FXQ-TEST centos]# pvcreate /dev/vdc Physical volume "/dev/vdc" successfully created. [root@PAGL-FXQ-TEST centos]# pvs PV VG Fmt Attr PSize PFree /dev/vda2 centos lvm2 a-- <1023.00g 0 /dev/vdb1 centos lvm2 a-- <1024.00g 0 /dev/vdc lvm2 --- 2.00t 2.00t
5.将初始化后的分区添加到VG中
[root@PAGL-FXQ-TEST centos]# vgextend centos /dev/vdc Volume group "centos" successfully extended [root@PAGL-FXQ-TEST centos]# vgs VG #PV #LV #SN Attr VSize VFree centos 3 2 0 wz--n- <4.00t <2.00t
5.将VG分配给lv
lvm的名称为/dev/centos/root
[root@PAGL-FXQ-TEST centos]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 1.98 TiB ( extents) to 3.98 TiB ( extents). Logical volume centos/root successfully resized. [root@PAGL-FXQ-TEST centos]# vgs VG #PV #LV #SN Attr VSize VFree centos 3 2 0 wz--n- <4.00t 0 [root@PAGL-FXQ-TEST centos]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 3.98t swap centos -wi-ao---- 15.75g
6.扩展文件系统
注意:lvextend扩展后只是扩展了lv的大小,而此时文件系统并未感知到,所有还需要使用xfs_growfs、resize2fs等命令来扩展文件系统,xfs_growf命令是扩展xfs文件系统,resize2fs是扩展ext4文件系统。
[root@PAGL-FXQ-TEST centos]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=9, agsize= blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from to [root@PAGL-FXQ-TEST centos]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 16G 0 16G 0% /dev tmpfs 16G 9.3M 16G 1% /dev/shm tmpfs 16G 1.5G 15G 10% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/mapper/centos-root 4.0T 1.9T 2.2T 47% / /dev/vda1 1014M 202M 813M 20% /boot tmpfs 3.2G 52K 3.2G 1% /run/user/0 /dev/sr0 4.4G 4.4G 0 100% /mnt/cdrom
扩容成功!!
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/114907.html
