07d01ab1517249424232f37f6ce2b272dce36242
[sliceimage.git] / vserver-reference.init
1 #!/bin/bash
2 #
3 # Builds VServer reference image. Requires the web and boot servers to
4 # be up, which complicates bootstrap. Alternatively, we could require
5 # the build server to host a local yum repository. Already, it is
6 # required to run the same major version of yum as the nodes.
7 #
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2004-2005 The Trustees of Princeton University
10 #
11 # $Id: vserver-reference.init,v 1.13 2005/09/01 17:51:26 mlhuang Exp $
12 #
13
14 YUM_CONF="http://www.planet-lab.org/PlanetLabConf/v3-yum.conf"
15
16 # Make /vservers
17 VROOT=$PWD/vservers/vserver-reference
18 install -d -m 755 $VROOT
19
20 MAKEDEV ()
21 {
22     rm -rf $VROOT/dev
23     mkdir -p $VROOT/dev
24     mknod -m 666 $VROOT/dev/null c 1 3
25     mknod -m 666 $VROOT/dev/zero c 1 5
26     mknod -m 666 $VROOT/dev/full c 1 7
27     mknod -m 644 $VROOT/dev/random c 1 8
28     mknod -m 644 $VROOT/dev/urandom c 1 9
29     mknod -m 666 $VROOT/dev/tty c 5 0
30     mknod -m 666 $VROOT/dev/ptmx c 5 2
31     # For bash command substitution
32     ln -nsf ../proc/self/fd /dev/fd
33     # For df and linuxconf
34     touch $VROOT/dev/hdv1
35     # For TUN/TAP
36     mkdir -p $VROOT/dev/net
37     mknod -m 600 $VROOT/dev/net/tun c 10 200
38 }
39
40 # Initialize /dev in reference image
41 MAKEDEV
42
43 # Mount /dev/pts in reference image
44 mkdir -p $VROOT/dev/pts
45 mount -t devpts none $VROOT/dev/pts
46
47 # Mount /proc in reference image
48 mkdir -p $VROOT/proc
49 mount -t proc none $VROOT/proc
50
51 # Clean up before exiting if anything goes wrong
52 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
53
54 # Create a dummy /etc/fstab in reference image
55 mkdir -p $VROOT/etc
56 cat > $VROOT/etc/fstab <<EOF
57 # This fake fstab exists only to please df and linuxconf.
58 /dev/hdv1       /       ext2    defaults        1 1
59 EOF
60 cp $VROOT/etc/fstab $VROOT/etc/mtab
61
62 # Prevent all locales from being installed in reference image
63 mkdir -p $VROOT/etc/rpm
64 cat > $VROOT/etc/rpm/macros <<EOF
65 %_install_langs en_US:en
66 %_excludedocs 1
67 %__file_context_path /dev/null
68 EOF
69
70 # This tells the Boot Manager that it is okay to update
71 # /etc/resolv.conf and /etc/hosts whenever the network configuration
72 # changes. Users are free to delete this file.
73 touch $VROOT/etc/AUTO_UPDATE_NET_FILES
74
75 # Trick rpm and yum, who read the real root /etc/rpm/macros file
76 # rather than the one installed in the reference image, despite what
77 # you might expect the --root and --installroot options to mean. Both
78 # programs always read $HOME/.rpmmacros.
79 export HOME=$PWD
80 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
81
82 # Initialize RPM database in reference image
83 mkdir -p $VROOT/var/lib/rpm
84 rpm --root $VROOT --initdb
85
86 # Go, baby, go
87 yum -c $YUM_CONF --installroot=$VROOT -y groupinstall VServer
88
89 # Freshen the RPM set with any just built. This does not help when a
90 # completely new PlanetLab package must be installed in the reference
91 # image. To work around this limitation, introduce the new package in
92 # one release, then include it in the VServer yumgroup in the next.
93 FRESHEN=$RPM_BUILD_DIR/../RPMS/*/*.rpm
94 if [ -n "$FRESHEN" ] ; then
95     rpm --root $VROOT --freshen --verbose $FRESHEN
96 fi
97
98 # Remove stale RPM locks
99 rm -f $VROOT/var/lib/rpm/__db*
100
101 # Clean up /dev in reference image
102 umount $VROOT/dev/pts
103 MAKEDEV
104
105 # Disable all services in reference image
106 /usr/sbin/chroot $VROOT /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"
107
108 # Clean up
109 umount $VROOT/proc
110
111 exit 0