## shutdown the VM first before resize the virtual disktyla@e32:~$virshshutdownalmalinux8Domain'almalinux8'isbeingshutdown## resize the .qcow2 file on host machinetyla@e32:~$sudoqemu-imgresize/data/kvm/almalinux8.qcow2+4GImageresized.## verify if the virtual size is now 25 GBtyla@e32:~$sudoqemu-imginfo/data/kvm/almalinux8.qcow2image:/data/kvm/almalinux8.qcow2fileformat:qcow2virtualsize:25GiB (26843545600 bytes)disksize:2.63GiBcluster_size:65536Formatspecificinformation:compat:1.1compressiontype:zliblazyrefcounts:truerefcountbits:16corrupt:falseextendedl2:falseChildnode'/file':filename:/data/kvm/almalinux8.qcow2protocoltype:filefilelength:20GiB (21478375424 bytes)disksize:2.63GiB## start the VM tyla@e32:~$virshstartalmalinux8Domain'almalinux8'started## verify if the VM is runningtyla@e32:~$virshlistIdNameState----------------------------9almalinux8running
## also check the partition layout and size with both lsblk and df commands[root@almalinux8 ~]# lsblkNAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTsr011:011024M0romvda252:0025G0disk├─vda1252:101G0part/boot└─vda2252:2019G0part├─almalinux-root253:0017G0lvm/└─almalinux-swap253:102G0lvm [SWAP][root@almalinux8 ~]# df -ThFilesystemTypeSizeUsedAvailUse%Mountedondevtmpfsdevtmpfs870M0870M0%/devtmpfstmpfs890M0890M0%/dev/shmtmpfstmpfs890M8.6M881M1%/runtmpfstmpfs890M0890M0%/sys/fs/cgroup/dev/mapper/almalinux-rootxfs17G2.2G15G13%//dev/vda1xfs1014M232M783M23%/boottmpfstmpfs178M0178M0%/run/user/1000
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/vdaWelcometofdisk (util-linux 2.32.1).Changeswillremaininmemoryonly,untilyoudecidetowritethem.Becarefulbeforeusingthewritecommand.## 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 forhelp): pDisk/dev/vda:25GiB,26843545600bytes,52428800sectorsUnits:sectorsof1*512=512bytesSectorsize (logical/physical): 512 bytes / 512 bytesI/Osize (minimum/optimal): 512 bytes / 512 bytesDisklabeltype:dosDiskidentifier:0xa8460c45DeviceBootStartEndSectorsSizeIdType/dev/vda1*2048209919920971521G83Linux/dev/vda22099200419430393984384019G8eLinuxLVM## type 'd' here to delete the partition /dev/vda2## note that it does not delete data on the disk but the entry in partition tableCommand (m forhelp): d## if no input and enter, the default is partition number 2 (/dev/vda2 here)Partitionnumber (1,2, default2): Partition2hasbeendeleted.## type 'n' for new to create new partitionCommand (m forhelp): nPartitiontypepprimary (1 primary,0extended,3free)eextended (container forlogicalpartitions)## if no input and enter, the default is 'p' for primary partition typeSelect (default p): Usingdefaultresponsep.## if no input and enter, the default is '2' for second primary partitionPartitionnumber (2-4, default2): ## if no input and enter, the default should be the same value as before## value is 2099200 hereFirstsector (2099200-52428799, default2099200): ## if no input and enter, the default is the last sector of the disk after resizeLastsector,+sectorsor+size{K,M,G,T,P} (2099200-52428799, default52428799): Createdanewpartition2oftype'Linux'andofsize24GiB.Partition#2 contains a LVM2_member signature.## !!!CAUTION!!! - type 'N' for No to keep the LVM2_member signatureDoyouwanttoremovethesignature? [Y]es/[N]o: N## type 't' for type to set the partition typeCommand (m forhelp): t## type '8e' for LVM Hex code for the partitionPartitionnumber (1,2, default2): Hexcode (type Ltolistallcodes): 8eChangedtypeofpartition'Linux'to'Linux LVM'.## type 'w' for write to apply the changes to the diskCommand (m forhelp): wThepartitiontablehasbeenaltered.Syncingdisks.
## check if the vda2 disk partition size[root@almalinux8 ~]# lsblk NAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTsr011:011024M0romvda252:0025G0disk├─vda1252:101G0part/boot└─vda2252:2024G0part├─almalinux-root253:0017G0lvm/└─almalinux-swap253:102G0lvm [SWAP]## verify the LVM physical volume before resize [root@almalinux8 ~]# pvsPVVGFmtAttrPSizePFree/dev/vda2almalinuxlvm2a--<19.00g0## resize the physical volume with pvresize[root@almalinux8 ~]# pvresize /dev/vda2Physicalvolume"/dev/vda2"changed1physicalvolume(s) resizedorupdated/0physicalvolume(s) notresized## verify the LVM physical volume after resize [root@almalinux8 ~]# pvsPVVGFmtAttrPSizePFree/dev/vda2almalinuxlvm2a--<24.00g5.00g
## also verify the LVM volume group for free space[root@almalinux8 ~]# vgsVG#PV #LV #SN Attr VSize VFreealmalinux120wz--n-<24.00g5.00g## now extend the LVM logical volume with lvextend to extend /dev/almalinux/root[root@almalinux8 ~]# lvextend -l +100%FREE /dev/almalinux/rootSizeoflogicalvolumealmalinux/rootchangedfrom<17.00GiB (4351 extents) to <22.00 GiB (5631extents).Logicalvolumealmalinux/rootsuccessfullyresized.## verify the logical volume size of root [root@almalinux8 ~]# lvsLVVGAttrLSizePoolOriginData%Meta%MoveLogCpy%SyncConvertrootalmalinux-wi-ao----<22.00gswapalmalinux-wi-ao----2.00g
နောက်တခါ lsblk နဲ့ / mount point ကိုစစ်ကြည့်တဲ့အခါမှာ 22 GB ဖြစ်နေတာကိုတွေ့ရမှာပါ။ အရှေ့မှာ စစ်ကြည့်ထားလို့ xfs ဆိုတဲ့ filesystem ကိုအသုံးပြုထားတာသိရှိပြီးတဲ့အတွက် xfs_growfs ဆိုတဲ့ command နဲ့ / mount point ရဲ့ filesystem ကို grow လုပ်ပေးရပါလိမ့်မယ်။ နောက်ဆုံးအနေနဲ့ df command ကိုအသုံးပြုပြီး / mount point ကိုစစ်ကြည့်လိုက်ရင် ကိုယ်လိုချင်တဲ့ size ကိုတိုးပြီးမြင်နိုင်မှာဖြစ်ပါတယ်။
## also verify it with lsblk[root@almalinux8 ~]# lsblkNAMEMAJ:MINRMSIZEROTYPEMOUNTPOINTsr011:011024M0romvda252:0025G0disk├─vda1252:101G0part/boot└─vda2252:2024G0part├─almalinux-root253:0022G0lvm/└─almalinux-swap253:102G0lvm [SWAP]## grow the / mount with xfs_growfs because the filesystem is xfs here## note that resize2fs is used when the filesystem is ext4[root@almalinux8 ~]# xfs_growfs /meta-data=/dev/mapper/almalinux-root isize=512 agcount=4, agsize=1113856blks=sectsz=512attr=2,projid32bit=1=crc=1finobt=1,sparse=1,rmapbt=0=reflink=1bigtime=0inobtcount=0data=bsize=4096blocks=4455424,imaxpct=25=sunit=0swidth=0blksnaming=version2bsize=4096ascii-ci=0,ftype=1log=internallogbsize=4096blocks=2560,version=2=sectsz=512sunit=0blks,lazy-count=1realtime=noneextsz=4096blocks=0,rtextents=0datablockschangedfrom4455424to5766144## verify the disk free space at / mount point now[root@almalinux8 ~]# df -ThFilesystemTypeSizeUsedAvailUse%Mountedondevtmpfsdevtmpfs870M0870M0%/devtmpfstmpfs890M0890M0%/dev/shmtmpfstmpfs890M8.6M881M1%/runtmpfstmpfs890M0890M0%/sys/fs/cgroup/dev/mapper/almalinux-rootxfs22G2.2G20G10%//dev/vda1xfs1014M232M783M23%/boottmpfstmpfs178M0178M0%/run/user/1000