Skip to content

Instantly share code, notes, and snippets.

@mikehale
Created February 7, 2012 04:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikehale/9223336a3a387cfe1eb0 to your computer and use it in GitHub Desktop.
Save mikehale/9223336a3a387cfe1eb0 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -x
set -e
TEMPROOT=/root/usb-live
mkdir -p ${TEMPROOT}/usb
mkdir -p ${TEMPROOT}/live
mkdir -p ${TEMPROOT}/fetch
mkdir -p ${TEMPROOT}/tmp
USB_MOUNT=${TEMPROOT}/usb
LIVE_MOUNT=${TEMPROOT}/live
FETCH_DIR=${TEMPROOT}/fetch
TMP_DIR=${TEMPROOT}/tmp
rm -rf ${USB_MOUNT}/boot
mkdir -p ${USB_MOUNT}/boot/grub/
UBUNTU_SERVER () {
# Fetch iso and hd-media initrd
test -e ${FETCH_DIR}/initrd.gz || wget -nd http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-$ARCH/current/images/hd-media/initrd.gz -O ${FETCH_DIR}/initrd.gz
zsync http://ftp.ucsb.edu/pub/mirrors/linux/ubuntu/${VERSION}/${NAME}.iso.zsync -o ${FETCH_DIR}/${NAME}.iso
# Prepare to mangle initrds
mount -o loop ${FETCH_DIR}/${NAME}.iso ${LIVE_MOUNT} || true
rm -rf ${TMP_DIR}/initrd-hd-media ${TMP_DIR}/initrd-iso
mkdir -p ${TMP_DIR}/initrd-hd-media ${TMP_DIR}/initrd-iso
mkdir -p ${USB_MOUNT}/${NAME}
# Build a new initrd with modules from the iso (to match the kernel from the iso), but based on hd-media so we can install from a non-cd source
cd ${TMP_DIR}/initrd-iso
gzip -dc ${LIVE_MOUNT}/install/initrd.gz | cpio -i
cd ${TMP_DIR}/initrd-hd-media
gzip -dc ${FETCH_DIR}/initrd.gz | cpio -i
rsync -av --delete --progress ${TMP_DIR}/initrd-iso/lib/modules ${TMP_DIR}/initrd-hd-media/lib/modules
# Tell initrd where we will place the iso
sed -i "s/iso_to_try=\\\\\\$1/iso_to_try=\\/hd-media\\/${NAME}\\/${NAME}.iso/" ${TMP_DIR}/initrd-hd-media/var/lib/dpkg/info/iso-scan.postinst
find . | cpio -o -H newc | gzip -9 > ${USB_MOUNT}/${NAME}/initrd.gz
cd -
# Add iso and kernel to install dir
rsync -av --progress ${FETCH_DIR}/${NAME}.iso ${USB_MOUNT}/${NAME}/
rsync -av --progress ${LIVE_MOUNT}/install/vmlinuz ${USB_MOUNT}/${NAME}/
}
################################### ubuntu-server ####################################
DIST=lucid
ARCH=amd64
VERSION=10.04.3
NAME="ubuntu-${VERSION}-server-${ARCH}"
UBUNTU_SERVER
cat <<EOF>> ${USB_MOUNT}/boot/grub/grub.cfg
menuentry "${NAME}" {
set root='(hd1,1)'
linux /${NAME}/vmlinuz auto=true priority=critical file=/hd-media/${NAME}/ubuntu.seed noeject noprompt toram --
initrd /${NAME}/initrd.gz
}
EOF
# sync working copy with the "removeable" media
mount /dev/sdb1 /hd-media/
rsync -av --progress --delete ${USB_MOUNT}/ /hd-media/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment