3 # Copyright (C) 2007, 2008, 2009 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
24 if [ "$GENERATE_CACHE" = "yes" -a ! -d "$CACHE_DIR" ]; then
28 DPKG_ARCH=${ARCH:-`dpkg --print-architecture`}
29 CACHE_FILE="$CACHE_DIR/cache-${SUITE}-${DPKG_ARCH}.tar"
31 # If the target device is not a real block device we'll first losetup it.
32 # This is needed for file disks.
33 if [ ! -b $blockdev ]; then
34 ORIGINAL_BLOCKDEV=$blockdev
35 blockdev=$(losetup -sf $blockdev)
36 CLEANUP+=("losetup -d $blockdev")
39 if [ "$PARTITION_STYLE" = "none" ]; then
40 filesystem_dev=$blockdev
41 elif [ "$PARTITION_STYLE" = "msdos" ]; then
42 # Create one big partition, and make it bootable
43 format_disk0 $blockdev
44 filesystem_dev=$(map_disk0 $blockdev)
45 CLEANUP+=("unmap_disk0 $blockdev")
47 echo "Unknown partition style $PARTITION_STYLE"
51 mke2fs -Fjq $filesystem_dev
52 root_uuid=$($VOL_ID -u $filesystem_dev )
54 if [ -n "$swapdev" ]; then
56 swap_uuid=$($VOL_ID -u $swapdev || true )
59 TMPDIR=`mktemp -d` || exit 1
60 CLEANUP+=("rmdir $TMPDIR")
62 mount $filesystem_dev $TMPDIR
63 CLEANUP+=("umount $TMPDIR")
65 # remove the cache file if it's old (> 2 weeks) and writable by the owner (the
66 # default due to the standard umask)
67 if [ "$CLEAN_CACHE" -a -d "$CACHE_DIR" ]; then
68 find "$CACHE_DIR" -name 'cache-*.tar' -type f \
69 -daystart -mtime "+${CLEAN_CACHE}" -print0 | \
73 if [ -f "$CACHE_FILE" ]; then
74 tar xf "$CACHE_FILE" -C $TMPDIR
77 export http_proxy="$PROXY"
79 # INCLUDE will be empty if EXTRA_PKGS is null/empty, otherwise we
80 # build the full parameter format from it
81 INCLUDE=${EXTRA_PKGS:+"--include=$EXTRA_PKGS"}
85 "$SUITE" $TMPDIR $MIRROR
87 # remove the downloaded debs, as they are no longer needed
88 find "$TMPDIR/var/cache/apt/archives" -type f -name '*.deb' -print0 | \
91 # remove the persistent-net rules, otherwise it will remember the node's
92 # interfaces as eth0, eth1, ...
93 rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
95 if [ "$GENERATE_CACHE" = "yes" ]; then
96 TMP_CACHE=`mktemp "${CACHE_FILE}.XXXXXX"`
97 tar cf "$TMP_CACHE" -C $TMPDIR .
98 mv -f "$TMP_CACHE" "$CACHE_FILE"
102 cp -p /etc/hosts $TMPDIR/etc/hosts
103 cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
104 echo $instance > $TMPDIR/etc/hostname
105 echo $instance > $TMPDIR/etc/mailname
107 cat > $TMPDIR/etc/fstab <<EOF
108 # /etc/fstab: static file system information.
110 # <file system> <mount point> <type> <options> <dump> <pass>
111 UUID=$root_uuid / ext3 defaults 0 1
112 proc /proc proc defaults 0 0
115 [ -n "$swapdev" -a -n "$swap_uuid" ] && cat >> $TMPDIR/etc/fstab <<EOF
116 UUID=$swap_uuid swap swap defaults 0 0
119 cat > $TMPDIR/etc/network/interfaces <<EOF
121 iface lo inet loopback
124 if [ -e $TMPDIR/etc/inittab ]; then
125 cat $TMPDIR/etc/inittab | sed -re 's/\stty1$/ console/' \
126 > $TMPDIR/etc/inittab.new
127 mv $TMPDIR/etc/inittab.new $TMPDIR/etc/inittab
128 elif [ -e $TMPDIR/etc/event.d/tty1 ]; then
129 cat $TMPDIR/etc/event.d/tty1 | sed -re 's/tty1/console/' \
130 > $TMPDIR/etc/event.d/console
131 rm $TMPDIR/etc/event.d/tty1
134 RUN_PARTS=`which run-parts`
136 if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
139 FSYSDEV=$filesystem_dev
140 export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV FSYSDEV
141 $RUN_PARTS $CUSTOMIZE_DIR