Monday, May 18, 2009

Backing up a system on Compact Flash

If you have a system on Compact Flash, for instance a digital picture frame. There's a really neat way to work on the system without having to write to the disk more than once, and still do alot of updates or other changes.

What you do is that you make a disk image of the Compact Flash media and then run that image in a machine emulator like Qemu for Linux and Windows or Q - [kju:] for OSX. Once the image is booted you can, work on the system and do all sorts of changes and when you're done all you have to do is write that image back to the media it came from. Ofcourse, if you're only doing minor changes this might be unecessary but for bigger system updates or just testing out new software before going live it's really nice.


How it's done
  1. Hook up your CF-card to your host system make sure the disk is not mounted, unmount it if necessary. But before doing that find out the path to the disk i.e: /dev/sdb, /dev/hdb or something like that.

  2. Then run dd to copy the whole disk to an image.
    Warning!
    The dd command can cause irreversible damage to your system. If you're not sure what you're doing, don't do it.

    Syntax: dd if=path_to_disk_to_backup of=outfile
    Where
    if stands for "Input file" and of for "Output file"

    For my system I use the following command:

    dd if=/dev/sdb of=lappy586.bin conv=noerror,sync
    The added option
    conv=noerror,sync makes sure that the copy will go on even if there are errors.
    The copy might take a while depending on the size of the image you try to copy.

  3. After the copy is done you can run the image with qemu like this:
    qemu -hda path_to_diskimage

    Qemu has alot of options, if things don't work out for you the first time have a look at the manpages and other documentation. I got lucky and had everything working without any need for extra configuration when running Qemu from Debian but not so lucky when trying to run the same image from Windows Vista.

  4. Finally, to write the backup back to disk just reverse the paths in the dd command:
    dd if=lappy586.bin of=/dev/sdb conv=noerror,sync