+ cat >${BUILDTMP}/mtools.conf<<EOF
+drive z:
+file="${usb}"
+cylinders=$cylinders
+heads=$heads
+sectors=$sectors
+offset=$offset
+mformat_only
+mtools_skip_check=1
+EOF
+ # environment variable for mtools
+ export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+ ### COPIED FROM build_usb() below!!!!
+ echo -n " populating USB image... "
+ mcopy -bsQ -i "$usb" "$ISOFS"/* z:/
+
+ # Use syslinux instead of isolinux to make the image bootable
+ tmp="${BUILDTMP}/syslinux.cfg"
+ cat >$tmp <<EOF
+${console_serial_line}
+DEFAULT kernel
+APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${kernel_args}
+DISPLAY pl_version
+PROMPT 0
+TIMEOUT 40
+EOF
+ mdel -i "$usb" z:/isolinux.cfg 2>/dev/null || :
+ mcopy -i "$usb" "$tmp" z:/syslinux.cfg
+ rm -f "$tmp"
+ rm -f "${MTOOLSRC}"
+ unset MTOOLSRC
+
+ echo "making USB image bootable."
+ syslinux -o $offset "$usb"
+
+}
+
+#################### plain USB
+function build_usb() {
+ echo -n "* Creating USB image... "
+ local usb="$1" ; shift
+ local custom="$1"
+
+ rm -f "$usb"
+ mkfs.vfat -C "$usb" $(($(du -Lsk $ISOFS | awk '{ print $1; }') + $FREE_SPACE))
+
+ cat >${BUILDTMP}/mtools.conf<<EOF
+mtools_skip_check=1
+EOF
+ # environment variable for mtools
+ export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+ # Populate it
+ echo -n " populating USB image... "
+ mcopy -bsQ -i "$usb" "$ISOFS"/* ::/
+
+ # Use syslinux instead of isolinux to make the image bootable
+ tmp="${BUILDTMP}/syslinux.cfg"
+ cat >$tmp <<EOF
+${console_serial_line}
+DEFAULT kernel
+APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${kernel_args}
+DISPLAY pl_version
+PROMPT 0
+TIMEOUT 40
+EOF
+ mdel -i "$usb" ::/isolinux.cfg 2>/dev/null || :
+ mcopy -i "$usb" "$tmp" ::/syslinux.cfg
+ rm -f "$tmp"
+ rm -f "${MTOOLSRC}"
+ unset MTOOLSRC
+
+ echo "making USB image bootable."
+ syslinux "$usb"
+}
+
+#################### utility to setup CRAMFS related support
+function prepare_cramfs() {
+ [ -n "$CRAMFS_PREPARED" ] && return 0
+ local custom=$1;
+
+ echo "* Setting up CRAMFS-based images"
+ local tmp="${BUILDTMP}/cramfs-tree"
+ mkdir -p "$tmp"
+ push_cleanup rm -rf $tmp
+ pushd $tmp
+ gzip -d -c $ISOFS/bootcd.img | cpio -diu
+ gzip -d -c $ISOFS/overlay.img | cpio -diu
+ [ -n "$custom" ] && \
+ gzip -d -c $ISOFS/custom.img | cpio -diu
+
+ # clean out unnecessary rpm lib
+ echo "* clearing var/lib/rpm/*"
+ rm -f var/lib/rpm/*
+
+ # bootcd requires this directory
+ mkdir -p mnt/confdevice
+
+ # relocate various directory to /tmp
+ rm -rf root
+ ln -fs /tmp/root root
+ ln -fs /sbin/init linuxrc
+ ln -fs /tmp/resolv.conf etc/resolv.conf
+ ln -fs /tmp/etc/mtab etc/mtab
+
+ # have pl_rsysinit copy over appropriate etc & var directories into /tmp/etc/
+ # make /tmp/etc
+ echo "* renaming dirs in ./etc"
+ pushd etc
+ for dir in `find * -type d -prune | grep -v rc.d`; do
+ mv ${dir} ${dir}_o
+ ln -fs /tmp/etc/${dir} ${dir}
+ done
+ popd
+
+ echo "* renaming dirs in ./var"
+ # rename all top-level directories and put in a symlink to /tmp/var
+ pushd var
+ for dir in `find * -type d -prune`; do
+ mv ${dir} ${dir}_o
+ ln -fs /tmp/var/${dir} ${dir}
+ done
+ popd