Ubuntu 16.04: A 64GB SD-Card image was created with the command:
date; sudo sh -c 'pv /dev/mmcblk0 >rpi4_Ubuntu18.1_64GB.image'; date
The rasbperry pi SD-Card is outfitted with Ubuntu 18.1
Can a Ubuntu 16.04 laptop:
- mount the .image file?
- run zerofree on the mounting point of the .image file?
- unmount the .image file?
I am aware that it is possible to restore the image file to the SD-card and process the card with zerofree and snapping the image again. It would be nice to be able to process several .image files without restoring them to the SD card.
UPDATE: Test results
Image successfully mounted to /dev/loop9p2:
$ sudo losetup -P /dev/loop9 rpi4_Ubuntu18.1_64GB.image $ ls -l /dev/loop9* brw-rw---- 1 root disk 7, 9 Feb 2 19:12 /dev/loop9 brw-rw---- 1 root disk 259, 0 Feb 2 19:12 /dev/loop9p1 brw-rw---- 1 root disk 259, 1 Feb 2 19:12 /dev/loop9p2
$ zerofree -v /dev/loop9p2 zerofree: failed to open filesystem /dev/loop9p2
$ sudo zerofree -v /dev/loop9p2 14346339/14348998/15073019
- 14346339 number of nonzero blocks encountered
- 14348998 number of free blocks within the filesystem
- 15073019 total number of blocks within the filesystem
Bonus: reduce image size with script pishrink