c1786723e5ad4da6248ce8967bb769adb0779915
[ext/instance-debootstrap.git] / create
1 #!/bin/sh
2
3 # Copyright (C) 2007 Google Inc.
4 #
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.
9 #
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.
14 #
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
18 # 02110-1301, USA.
19
20 set -e
21
22 # Customize this if you need another mirror, or set to empty to get the
23 # node's sources.list
24 MIRROR="http://ftp.debian.org/debian"
25
26 TEMP=`getopt -o i:b:s: -n '$0' -- "$@"`
27
28 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
29
30 # Note the quotes around `$TEMP': they are essential!
31 eval set -- "$TEMP"
32
33 while true; do 
34         case "$1" in
35                 -i) instance=$2; shift 2;;
36
37                 -b) blockdev=$2; shift 2;;
38
39                 -s) swapdev=$2; shift 2;;
40
41                 --) shift; break;;
42
43                 *)  echo "Internal error!"; exit 1;;
44         esac
45 done
46 if [ -z "$instance" -o -z "$blockdev" -o -z "$swapdev" ]; then
47         echo "Missing -i or -b or -s argument!"
48         exit 1
49 fi
50
51 mkswap $swapdev
52 mke2fs -Fjq $blockdev
53 TMPDIR=`mktemp -d` || exit 1
54 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
55 mount $blockdev $TMPDIR
56
57 # On i386, we need the xen-specific library
58 DPKG_ARCH="`dpkg --print-architecture`"
59 if [ "$DPKG_ARCH" = "i386" ]; then
60         EXTRAPKG="linux-image-xen-686 libc6-xen"
61 elif [ "$DPKG_ARCH" = "amd64" ]; then
62         EXTRAPKG="linux-image-xen-amd64"
63 fi
64
65 debootstrap --include="$EXTRAPKG" etch $TMPDIR $MIRROR
66
67 # remove the persistent-net rules, otherwise it will remember the node's
68 # interfaces as eth0, eth1, ...
69
70 rm -f "$TMPDIR/etc/udev/rules.d/z25_persistent-net.rules"
71
72 cp -p /etc/hosts $TMPDIR/etc/hosts
73 cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
74 echo $instance > $TMPDIR/etc/hostname
75 echo $instance > $TMPDIR/etc/mailname
76
77 cat > $TMPDIR/etc/fstab <<EOF
78 # /etc/fstab: static file system information.
79 #
80 # <file system> <mount point>   <type>  <options>       <dump>  <pass>
81 /dev/sda        /               ext3    defaults        0       1
82 /dev/sdb        swap            swap    defaults        0       0
83 proc            /proc           proc    defaults        0       0
84 EOF
85
86 cat > $TMPDIR/etc/network/interfaces <<EOF
87 auto lo
88 iface lo inet loopback
89 EOF
90
91 umount $TMPDIR
92 rmdir $TMPDIR
93 trap - EXIT
94
95 exit 0