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.
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2004-2005 The Trustees of Princeton University
11 # $Id: build.sh,v 1.2 2005/10/01 18:20:08 mlhuang Exp $
14 # Get the production /etc/yum.conf file. XXX When MAs begin deploying
15 # their own boot servers and/or code, this will have to change.
16 curl --silent http://boot.planet-lab.org/$(curl --silent --insecure --form node_id=1 --form file=/etc/yum.conf https://boot.planet-lab.org/db/plnodeconf/getsinglefile.php) > yum.conf
18 # Solve the bootstrap problem by including any just built packages in
19 # the yum configuration. This cooperates with the PlanetLab build
21 if [ -n "$RPM_BUILD_DIR" ] ; then
22 # Remove any [PlanetLab*] sections
23 sed -i -f - yum.conf <<EOF
24 # Match lines between [PlanetLab*] and the next [*
25 /\[PlanetLab.*\]/I,/^\[/{
35 # And replace them with a section for the RPMS that were just built
36 yum-arch $(dirname $RPM_BUILD_DIR)/RPMS
39 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
40 baseurl=file://$(dirname $RPM_BUILD_DIR)/RPMS/
45 VROOT=$PWD/vservers/vserver-reference
46 install -d -m 755 $VROOT
52 mknod -m 666 $VROOT/dev/null c 1 3
53 mknod -m 666 $VROOT/dev/zero c 1 5
54 mknod -m 666 $VROOT/dev/full c 1 7
55 mknod -m 644 $VROOT/dev/random c 1 8
56 mknod -m 644 $VROOT/dev/urandom c 1 9
57 mknod -m 666 $VROOT/dev/tty c 5 0
58 mknod -m 666 $VROOT/dev/ptmx c 5 2
59 # For bash command substitution
60 ln -nsf ../proc/self/fd /dev/fd
61 # For df and linuxconf
64 mkdir -p $VROOT/dev/net
65 mknod -m 600 $VROOT/dev/net/tun c 10 200
68 # Initialize /dev in reference image
71 # Mount /dev/pts in reference image
72 mkdir -p $VROOT/dev/pts
73 mount -t devpts none $VROOT/dev/pts
75 # Mount /proc in reference image
77 mount -t proc none $VROOT/proc
79 # Clean up before exiting if anything goes wrong
80 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
82 # Create a dummy /etc/fstab in reference image
84 cat > $VROOT/etc/fstab <<EOF
85 # This fake fstab exists only to please df and linuxconf.
86 /dev/hdv1 / ext2 defaults 1 1
88 cp $VROOT/etc/fstab $VROOT/etc/mtab
90 # Prevent all locales from being installed in reference image
91 mkdir -p $VROOT/etc/rpm
92 cat > $VROOT/etc/rpm/macros <<EOF
93 %_install_langs en_US:en
95 %__file_context_path /dev/null
98 # This tells the Boot Manager that it is okay to update
99 # /etc/resolv.conf and /etc/hosts whenever the network configuration
100 # changes. Users are free to delete this file.
101 touch $VROOT/etc/AUTO_UPDATE_NET_FILES
103 # Trick rpm and yum, who read the real root /etc/rpm/macros file
104 # rather than the one installed in the reference image, despite what
105 # you might expect the --root and --installroot options to mean. Both
106 # programs always read $HOME/.rpmmacros.
108 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
110 # Initialize RPM database in reference image
111 mkdir -p $VROOT/var/lib/rpm
112 rpm --root $VROOT --initdb
115 yum -c yum.conf --installroot=$VROOT -y groupinstall VServer
117 # Remove stale RPM locks
118 rm -f $VROOT/var/lib/rpm/__db*
120 # Clean up /dev in reference image
121 umount $VROOT/dev/pts
124 # Disable all services in reference image
125 /usr/sbin/chroot $VROOT /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"