Environment: 128GB SSD, I have already backed up the image in the “tools/backup_restore/images” directory, and 128GB is not fully utilized. Below is a list of less than 100GB.
I’m not sure I know what space is being lost or space is being added, but sometimes you can create a blank file of the right size, cover it with loopback, and then format it as ext4. Then use rsync to copy content into that new image. However, your backup is perhaps multiple partitions which must fit together, and this might be frustrating. For example, some partitions might require being at the same offset, and you might need to hand fit the pieces of other partitions in by using offsets. The partition which is for the rootfs is kind of a special case in that it is not binary data, so it has some flexibility, but you’d still want it to be a multiple of 1024 bytes (or better yet, due to some cases, a multiple of 4096 bytes). The fact that that partition is ext4 is why rsync can work on it when covered with loopback.
It is an entire lesson just to work with dd when mixing and matching binary partitions. Consider that if you can work with just the rootfs, then it is still a bit complicated, but it isn’t nearly as difficult. If the rootfs is not only its own separate partition, but a separate file from all of those other backed up partitions, then something like gparted will work on the loopback mounted rootfs if there is room. Making room and trimming room of loopback filesystems is the part where you need a lot of disk space and time and be willing to make mistakes.