sudo losetup --partscan /dev/loop13 disk_image.img

'
sudo e2fsck -f /dev/loop13p1
sudo e2fsck -f /dev/loop13p2

'
sudo resize2fs /dev/loop13p1 -M
sudo resize2fs /dev/loop13p2 -M

'
block_count1=$(sudo tune2fs -l /dev/loop13p1 | grep 'Block count1' | sed 's/[^0-9]//g')
block_count2=$(sudo tune2fs -l /dev/loop13p1 | grep 'Block count2' | sed 's/[^0-9]//g')
'
block_size1=$(sudo tune2fs -l /dev/loop13p1 | grep 'Block size1' | sed 's/[^0-9]//g')
block_size2=$(sudo tune2fs -l /dev/loop13p2 | grep 'Block size2' | sed 's/[^0-9]//g')

'
fs_size1=$(((block_count1) * (block_size1)))
fs_size2=$(((block_count2) * (block_size2)))

'
sudo losetup --detach /dev/loop13

'
sudo losetup --partscan /dev/loop13 disk_image.img
start1=$(sudo parted /dev/loop13 unit B print --json | jq -r '.disk.partitions[0].start[0:-1]')
start2=$(sudo parted /dev/loop13 unit B print --json | jq -r '.disk.partitions[1].start[0:-1]')
end1=$((start1 + fs_size1))
end2=$((start2 + fs_size2))

'

sudo parted /dev/loop13 resizepart 1 ${end1}B
sudo parted /dev/loop13 resizepart 2 ${end2}B

'
sudo losetup --detach /dev/loop13
truncate -s $end2 disk_image.img
sudo losetup --partscan /dev/loop13 disk_image.img
mkdir /tmp/disk_image
sudo mount /dev/loop13p1 /tmp/disk_image
sudo fstrim -v /tmp/disk_image
sudo umount /tmp/disk_image
sudo losetup --detach /dev/loop13