Friday, March 12, 2010

Installing grml Linux on a USB Flash Drive

Last time I mentioned that I needed a USB flash drive for storing the GnuPG encryption keys and Amazon S3 access keys, which are used for backing up my files to the cloud.

The reason should be obvious: if I ever need to restore files from the remote backup, it would probably be because I either lost both my Debian box and Bacula backup disk, or that I can't access them for some reason. So I better have those keys available elsewhere.

So I purchased a 4GB SanDisk Cruzer Micro USB flash drive. But then I decided to install Linux on it, instead of just using it to store those key files.

Sick? I don't think so. After all, if I ever get that desperate, it's likely that I'll need to setup a Linux workstation with, at a minimum, GnuPG and duplicity installed on it. It would be much simpler if I could just boot any available PC with my USB key and be able to restore my files to some local storage device.

The only remaining question was which distro should I install? I wanted a distro that can be installed to a USB flash drive, which can be tailored ("remastered") to include up-to-date versions of s3cmd, duplicity and GnuPG, and support persistency of some sort (for storing the access keys and other configuration files). and Google provided some leads. There are many Live CD distros available, and quite a few minimal distros meant for USB flash drives. I further narrowed down my search by going for a Debian or Ubuntu based distro, which I'm familiar with, and figured I should first try the official releases: Debian Live and Ubuntu.

I've spent a few evenings trying to figure out Debian Live, and failed miserably. Debian Live is extremely configurable - it attempts to be the universal Live CD build system - and as such is pretty complex, at least for my taste and limited free time. The documentation seems to be out of date (e.g. it mentions commands such as lh_config and lh_build, where the actual command is lh) and the Debian Live wiki is a rather messy collection of apparently out-of-date howtos. Bottom line is that I just couldn't get past some error messages and gave up on it.

I ditched Debian Live in favor of the Ubuntu Live CD, which seemed less complicated to customize, and can also be installed to a USB flash drive.

I actually managed to generate a Live CD image with extra packages installed (s3cmd, duplicity and a few others) and some packages removed (such as the Ubuntu documentation). The only problem was that this image failed to boot under QEMU. Well, actually, it just hang during the startup process, showing a throbbing Ubuntu logo. It can very well be that I simply didn't wait long enough, and/or that my trouble had to do with a package that I should not have removed/installed - but I had neither the patience nor time to investigate.

This was rather frustrating. I didn't expect this to be so complicated. As I was about to settle for my original plan of placing the few key files I needed on the USB flash drive, I searched again for a Debian based live distro and found grml - "Linux Live system for sysadmins / texttool-users / geeks".

Grml is developed by several Debian developers, it's based on Debian/Testing, and it's currently actively maintained. Grml already includes s3cmd and duplicity, and a lot more - it even has awesome - ain't that awesome?!

This all looked very nice, and all that was left for me to do was to install it to my USB flash drive:
  1. download the grml iso image and burn it to a CD
  2. partition your USB flash drive (e.g. with gparted) such that it contains the following partitions, assuming its block device is /dev/sdb (adapted from the grml persistency howto):
    1. /dev/sdb1 - filesystem: FAT32, label: datastore, type: primary, size: 2GB
    2. /dev/sdb2 - filesystem: FAT16, label: grml, type: primary, bootable, size: 800MB (enough for one CD image)
    3. /dev/sdb5 - filesystem: EXT3, label: live-rw, type: logical, size: 1GB
    4. /dev/sdb6 - filesystem: EXT3, label: GRMLCFG, type: logical, size: 200MB
    and tune the EXT3 filesystems:
    tune2fs -i 0 -c 0 -m 1 /dev/sdb5
    tune2fs -i 0 -c 0 -m 1 /dev/sdb6
  3. boot a PC with this CD, press "q" at the prompt to enter the shell
  4. insert the USB flash drive
  5. run
    grml2usb --bootoptions="persistent" /live/image /dev/sdb2
    live-snapshot -d /dev/sdb5 -t ext3
    umount /live/live-snap*
  6. shutdown the PC, remove the CD and reboot it from the USB flash drive - if all goes well, grml should come up, with all system modifications loaded from, and subsequently saved to, the persistent live-rw partition
The larger FAT32 partition is used for storing files that should be accessible on a Window$ PC. At the moment I have Putty and TightVNC (viewer only) "installed" on it, allowing me to connect to my Debian box from any windows PC with access to the Internet - but I'll leave this to a future post.


  1. I try to make the same usb. When I type the following command.

    grml2usb --bootoptions="persistent" /live/image /dev/sdb2

    The error message show that there is no folder /live/image

    Could you tell me how to fix it in the current version GRML?



    1. I'm sorry but I'm not using the current version of GRML - please refer to the GRML wiki [1] and mailing list(s).
      Good luck!