Centos 使用空磁盘扩展xfs文件系统root分区
- 1.查看硬盘信息
- [2.将 /dev/sdb 添加到 LVM 卷组中](#2.将 /dev/sdb 添加到 LVM 卷组中)
-
- [1. 初始化物理卷](#1. 初始化物理卷)
- [2. 将物理卷添加到卷组](#2. 将物理卷添加到卷组)
- 3.扩展逻辑卷
- 4.验证
-
- [1. 查看分区和文件系统信息](#1. 查看分区和文件系统信息)
- [2. 查看逻辑卷信息](#2. 查看逻辑卷信息)
1.查看硬盘信息
javascript
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 198.4G 0 part
├─cl-root 253:0 0 176.4G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 20G 0 lvm /home
sdb 8:16 0 20G 0 disk
sr0 11:0 1 10.1G 0 rom
#空磁盘为sdb
2.将 /dev/sdb 添加到 LVM 卷组中
1. 初始化物理卷
将 /dev/sdb 初始化为物理卷:
javascript
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
2. 将物理卷添加到卷组
假设你的卷组名为 cl,将新物理卷添加到卷组:
javascript
[root@localhost ~]# vgextend cl /dev/sdb
Volume group "cl" successfully extended
3.扩展逻辑卷
1.扩展逻辑卷:
扩展 /root 分区的逻辑卷,假设你要将所有可用空间分配给 /root:
javascript
[root@localhost ~]# lvextend -l +100%FREE /dev/cl/root
Size of logical volume cl/root changed from <176.38 GiB (45153 extents) to <196.38 GiB (50272 extents).
Logical volume cl/root successfully resized.
2.扩展xfs文件系统:
扩展文件系统以使用新分配的空间。由于 /root 分区使用的是 XFS 文件系统,使用 xfs_growfs 命令:
javascript
[root@localhost ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root isize=512 agcount=11, agsize=4587520 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=46236672, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=8960, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 46236672 to 51478528
4.验证
1. 查看分区和文件系统信息
确认 /root 分区的大小已经更新:
javascript
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 895M 0 895M 0% /dev/shm
tmpfs tmpfs 895M 8.7M 887M 1% /run
tmpfs tmpfs 895M 0 895M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 197G 4.7G 192G 3% /
/dev/mapper/cl-home xfs 20G 175M 20G 1% /home
/dev/sda2 xfs 1014M 213M 802M 21% /boot
/dev/sda1 vfat 599M 7.3M 592M 2% /boot/efi
tmpfs tmpfs 179M 0 179M 0% /run/user/0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 198.4G 0 part
├─cl-root 253:0 0 196.4G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 20G 0 lvm /home
sdb 8:16 0 20G 0 disk
└─cl-root 253:0 0 196.4G 0 lvm /
sr0 11:0 1 10.1G 0 rom
2. 查看逻辑卷信息
检查逻辑卷的详细信息,以确认扩展已成功:
javascript
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID gX9aeL-1Y8m-tGCz-Euka-YynN-SeY4-ecOMWu
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-08-01 23:03:22 -0400
LV Status available
# open 1
LV Size <196.38 GiB
Current LE 50272
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/cl/home
LV Name home
VG Name cl
LV UUID dHsXfZ-okNT-82gk-6ed5-oXlP-BxUQ-rQV3xB
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-08-01 23:03:22 -0400
LV Status available
# open 1
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID SDh6NB-5tsS-Sdd6-uYpz-ygNi-bKiF-lU5hqn
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-08-01 23:03:23 -0400
LV Status available
# open 2
LV Size 2.03 GiB
Current LE 520
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1