💡 主要过程跟CentOS扩容差不多,但也有些小地方要注意差异。
1.查看扩容前的磁盘容量,以及分区情况
fdisk -l
df -h
2.对扩容的磁盘分区
(1)磁盘分区命令,新增分区
输入n新增分区,默认为主分区,默认值直接敲回车就好
fdisk /dev/sda
n
(2)设置分区格式,在fdisk命令下输入 t ,回车默认值,然后输入 8e
8e是代表适用LVM分区类型
(3)最后写入分区表,在Fdisk命令位置输入:w
此时fdisk 再查看一下,发现多了一个分区,分区格式为LVM
fdisk -l
3、格式化磁盘,并分区
partprobe
mkfs.ext4 /dev/sda3
4、进入LVM合并磁盘
进入lvm,初始化 /dev/sda3,将新分区添加进系统默认的Volume group,Rocky Linux的默认Volume group为 rl
lvm
pvcreate /dev/sda3
vgextend rl /dev/sda3
查看一下当前的Volume卷详情
vgdisplay -v
将系统盘/dev/mapper/rl-root与sda3的2559空余容量合并
lvextend -l +2559 /dev/mapper/rl-root
quit
5.最后让系统识别就行了
xfs_growfs /dev/mapper/rl-root
6.结束,再用fdisk -l命令,以及df -h命令查看一下效果:
fdisk -l
df -h
最后附上操作log:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xeaed9efd
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 41943039 39843840 19G 8e Linux LVM
Disk /dev/mapper/rl-root: 17 GiB, 18249416704 bytes, 35643392 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/rl-swap: 2 GiB, 2147483648 bytes, 4194304 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
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (3,4, default 3):
First sector (41943040-62914559, default 41943040):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (41943040-62914559, default 62914559):
Created a new partition 3 of type 'Linux' and of size 10 GiB.
Command (m for help): t
Partition number (1-3, default 3):
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xeaed9efd
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 41943039 39843840 19G 8e Linux LVM
/dev/sda3 41943040 62914559 20971520 10G 8e Linux LVM
Disk /dev/mapper/rl-root: 17 GiB, 18249416704 bytes, 35643392 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/rl-swap: 2 GiB, 2147483648 bytes, 4194304 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
[root@localhost ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@localhost ~]# mkfs.ext4 /dev/sda3
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 2621440 4k blocks and 655360 inodes
Filesystem UUID: c673720a-efd1-4770-993c-93ae44ceb0c0
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# lvm
lvm> pvcreate /dev/sda3
WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
lvm> vgextend rl /dev/sda3
Volume group "rl" successfully extended
lvm> vgdisplay -v
--- Volume group ---
VG Name rl
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 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 2559 / <10.00 GiB
VG UUID cYoE62-sQ6X-lVf0-XAu7-z2gK-Ro3g-NrlOAx
--- Logical volume ---
LV Path /dev/rl/swap
LV Name swap
VG Name rl
LV UUID irNT0l-i7Gp-EZhv-SxZE-Yqs9-ed8w-bP1BjR
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-07-09 11:18:48 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/rl/root
LV Name root
VG Name rl
LV UUID Hwb7Vm-DW0i-YAdX-gqHs-ThT5-Z9Ku-AMkCPx
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-07-09 11:18:48 +0800
LV Status available
# open 1
LV Size <17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID Dtz0ky-SqCn-t1d4-3DEf-VBM9-SdvC-C2l24g
PV Status allocatable
Total PE / Free PE 4863 / 0
PV Name /dev/sda3
PV UUID SFTVTo-oxx7-dafx-XzFC-yH2c-Vtfh-yhmX9B
PV Status allocatable
Total PE / Free PE 2559 / 2559
lvm> lvextend -l +2559 /dev/mapper/rl-root
Size of logical volume rl/root changed from <17.00 GiB (4351 extents) to 26.99 GiB (6910 extents).
Logical volume rl/root successfully resized.
lvm> quit
Exiting.
[root@localhost ~]# xfs_growfs /dev/mapper/rl-root
meta-data=/dev/mapper/rl-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1 nrext64=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 7075840
[root@localhost ~]#
[root@localhost ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xeaed9efd
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 41943039 39843840 19G 8e Linux LVM
/dev/sda3 41943040 62914559 20971520 10G 8e Linux LVM
Disk /dev/mapper/rl-root: 26.99 GiB, 28982640640 bytes, 56606720 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/rl-swap: 2 GiB, 2147483648 bytes, 4194304 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
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 732M 8.7M 724M 2% /run
/dev/mapper/rl-root 27G 1.4G 26G 5% /
/dev/sda1 960M 225M 736M 24% /boot
tmpfs 366M 0 366M 0% /run/user/0
[root@localhost ~]#