SD Cards – Why disk images?

So As we tinker, make images, and muck about we figured noting these tips and tricks would allow others to contribute or find inspiration for their own Sheeva geared projects, or contributing back to this one.

For instance someone could decide to take our base PlugPBX image, fire it up – add the Nerd Vittles various scripts, plugins and FreePBX enhancements, correct some mistakes, and then prior to setting up for their own use, image that SD card. Perhaps call it the Vittle PlugPBX – and upload a copy to this website. We’d love that kind of collaboration. You can make, create, share, backup and distribute your own SD card images of plug and play systems for others to try and apply. Think of the VMware marketplace, but applied to SheevaPlug computers!

Good Preparation Practices Before Imaging your SheevaPlug SD Card

  • First you’ll want to ensure no ‘left over’ junk is in the SD card file system you wish to backup. When you image an entire disk, deleted files may be gone but their left over data may not. Filling the systems free space with zero’s ensure its all empty so we’re not imaging anything we don’t care about anymore. The easiest way to do this in a UNIX system is the following trick. Just run this from an ssh or serial terminal session.
cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
  • This is four commands chained together; when one completes; the next will execute; until done. Can you guess what separates each command :)
  • So we are going to take an infinite number of zeros generated by the kernel generated file /dev/zero and write them to a file named zero.fill. Next we make sure the writes to disk are committed to disk (empty out caches and pending writes), wait a second, and do it again a second time (never hurts to be paranoid). Then we delete the mega huge zero file since we just ran out of disk space.
  • So now we can shutdown the SheevaPlug system, remove the SD card and raw image with with our choice tool.

Ideal Imaging of a PlugPBX system to share/backup – Backup (MAC OS X)

  • So in this example I’ll use a MAC OS X 10.6 machine. Once plugging the SD card and reader into the Mac it will indicate the disk is not a valid file system and ask if i wish to ignore it, eject it or format it. DO NOT FORMAT/INITIALIZE IT or you loose all your hard work!
  • Once connected you can see what it shows up as by listing your /dev/disk* via the following command
ls /dev/disk*
  • Next if we think we’ve found the suspect disk, we can use diskutility to examine its partitions as follows to be sure we have the right raw disk to image
diskutil list /dev/disk1  

/dev/disk1

#:                       TYPE NAME                    SIZE       IDENTIFIER
0:     FDisk_partition_scheme                        *4.0 GB     disk1
1:                      Linux                         230.3 MB   disk1s1
2:                      Linux                         3.6 GB     disk1s2
3:                 Linux_Swap                         139.8 MB   disk1s
  • That’s the disk alright. Finally we can use dd to image the raw disk to a image file on the computer
sudo dd if=/dev/disk1 of=/Users/abcdef/PlugPBX/betaimageDec18-nodev.img
  • Finally, you would want to compress this image, as it’ll be the raw size of the storage device. The image is done and dd reports its final output as
7839744+0 records in
7839744+0 records out
4013948928 bytes transferred in 1000.764773 secs (4010882 bytes/sec)
  • You should also run an md5 on the resulting image and ensure you provide that, so other people can check downloaded and decompressed images to render that they match so they are sure no corruption has occurred. Simply do the following to have it calculated and displayed.
md5 betaimageDec18-nodev.img
  • After a awhile the output will look similar to the example here
MD5 (betaimageDec18-nodev.img) = afab2ce02509acbd8fdfdefdca5d839e
  • This will store the md5 sum in a text file for others to refer to as a clean convention of md5 tracking
md5 betaimageDec18-nodev.img > betaimageDec18-nodev.md5sum
  • You should compress raw images as it shrinks the image by its empty space. Bzip2 is the preferred compression tool now a days. Yes, you can pipe the stream right into bzip2 and have the image compressed on the fly if you prefer doing it all in one command..but let’s keep the examples simple 
bzip2 betaimageDec18-nodev.img
  • Once done, this original 4 gig image file, has been compressed down to about 336 megabytes. I rushed the very first release of PlugPBX and it was a 4 to 1 gig compression. Now we’ve gone from 4 gig to 336 megabytes. Not bad. This same technique I’ve used in backing up virtual machines too

Other Operating Systems (Linux and Windows)

You can well imagine that Linux is very similar to Mac OS X, minus the disk utility, but the rest is exactly the same, minus differences in the names used in /dev/…

Windows can make use of the Cygwin UNIX environment to duplicate the above, or use other raw disk imaging tools and compression / md5 tools.

Anyone wishing to provide detailed tutorials on using Windows or Linux, I’ll be happy to amend the page here!