Tuesday, 23 August 2011

debirf - Building custom debian USB keys/CDROMs and run in RAM

I needed a way to make a simple custom bootable USB key to run linux on some test servers.
Furthermore I needed a strong linux environment that was easy to install additional tools into - such as an iSCSI initiator, bonnie++ and other tools to benchmark a new SAN.

I was also looking for a simple way to run the system from RAM (tmpfs) so I was not dependent on leaving the media in.

debirf is just such a tool. It builds an ISO image of a debian 6 system which boots into RAM and behaves like a normal system (ie you can trivially apt-get extra packages into the running system).

Turns out it's not too hard to tell it to add more packages to the ISO. Of course, when you have an ISOLINUX bootable ISO, it's not too hard to transfer to a USB key, though there is no automated way to do this yet.

It exists as a Debian package and also in Ubuntu, though I found problems running it from Ubuntu 10.10, so I installed a minimal Debian 6 system in a VirtualBox virtual machine.

The rough steps are, as root on the Debian 6 machine:
  • apt-get install debirf syslinux
  • mkdir /root/debirf; cd /root/debirf # You need lots of space here, use a suitable location
  • tar -xzf /usr/share/doc/debirf/example-profiles/rescue.tgz
  • Now edit rescue/debirf.conf and add the following line:

That just makes life slightly easier as you will get a usable isolinux config for using syslinux on a USB key.

Now some more steps:
  • as an example of how to add more packages to the image, add a file rescue/modules/benchmark:
#!/bin/bash -e

# debirf module: benchmark
# remove/install extra packages

# install packages
debirf_exec apt-get --no-install-recommends --assume-yes install bonnie++ iftop fio iperf

  • debirf make rescue
  • debirf makeiso rescue
Hopefully now, you will find an ISO file in rescue/ 

Burn this to a CDWR, or prep a USB key in the usual way:
  • fdisk /dev/sdX # Add one primary partition, type 0xc, boot flag set
  • syslinux -i /dev/sdX1
  • mount /dev/sdX /mnt/usb
  • mount -oloop rescue/<isofilefromdebirf>.iso /mnt/iso
  • cp /mnt/iso/* /mnt/usb/
  • mv /mnt/usb/isolinux.cfg /mnt/usb/syslinux.cfg
  • umount /mnt/iso /mnt/usb
Insert USB key (or CDWR) into computer, boot from it and you should see a syslinux menu offering console over "video" or "serial" (ttyS0 at 115000 baud).

Remove key and use again if required.

You can also just run the "isohybrid" command on the original iso, the dd the result to a USB key:

  • isohybrid rescue/<isofilefromdebirf>.iso
  • dd if=rescue/<isofilefromdebirf>.iso of=/dev/sdX
Where /dev/sdX is the device node of your USB stick. Make sure you umount the sick first as many OSes will auto mount it upon insertion!

No comments:

Post a Comment