20
May

Prepping, Cleaning, and Compressing an Image

Here are some non-comprehensive tips for creating an image from a block device that runs an embedded Linux system (ie. SD Card, USB Drive, etc). Using these steps will help you prepare, clean, and compress an image to the smallest size possible. I used these recently to create a microSD card image for the company I work for (Technologic Systems) so we can upload them to an FTP server that customers have access to. It runs Debian Linux with and initrd and Busybox. I believe that BeagleBoard and other embedded system companies who produce single board computers (SBCs) also have a similar setup to this.

Steps on the Embedded System Itself:
Clear any history from within Busybox:

> .ash_profile

Boot to full Debian and clean up:

apt-get autoremove
apt-get clean
rm -rf /var/log/*/*

Now, clear any history in Debian and shutdown:

> .bash_history; history -c; shutdown -h now

Steps on the Linux PC:
Mount SD card on another Linux box (assumes /dev/sdb) and “zero out” all available partitions. In this example, there are four, one is raw kernel image so it is left alone:

mount /dev/sdb1 /mnt/tmp; cd /mnt/tmp
dd if=/dev/zero of=zerofill; rm -rf zerofill
umount /dev/sdb1

mount /dev/sdb3 /mnt/tmp; cd /mnt/tmp
dd if=/dev/zero of=zerofill; rm -rf zerofill
umount /dev/sdb3

mount /dev/sdb4 /mnt/tmp; cd /mnt/tmp
dd if=/dev/zero of=zerofill; rm -rf zerofill
umount /dev/sdb4

Now, create the .dd image and compress it:

dd if=/dev/sdb of=theImage.dd
bzip2 --best theImage.dd

Using the steps above, I was able to compress a 2GB SD image down to ~800MB (zeros compress very well)! And, since I took the time to clear out the history and logs, the user who downloads and uses the image will have a nice, clean image to work from. You could take it another step further and reduce the size of your kernel modules using my other guide:
Command to Reduce File Size of Installed Kernel Modules

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 0 Comment So Far

Share your thoughts, leave a comment!