The motivation behind this effort is to have the USB stick function like a regular hard drive and provide the basic functionality for some virtual or real machine to do exactly what it is supposed to do (and nothing much else). Again, a compressed file system would be lovely, but a plain journaled ext2 seems to allow a good start.

The installation is performed via deboostrap. cdebootstrap should also work, but it has not for me. Then to be added is a bootloader. I tried with grub2, but it reads from hd0 instead of hd1 when tested on a Windows machine, and I failed to change that. If hd0 is correct for a diskless client I cannot tell. I was then successful with extlinux, an ext2-compatible syslinux. The following worked for me.

Some parameters to be used throughout the remainder of these instructions

   device=/dev/sdb # where the stick appears locally
   ddevice=/dev/sda # where the stick appears when booted on target machine
   partno=1 # number of partition you want to boot from
   mountpoint="/mnt/stick" # directory for the stick to show up
   mirror="http://ftp.de.debian.org/debian" # from where to download
   # packages that shall be installed
   packages="boinc-client autodock autogrid autodocktools gromacs r-cran-qtl r-recommended"
   kernelversion=$(apt-cache show linux-image-amd64| grep Depends|cut -f2 -d\  | cut -f3,4,5 -d-)

Now the real thing starts

   sudo fdisk $device # create a partition
   mke2fs -j $device$partno # journaled ext2 file system
   tune2fs -c 0 $device$partno # don't check
   [ -d "$mountpoint" ] || sudo mkdir "$mountpoint" # prepare mount point
   mount -t ext2 $device$partno "$mountpoint"
   debootstrap --include=openssh-client,nfs-common squeeze "$mountpoint" $mirror

A disadvantage of this setup is the limited space to cache the packages - the binaries eat up the disk space that is needed to unpack them. And apt-get does not care about removing packages from /var/cache/apt to free disk space during installation. After the debootstrap, one should install in fractions rather than all in one - also depending on the size of your medium. A 4GB USB stick was found to be sufficient, but far less comfy than originally anticipated. Go for at least 8GB.

   chroot "$mountpoint"
   # some basic infrastructure
   apt-get install debian-keyring build-essential dhcp3-client 
   # debian-med
   apt-get install med-bio-dev
   apt-get clean
   # more advanced packages - adjust to your liking
   for p in $packages; do echo "Installing $p"; apt-get --no-install-recommends install $p && apt-get clean; done

While still in the chroot, the password of root needs to be set.

   passwd root

And how to access the network should be specified - please adjust:

   cat > /etc/network/interfaces <<EONET
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
EONET

For getting the beast to boot, I attempted the following. The kernel should be installed, first, and the installation inspects the /proc directory, so this is prepared for it, too.

   #sudo chroot "$mountpoint" # entering the chroot just created, if not already in

   cat /etc/fstab # make sure you really are in the chroot and
                  # hence want to overwrite this
   echo "Will be overwritten in ten seconds if you don't CTRL-C"
   sleep 10 # you shall not copy and paste blindly
   cat > /etc/fstab << EOFSTAB
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
$ddevice$partno       /               ext3    defaults,errors=remount-ro 0       1
EOFSTAB
   mount /proc
   apt-get install linux-image
   # answering 'Y' to the questions asked, except for the
   # preparation for the initrd, which is fine - press "don't cancel"

Now the boot loader should be installed. It was not clear from the documentation (#548424) about how the configuration file should be named - so some good soul please improve the description given here.

   # still in the chroot
   cat > /extlinux.conf <<EOCFG
DEFAULT debian-med-$kernelversion
LABEL debian-med-$kernelversion
SAY Debian Med from USB stick
KERNEL /boot/vmlinuz-$kernelversion
APPEND ro root=$ddevice$partno initrd=/boot/initrd.img-$kernelversion
EOCFG
   exit  # now back from the chroot

   # here I have indeed done the cat mbr.bin > $device , but
   # it should also work without it - I think. If not, see
   # http://syslinux.zytor.com/wiki/index.php/EXTLINUX

   sudo apt-get install syslinux
   extlinux -i "$mountpoint"/boot

   sync # does not help too much with journaled file systems, though

   chroot $mountpoint umount /proc
   umount $mountpoint

References: