KVM 상의 Linux VM의 lvm 볼륨 사이즈 업을 하는 방법 안내

여기서는 19G -> 39G로 늘리는 것을 예제로 함.

.

서버 정보

KVM Hypervisor : kvm-host
VM : rocky88-mltest

현재 VM의 디스크(확장하고자 하는) 사이즈 확인 후 shutdown

[root@rocky88-mltest ~]# df -h | grep rocky-root
/dev/mapper/rocky-root 17G 3.3G 13G 21% /

[root@rocky88-mltest ~]# shutdown -h 0
(vm이 온라인 상태일 때 virt-filesystems 수행 시 vm의 /dev/sda에 확장이 반영되지 않음)

KVM 하이퍼바이저에서 해당 vm의 이미지 정보 확인

[root@kvm-host ~]# qemu-img info /nvme/vms/rocky-ml-test1698850995348.img
image: /nvme/vms/rocky-ml-test1698850995348.img
file format: qcow2
virtual size: 19G (20480000000 bytes)
disk size: 16G
cluster_size: 65536
Format specific information:
compat: 0.10

qcow2 image 파일 확장

[root@kvm-host ~]# qemu-img resize /nvme/vms/rocky-ml-test1698850995348.img +20G
Image resized.

[root@kvm-host ~]# qemu-img info /nvme/vms/rocky-ml-test1698850995348.img
image: /nvme/vms/rocky-ml-test1698850995348.img
file format: qcow2
virtual size: 39G (41954836480 bytes)
disk size: 16G
cluster_size: 65536
Format specific information:
compat: 0.10

vm의 디스크 확장

[root@kvm-host ~]# virt-filesystems --long --all -h -a /nvme/vms/rocky-ml-test1698850995348.img
Name             Type        VFS   Label  MBR  Size  Parent
/dev/sda1        filesystem  xfs   -      -    1.0G  -
/dev/rocky/root  filesystem  xfs   -      -    16G   -
/dev/rocky/swap  filesystem  swap  -      -    1.9G  -
/dev/rocky/root  lv          -     -      -    16G   /dev/rocky
/dev/rocky/swap  lv          -     -      -    1.9G  /dev/rocky
/dev/rocky       vg          -     -      -    18G   /dev/sda2
/dev/sda2        pv          -     -      -    18G   -
/dev/sda1        partition   -     -      83   1.0G  /dev/sda
/dev/sda2        partition   -     -      8e   18G   /dev/sda
/dev/sda         device      -     -      -    39G   -


[root@kvm-host ~]# qemu-img info /nvme/vms/rocky-ml-test1698850995348.img
image: /nvme/vms/rocky-ml-test1698850995348.img
file format: qcow2
virtual size: 39G (41954836480 bytes)
disk size: 16G
cluster_size: 65536
Format specific information:
compat: 0.10

파티션 확장

[root@rocky88-mltest ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 39.1G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 18.1G 0 part
├─rocky-root 253:0 0 16.2G 0 lvm /
└─rocky-swap 253:1 0 1.9G 0 lvm [SWAP]
sr0 11:0 1 11.6G 0 rom

[root@rocky88-mltest ~]# parted /dev/sda resizepart 2 100%
Information: You may need to update /etc/fstab.

[root@rocky88-mltest ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 39.1G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 38.1G 0 part
├─rocky-root 253:0 0 16.2G 0 lvm /
└─rocky-swap 253:1 0 1.9G 0 lvm [SWAP]
sr0 11:0 1 11.6G 0 rom

pv resize(extend)

[root@rocky88-mltest ~]# pvscan
PV /dev/sda2 VG rocky lvm2 [18.07 GiB / 0 free]
Total: 1 [18.07 GiB] / in use: 1 [18.07 GiB] / in no VG: 0 [0 ]

[root@rocky88-mltest ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rocky 1 2 0 wz--n- 18.07g 0

[root@rocky88-mltest ~]# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

[root@rocky88-mltest ~]# pvscan
PV /dev/sda2 VG rocky lvm2 [38.07 GiB / 20.00 GiB free]
Total: 1 [38.07 GiB] / in use: 1 [38.07 GiB] / in no VG: 0 [0 ]

lv resize(extend)

[root@rocky88-mltest ~]# lvscan
ACTIVE '/dev/rocky/swap' [1.91 GiB] inherit
ACTIVE '/dev/rocky/root' [16.16 GiB] inherit

[root@rocky88-mltest ~]# lvextend -r -l +100%FREE /dev/mapper/rocky-root
Size of logical volume rocky/root changed from 16.16 GiB (4137 extents) to 36.16 GiB (9257 extents).
Logical volume rocky/root successfully resized.
meta-data=/dev/mapper/rocky-root isize=512 agcount=4, agsize=1059072 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=4236288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4236288 to 9479168

[root@rocky88-mltest ~]# lvscan
ACTIVE '/dev/rocky/swap' [1.91 GiB] inherit
ACTIVE '/dev/rocky/root' [36.16 GiB] inherit

[root@rocky88-mltest ~]# df -h | grep rocky-root
/dev/mapper/rocky-root 37G 3.5G 33G 10% /

Extend qcow img on KVM and resize lvm on VM

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다