Improve performance of the debian-etch-debootstrap OS
authorIustin Pop <iustin@google.com>
Wed, 28 Nov 2007 07:48:24 +0000 (07:48 +0000)
committerIustin Pop <iustin@google.com>
Wed, 28 Nov 2007 07:48:24 +0000 (07:48 +0000)
This patch enables the debian-etch-debootstrap instance to generate (and
subsequently use) a cache file on the first install. Because, even with
a very fast mirror, debootstrap itself is slow, saving the installed
image and afterwards just untar-ing that over the filesystem is much
faster.

The patch also adds a 'version' file so that users can see what they
have installed (maybe in the future we could use require this file so we
know what versions of the OS we have installed).

Reviewed-by: ultrotter

README
create
version [new file with mode: 0644]

diff --git a/README b/README
index fe2d22a..4f7a558 100644 (file)
--- a/README
+++ b/README
@@ -10,3 +10,22 @@ Notes:
  - no password for root; simply login at the console
  - no network interfaces defined (besides lo); add your own definitions to
    /etc/network/interfaces
+
+Since version 0.3, the OS will cache the image of the first instance it
+installs using the name "cache-$arch.tar" (where $arch is what dpkg
+--print-architecture returns). This cache will be then used on the
+future installs, speeding them greatly (even with a fast mirror). Feel
+free to remove the cache at any time, or to copy it to all nodes. The
+cache will be kept for two weeks, after which the first install will
+recreate the cache (in order not to use old packages). If you don't care
+about package age, remove the user write permission (chmod u-w) from the
+cache and ganeti will continue to use the same file without refreshing
+it.
+
+If you don't have enough space and don't want cache creation, just touch
+the file 'no_cache' - this will prevent the creation, but the script
+will continue to use a cache if it exists (but it will remove an
+existing one after two weeks).
+
+Also note that if the image file is there, the script does not need
+network access at all.
diff --git a/create b/create
index c178672..661f364 100755 (executable)
--- a/create
+++ b/create
@@ -22,6 +22,8 @@ set -e
 # Customize this if you need another mirror, or set to empty to get the
 # node's sources.list
 MIRROR="http://ftp.debian.org/debian"
+DPKG_ARCH="`dpkg --print-architecture`"
+CACHE_FILE="cache-${DPKG_ARCH}.tar"
 
 TEMP=`getopt -o i:b:s: -n '$0' -- "$@"`
 
@@ -54,20 +56,36 @@ TMPDIR=`mktemp -d` || exit 1
 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
 mount $blockdev $TMPDIR
 
-# On i386, we need the xen-specific library
-DPKG_ARCH="`dpkg --print-architecture`"
-if [ "$DPKG_ARCH" = "i386" ]; then
-       EXTRAPKG="linux-image-xen-686 libc6-xen"
-elif [ "$DPKG_ARCH" = "amd64" ]; then
-       EXTRAPKG="linux-image-xen-amd64"
+# remove the cache file if it's old (> 2 weeks) and writable by the owner (the
+# default due to the standard umask)
+if [ -f "$CACHE_FILE" ]; then
+       find "$CACHE_FILE" -perm -0200 -daystart -mtime +14 -print0 | \
+               xargs -r0 rm
 fi
 
-debootstrap --include="$EXTRAPKG" etch $TMPDIR $MIRROR
+if [ -f "$CACHE_FILE" ]; then
+       tar xf "$CACHE_FILE" -C $TMPDIR
+else
+       # On i386, we need the xen-specific library
+       if [ "$DPKG_ARCH" = "i386" ]; then
+               EXTRAPKG="linux-image-xen-686 libc6-xen"
+       elif [ "$DPKG_ARCH" = "amd64" ]; then
+               EXTRAPKG="linux-image-xen-amd64"
+       fi
+
+       debootstrap --include="$EXTRAPKG" etch $TMPDIR $MIRROR
 
-# remove the persistent-net rules, otherwise it will remember the node's
-# interfaces as eth0, eth1, ...
+       # remove the persistent-net rules, otherwise it will remember the node's
+       # interfaces as eth0, eth1, ...
 
-rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
+       rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
+
+       if [ ! -e no_cache ]; then
+               TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"`
+               tar cf "$TMP_CACHE" -C $TMPDIR .
+               mv "$TMP_CACHE" "$CACHE_FILE"
+       fi
+fi
 
 cp -p /etc/hosts $TMPDIR/etc/hosts
 cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
diff --git a/version b/version
new file mode 100644 (file)
index 0000000..be58634
--- /dev/null
+++ b/version
@@ -0,0 +1 @@
+0.3