Evolution of a Blog

This blog has evolved as I have as a maker. It starts at the beginning of my journey where I began to re-tread my tires in the useful lore of micro electronics and the open-source software that can drive them. While building solutions around micro-electronics are still an occasional topic my more recent focus has been on the 3D Printing side of making.

Saturday, April 13, 2013

Managing SD Card Images

Having multiple Raspberry Pis doing a variety of tasks with some aspect of new development constantly underway means a lot of different SD Card images.   I got tired of manually managing them so developed a little Python script to help.

What I wanted was a script that would run under Python on a Linux workstation and do the following:
  1. Save an image to the hard drive of the Linux box or burn a previously saved image to an SD Card (--save and --burn).
  2. Optionally compress the saved image (and decompress as part of the burn process) as the hard drive on my Linux box is kinda small (--zip).
  3. Organize my images into three folders with one for original Distro images, one for date stamped Backups, and one for Checkpoints.   An example of my use of Checkpoints:   I have an Arch image that is built just to the point of the network running, one that includes LXDE, and one that is my working Robot (--checkpoint and --distros with backup being default).   
  4. List images available for burn in the above folders (--list).
As I developed the script I also added some more options to:
  1. Provide password on the command line so it can be fed to sudo for the execution of the dd command 
  2. Enable a save or restore at the partition level.   Note that only two partitions are supported and that a burn destination will be reformatted and partitioned to fit the saved image
  3. Alter output from the script with one displaying everything (--verbose) and one nothing (--quiet).  The default is to display a minimum of status but to prompt for confirmation of command line options.
  4. Added an image number to the --list option such that the user can provide that number for a burn request rather than an entire image name.
Here is the --help for the script:
  -h, --help            show this help message and exit
  -b, --burn            Burn an image to an SD card
  -c, --checkpoint      Checkpoint type image, default is Backup
  -d, --distro          Distro type image
  -e DEVICE, --device=DEVICE
                        Device name (e.g. sdc)

  -l, --list            List images availble for burning
  -p, --part            Save at partition level
  -q, --quiet           Display nothing (including confirmation request) other
                        than an error
  -r ROOT, --root=ROOT  Root password for sudo
  -s, --save            Save image to computer
  -v, --verbose         Display everything
  -z, --zip             Source (/Target) is (/to be) compressed using zip

Some examples of the script command line invocation:
python mi.py --burn --distro --device=sdd distro-name
python mi.py --burn --distro --zip --device=sdd distro-name
python mi.py --burn --checkpoint --zip --device=sdd checkpoint-name
python mi.py --burn --zip --device=sdd backup-name
python mi.py --save --checkpoint --zip --device=sdd checkpoint-name
python mi.py --save --zip --device=sdd --root=secret backup-name

python mi.py --burn --distro --device=sdd 3
python mi.py -bde=sdd 3  

Output from the --list command showing image numbers:
will@UbuntuMini:~/Images$ ./mi --list
Images available in Distros
  ( 1) 2013-02-09-wheezy-raspbian:
       1.94gb/z    saved on 2013-04-11 07:06:08.736134
  ( 2) archlinux-hf-2013-02-11:
       1.94gb/z    saved on 2013-04-11 09:10:53.009246

Images available in Checkpoints
  ( 1) arch-1:
       3.97gb/z    saved on 2013-04-13 22:41:33.510442
  ( 2) arch-2-LXDE:
       3.97gb/z    saved on 2013-04-13 23:00:23.804046
  ( 3) tvhe:
       3.96gb/p/z  saved on 2013-04-18 15:15:52.762579

Images available in Backups
  ( 1) 2013-04-12-CritterCam:
       16.04gb/z    saved on 2013-04-12 09:44:34.467685
  ( 2) 2013-04-14-arch-webcam:
       3.97gb/z    saved on 2013-04-14 17:12:50.241074  

I had made the source code for this script available but then pulled it when I a) realized that there were still features that I wanted to add and b) that as I added those features I was also introducing bugs.

I have finally finished development and a fair amount of testing on the three Ubuntu machines that I have available.  The code is available here.  I would really appreciate some feedback and any reports of problems.

No comments:

Post a Comment