A few notes on manipulating image files of a Raspberry Pi filesystem.
- How to mount the image file.
- How to compress the image file.
Manipulate the image file
Interesting link on how to use loopback driver. After the file is attached to the loopback driver, it can be manipulated as every other block device.
Fill empty space with zeros
For better compression! Use the command
[tommz@tommz-fedora Data 1T]$ sudo zerofree /dev/loop0p2
2.4 GB image of a Raspberry Pi SD card has been compressed with 7z. Then
zerofree has been applied and the image was compressed again. Result:
$ ls -lh 684M img.7z 349M img.zerofree.7z
The file size has been reduced to one half.
Copy an image file to an SD Card
sudo dd bs=4M if=image.img of=/dev/sdX sync
Note: Make sure that the partitions of the SD Card are not mounted!