SYS

Image file resizing

A brief technical note outlining the basic approach and applicable steps for image file resizing.

Sometimes we have an image file (such as .img) and we may need to increase its size. In these cases, we can follow the steps below. Our image file is a raspberry os image file.

We are installing the following applications. I used Raspberry Pi Lite OS while doing these steps. These steps worked without any problems.

sudo apt install qemu-utils qemu-system-arm unzip lsof

We make the first check and learn the size information.

kpartx -a -v <img file>
mount /dev/mapper/loop0p2 /mnt
df -h

We close the image file with kpartx and unmount it.

umount /mnt
kpartx -d <img file>

We check if image is used


lsof <img file>

We are doing the resize process

qemu-img resize <img file> +1G

we reboot

We open the image file with kpart

kpartx -a -v <img file>

We open the file with fdisk and edit the partiton.

fdisk -l <img file>
fdisk <img file>

we reboot and edit the file system

e2fsck -f /dev/mapper/loop0p2 ## burada kendi loop dosyanızı gösterin

resize2fs /dev/mapper/loop0p2  ## burada kendi loop dosyanızı gösterin


We Check the Change

mount /dev/mapper/loop0p2 /mnt
df -h

Source