Skip to content

Instantly share code, notes, and snippets.

@DazWorrall
Created December 13, 2012 15:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save DazWorrall/4277257 to your computer and use it in GitHub Desktop.
Save DazWorrall/4277257 to your computer and use it in GitHub Desktop.
Little script to create a minimal ubuntu using debootstrap and bring it up to date
#!/bin/bash
set -e
DEFAULT_PACKAGES=ssh,language-pack-en-base
DEFAULT_COMPONENTS=main,universe
DEBOOTSTRAP=/usr/sbin/debootstrap
DEFAULT_MIRROR=http://archive.ubuntu.com/ubuntu
DEFAULT_VARIANT=minbase
MIRROR=${STRAP_MIRROR:-$DEFAULT_MIRROR}
ROOTFS=$1
PACKAGES=${STRAP_PACKAGES:-$DEFAULT_PACKAGES}
COMPONENTS=${STRAP_COMPONENTS:-$DEFAULT_COMPONENTS}
SUITE=${STRAP_SUITE:-precise}
VARIANT=${STRAP_VARIANT:-$DEFAULT_VARIANT}
type $DEBOOTSTRAP >/dev/null
if [ $? -ne 0 ]; then
echo "debootstrap not installed"
exit 1
fi
if [ "x$ROOTFS" == "x" ]; then
echo "Usage: $0 <path_to_root>"
exit 1
fi
$DEBOOTSTRAP --include $PACKAGES --components $COMPONENTS --variant $VARIANT $SUITE $ROOTFS $MIRROR
cat > $ROOTFS/etc/apt/sources.list << EOF
deb $MIRROR $SUITE ${COMPONENTS//,/ }
deb $MIRROR $SUITE-updates ${COMPONENTS//,/ }
deb $MIRROR $SUITE-security ${COMPONENTS//,/ }
EOF
chroot $ROOTFS mount -t proc /proc /proc
chroot $ROOTFS apt-get update
chroot $ROOTFS apt-get dist-upgrade -y
umount $ROOTFS/proc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment