3 # Copyright (C) 2007 Google Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # Customize this if you need another mirror, or set to empty to get the
24 MIRROR="http://ftp.debian.org/debian"
25 DPKG_ARCH="`dpkg --print-architecture`"
26 CACHE_FILE="cache-${DPKG_ARCH}.tar"
28 TEMP=`getopt -o i:b:s: -n '$0' -- "$@"`
30 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
32 # Note the quotes around `$TEMP': they are essential!
37 -i) instance=$2; shift 2;;
39 -b) blockdev=$2; shift 2;;
41 -s) swapdev=$2; shift 2;;
45 *) echo "Internal error!"; exit 1;;
48 if [ -z "$instance" -o -z "$blockdev" -o -z "$swapdev" ]; then
49 echo "Missing -i or -b or -s argument!"
55 TMPDIR=`mktemp -d` || exit 1
56 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
58 # If it's not a block device try to mount it via loopback device.
59 # This is needed for file disks.
61 if [ ! -b $blockdev ]; then
62 MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop"
64 mount $MOUNT_OPTIONS $blockdev $TMPDIR
66 # remove the cache file if it's old (> 2 weeks) and writable by the owner (the
67 # default due to the standard umask)
68 if [ -f "$CACHE_FILE" ]; then
69 find "$CACHE_FILE" -perm -0200 -daystart -mtime +14 -print0 | \
73 if [ -f "$CACHE_FILE" ]; then
74 tar xf "$CACHE_FILE" -C $TMPDIR
76 # On i386, we need the xen-specific library
77 if [ "$DPKG_ARCH" = "i386" ]; then
78 EXTRAPKG="linux-image-xen-686 libc6-xen"
79 elif [ "$DPKG_ARCH" = "amd64" ]; then
80 EXTRAPKG="linux-image-xen-amd64"
83 debootstrap --include="$EXTRAPKG" etch $TMPDIR $MIRROR
85 # remove the downloaded debs, as they are no longer needed
86 find "$TMPDIR/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
89 # remove the persistent-net rules, otherwise it will remember the node's
90 # interfaces as eth0, eth1, ...
92 rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
94 if [ ! -e no_cache ]; then
95 TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"`
96 tar cf "$TMP_CACHE" -C $TMPDIR .
97 mv -f "$TMP_CACHE" "$CACHE_FILE"
101 cp -p /etc/hosts $TMPDIR/etc/hosts
102 cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
103 echo $instance > $TMPDIR/etc/hostname
104 echo $instance > $TMPDIR/etc/mailname
106 cat > $TMPDIR/etc/fstab <<EOF
107 # /etc/fstab: static file system information.
109 # <file system> <mount point> <type> <options> <dump> <pass>
110 /dev/sda / ext3 defaults 0 1
111 /dev/sdb swap swap defaults 0 0
112 proc /proc proc defaults 0 0
115 cat > $TMPDIR/etc/network/interfaces <<EOF
117 iface lo inet loopback