MicroSd

From Gumstix User Wiki
Jump to: navigation, search

It is possible to duplicate a microSD using a few simple tools in Linux. This can be useful once you have a known good image that you want to replicate for a bunch of Gumstix COMs.

The Use-Cases below assume a source card found at /dev/sourcecard and a destination card at /dev/destcard. Note, you can use 'dmesg' or 'mount' to confirm the actual mounting location; they are probably something like /dev/sde. Also, we are interested in the actual card device (e.g. /dev/sde) rather than the block devices representing any partitions it may have (e.g. /dev/sde0, /dev/sde1).

Creating a Basic Card Image

Note 1: before executing the commands below you will need to "umount" the partitions of the card that has been inserted in your computer (you may want to insert more than one card). For example, if your partitions are located in /dev/sde0 and /dev/sde1, the first thing you would have to do is:

sudo umount /dev/sde0
sudo umount /dev/sde1

Note 2: super user access (sudo) may be required to execute the following commands.

Commands to create a Basic Card Image:

dd if=/dev/sourcecard of=/home/user/masterimage.img bs=1M
dd if=/home/user/masterimage.img of=/dev/destcard bs=1M

Specifying a block size of 1MB should speed up the transfer.

If you happen to have two microSD slots so both cards are simultaneously available, you can do a direct copy:

dd if=/dev/sourcecard of=/dev/destcard bs=1M

For touchscreen boards, you'll redo the calibration for each board. Be sure to remove the /etc/pointercal file from the master image.

Creating a compressed image

You can also compress the image on disk but be warned that you need to do this as the root user.

dd if=/dev/sourcecard bs=1M | gzip -c > somefile.gz
gunzip -c somefile.gz | dd of=/dev/destcard bs=1M

To make even smaller image files, zero out all remaining space on your microSD card partitions before doing the two steps above. For example, let's say your Ext3 partition is mostly empty and is mounted at /mnt/card_ext/.

dd if=/dev/zero of=/mnt/card_ext/mybigfile
rm /mnt/card_ext/mybigfile

Note for large cards, it may be faster to create a script to format the card (see [1] for hints) and copy over the required files.

Thanks to Dave Hylands, Ananth and Coderone for their mailing list replies and to Doug Gibbs who posed the original question. See this thread for the full discussion.