Oracle Linux 8擴充位於LVM下的root partition,file system為XFS
下列的例子由~50G變成~60G
先檢查目前的Disk狀態:
[root@db01 ~]# sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 190M 0 part /boot/efi
├─sda2 8:2 0 953M 0 part /boot
└─sda3 8:3 0 48.9G 0 part
├─ol-root 252:0 0 45.2G 0 lvm /
└─ol-swap 252:1 0 3.7G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
檢查PV/VG狀態
[root@db01 ~]# sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ol lvm2 a-- <48.88g 0
OS關機,擴充Disk,這時可以看到sda的大小由50變成60G
[root@db01 ~]# sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 190M 0 part /boot/efi
├─sda2 8:2 0 953M 0 part /boot
└─sda3 8:3 0 48.9G 0 part
├─ol-root 252:0 0 45.2G 0 lvm /
└─ol-swap 252:1 0 3.7G 0 lvm [SWAP]
sr0 11:0 1 11.6G 0 rom
另外,可以看/proc/partitions的檔案做double check
[root@db01 ~]# cat /proc/partitions
major minor #blocks name
8 0 62914560 sda
8 1 194560 sda1
8 2 975872 sda2
8 3 51256320 sda3
11 0 12123136 sr0
252 0 47345664 dm-0
252 1 3907584 dm-1
安裝growpart
[root@db01 ~]# sudo yum -y install cloud-utils-growpart
Last metadata expiration check: 0:18:22 ago on Thu 01 Feb 2024 09:12:18 AM CST.
Dependencies resolved.
====================================================================================================
Package Architecture Version Repository Size
====================================================================================================
Installing:
cloud-utils-growpart noarch 0.33-0.el8 ol8_appstream 36 k
Transaction Summary
====================================================================================================
Install 1 Package
Total download size: 36 k
Installed size: 75 k
Downloading Packages:
cloud-utils-growpart-0.33-0.el8.noarch.rpm 102 kB/s | 36 kB 00:00
----------------------------------------------------------------------------------------------------
Total 100 kB/s | 36 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : cloud-utils-growpart-0.33-0.el8.noarch 1/1
Running scriptlet: cloud-utils-growpart-0.33-0.el8.noarch 1/1
Verifying : cloud-utils-growpart-0.33-0.el8.noarch 1/1
Installed:
cloud-utils-growpart-0.33-0.el8.noarch
Complete!
再次double check空間大小
[root@db01 ~]# sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 190M 0 part /boot/efi
├─sda2 8:2 0 953M 0 part /boot
└─sda3 8:3 0 48.9G 0 part
├─ol-root 252:0 0 45.2G 0 lvm /
└─ol-swap 252:1 0 3.7G 0 lvm [SWAP]
sr0 11:0 1 11.6G 0 rom
==> /dev/sda3 (sda的第三個partition是要擴充的LVM,等一下下指令時,要指定為 /dev/sda 3)
擴大partition
[root@db01 ~]# sudo growpart /dev/sda 3
CHANGED: partition=3 start=2342912 old: size=102512640 end=104855551 new: size=123486175 end=125829086
[root@db01 ~]# sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 190M 0 part /boot/efi
├─sda2 8:2 0 953M 0 part /boot
└─sda3 8:3 0 58.9G 0 part
├─ol-root 252:0 0 45.2G 0 lvm /
└─ol-swap 252:1 0 3.7G 0 lvm [SWAP]
sr0 11:0 1 11.6G 0 rom
Resize PV
[root@db01 ~]# sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@db01 ~]# sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ol lvm2 a-- <58.88g 10.00g
[root@db01 ~]# sudo vgs
VG #PV #LV #SN Attr VSize VFree
ol 1 2 0 wz--n- <58.88g 10.00g
查詢要擴充的LV之device name
[root@db01 ~]# df -hT | grep mapper
/dev/mapper/ol-root xfs 46G 38G 8.0G 83% /
擴大lv
[root@db01 ~]# sudo lvextend -r -l +100%FREE /dev/mapper/ol-root
Size of logical volume ol/root changed from 45.15 GiB (11559 extents) to 55.15 GiB (14119 extents).
Logical volume ol/root successfully resized.
meta-data=/dev/mapper/ol-root isize=512 agcount=4, agsize=2959104 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=11836416, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=5779, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11836416 to 14457856
檢查disk size (這時disk已放大)
[root@db01 ~]# df -hT | grep mapper
/dev/mapper/ol-root xfs 56G 38G 18G 68% /
如果沒放大,可用下列指令
[root@db01 ~]# xfs_growfs /dev/mapper/ol-root
meta-data=/dev/mapper/ol-root isize=512 agcount=5, agsize=2959104 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=14457856, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=5779, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
留言