I've done the following several times, but now it doesn't work anymore:
- downloaded the latest Raspbian image
qemu-img resize 2017-06-21-raspbian-jessie-lite.img +300M
sudo losetup -P /dev/loop0 2017-06-21-raspbian-jessie-lite.img
sudo gparted /dev/loop0
- using gparted, resized the fs partition to fill the empty space
sudo losetup -D
truncate --size=$[(3162111+1)*512] 2017-06-21-raspbian-jessie-lite.img
The "magic number" 3162111 is the last sector of the second partition. Then I burned an sd-card with the new image. It doesn't boot - it hangs on the 4 raspberries with black screen.
Of course the original one works fine.
I've noticed that
sudo losetup -a still shows the image mounted:
$ sudo losetup -a /dev/loop0: :1179664 (/home/dev/opt/2017-06-21-raspbian-jessie-lite.img), offset 48234496
Trying again with
sudo losetup -D doesn't change anything.
fuser -c or
-k does nothing useful.
I'm afraid the problem on boot is related to this. What could I try to check now?