## shutdown the VM first before resize the virtual disk
tyla@e32:~$ virsh shutdown almalinux8
Domain 'almalinux8' is being shutdown
## resize the .qcow2 file on host machine
tyla@e32:~$ sudo qemu-img resize /data/kvm/almalinux8.qcow2 +4G
Image resized.
## verify if the virtual size is now 25 GB
tyla@e32:~$ sudo qemu-img info /data/kvm/almalinux8.qcow2
image: /data/kvm/almalinux8.qcow2
file format: qcow2
virtual size: 25 GiB (26843545600 bytes)
disk size: 2.63 GiB
cluster_size: 65536
Format specific information:
compat: 1.1
compression type: zlib
lazy refcounts: true
refcount bits: 16
corrupt: false
extended l2: false
Child node '/file':
filename: /data/kvm/almalinux8.qcow2
protocol type: file
file length: 20 GiB (21478375424 bytes)
disk size: 2.63 GiB
## start the VM
tyla@e32:~$ virsh start almalinux8
Domain 'almalinux8' started
## verify if the VM is running
tyla@e32:~$ virsh list
Id Name State
----------------------------
9 almalinux8 running
fdisk ကိုပဲအသုံးပြုပြီး /dev/vda disk ရဲ့ /dev/vda1 partition ကိုအရင်ဆုံး resize လုပ်ဖို့လိုပါလိမ့်မယ်။ ကိုယ်ပြင်ချင်တဲ့ partition ကိုပထမဆုံး ဖျက်ပစ်ပြီး ကိုယ်လိုချင်တဲ့ size ကိုပြောင်းလဲယူရမှာဖြစ်ပါတယ်။ ဒီအဆင့်မှာ သတိပြုရမှာက ဖျက်ပစ်တယ်လို့ဆိုပေမယ့် partition table ထဲက entry ကိုပဲဖျက်တာဖြစ်ပြီး၊ အဲ့ဒီ partition ထဲက data တွေကို ဖျက်ပစ်မှာမဟုတ်ပါဘူး။ သို့သော်... backup အရင်လုပ်ထားနိုင်တယ်ဆိုရင်တော့ အကောင်းဆုံးပါ။ နောက်တချက်က LVM type ကို ပြန်လည် setup လုပ်တဲ့အခါမှာ Do you want to remove the signature? [Y]es/[N]o: လို့မေးတဲ့နေရာရောက်ရင် N သို့မဟုတ် No လို့ဖြေပေးရပါ့မယ်။ ဒီနေရာမှာ သတိထားပြီးတော့ တဆင့်ပြီးတဆင့် လုပ်သင့်ပါတယ်။
## start working on the desired disk with fdisk
[root@almalinux8 ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
## type 'p' here to print the current disk layout to double check
## take note of 'Start' column for /dev/vda2
## value is 2099200 here.
Command (m for help): p
Disk /dev/vda: 25 GiB, 26843545600 bytes, 52428800 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
Disklabel type: dos
Disk identifier: 0xa8460c45
Device Boot Start End Sectors Size Id Type
/dev/vda1 * 2048 2099199 2097152 1G 83 Linux
/dev/vda2 2099200 41943039 39843840 19G 8e Linux LVM
## type 'd' here to delete the partition /dev/vda2
## note that it does not delete data on the disk but the entry in partition table
Command (m for help): d
## if no input and enter, the default is partition number 2 (/dev/vda2 here)
Partition number (1,2, default 2):
Partition 2 has been deleted.
## type 'n' for new to create new partition
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
## if no input and enter, the default is 'p' for primary partition type
Select (default p):
Using default response p.
## if no input and enter, the default is '2' for second primary partition
Partition number (2-4, default 2):
## if no input and enter, the default should be the same value as before
## value is 2099200 here
First sector (2099200-52428799, default 2099200):
## if no input and enter, the default is the last sector of the disk after resize
Last sector, +sectors or +size{K,M,G,T,P} (2099200-52428799, default 52428799):
Created a new partition 2 of type 'Linux' and of size 24 GiB.
Partition #2 contains a LVM2_member signature.
## !!!CAUTION!!! - type 'N' for No to keep the LVM2_member signature
Do you want to remove the signature? [Y]es/[N]o: N
## type 't' for type to set the partition type
Command (m for help): t
## type '8e' for LVM Hex code for the partition
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
## type 'w' for write to apply the changes to the disk
Command (m for help): w
The partition table has been altered.
Syncing disks.