Imaging SD Cards for PlugPBX

monitors

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 Card Imaging an SD card for PlugPBX (GUI)

  • We provide the image file in a compressed bzip2 file format. You can decompress this file format with the excellent (and free) 7Zip program, at https://www.7-zip.org/
  • So once you’ve decompressed the file, you should end up with a .img file. If you want check the md5 sum of the file before flashing. The free and easy to use winmd5sum tool works well and can be found at http://www.winmd5.com/ – If an .img file does not match our md5 sum, don’t flash it, download it again or reach out for help.
  • If you are using windows to image an SD card and want to do so easily via the GUI, I recommend Run Roadkil’s DiskImage Tool. It’s by far the easiest tool we have found online, and it’s free! You can get it here at http://www.roadkil.net/program.php?ProgramID=12
  • You should also check out some of his other tools and software!
  • Simply download, run and install the program. Select the .img file and select the disk drive letter of the SD card you are going to flash to under the “Write Image” tab. Double check the disk size to ensure it matches your SD card size. DO NOT PICK THE WRONG DISK, as you can damage or destroy your system or other drives /data. Double, no triple check!raodkil's disk image
  • In this example above we’re flashing the Dec22 image to our SD Card (note the 3.83 gig volume listed above). Click start, and the image will be written raw to the SD card, showing both data rate, and estimated time of completion.
  • Bonus Points: Once you have a PERFECT setup working as you want, SHUT down the SheevaPlug, and insert your SD card back into your Windows host, run this application again and use the “Store Image” tab. You’ll copy your SD card into your own .img file for safe keeping – you can duplicate your setup, restore from backup etc. If anyone wants to take our releases, and add features and re-release them back  – that would be very cool!

Imaging an SD card for PlugPBX (Windows Command Line)

If you are using windows to image an SD card, I recommend chrysocome.net’s windows port of dd.

  • An example of using the dd windows port with a Drive “E” flash card reader has been included below. In this example the image file will be written to the raw disk device of E:
dd –progress if=betaimageDec22-dhcpfixed4G.img   of=\.E:

As with any OS, take great care when imaging a destination device, that you have chosen the CORRECT DISK. If you do not, you can lose data!

The OpenSUSE  website does a great job of providing usage examples so there is little sense duplicating the content here. If there are better / faster examples of using this command please let us know of more optimal settings.

Any Windows tool that allows raw device imaging can be used to render a provided .img file – as its nothing special but a raw rip of the devices storage data, partitions, header, file-system et all in one data stream.

Leave a comment

You must be logged in to post a comment.