Here's how to use a .img file downloaded from the ODroid repositories for example. I'll also tell you how to create an image from a SD card.
I use ddrescue instead of dd because:
- It gives you a comprehensive real-time progress report - It corrects errors while it copies - It can make sparse images to save space - It tries harder when encountering problems.
Using a .img File
First, figure out what the device identifier is for your SD card. An easy way to do this is with GParted. Run
sudo gparted and find the device identifier for your SD card. In this example I will use
/dev/sdb. You need to make sure this is correct, you could corrupt your hard drive if you write random data over it accidentally.
Here's the command to copy the image file:
sudo ddrescue myimage.img /dev/sdb -f
-f flag will force ddrescue to overwrite a block device (rather than a file).
Creating .img Files
To create an image file, the basic command is simple:
sudo ddrescue /dev/sda myimage.img -S
-S flag is optional but will create a sparse image (smaller file).
Compressing the Image
You will probably want to make as small of an image as possible. You can make each of the partitions as small as possible with GParted and copy just the partition table (at the beginning) and the data from each partition to make a smaller image.
Open GParted, select your SD Card, and unmount each partition. Next right click each partition (left to right) and size them down to be as small as possible. Then move them all as far left as possible. GParted will defragment all of the data to the beginning of each partition on the disk, creating a solid block of data instead of a somewhat fragmented amount of data spread over the entire disk.
Figure out the total size of all three minified partitions, and add on a bit of a buffer space. I'd suggest about 100MB of extra buffer space. This is so you don't accidentally cut off the end of one of the partitions with a rounding error somewhere.
DDRescue supports size specifiers as you can see in the help (use the
-h option). They are byte, kilobyte, megabyte, etc. Convert your disk size into one of these sizes (I recommend megabytes) and use that for the size specifier. Here's an example:
sudo ddrescue /dev/sda my.img -S --size=6780M
This will store only the actual data on the device in a smaller image file.