3 # Build PlanetLab-Bootstrap.tar.bz2, the reference image for PlanetLab
4 # nodes. Requires the web and boot servers to be up, which complicates
5 # bootstrap. Alternatively, we could require the build server to host
6 # a local yum repository. Already, it is required to run the same
7 # major version of yum as the nodes.
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2005 The Trustees of Princeton University
12 # $Id: buildnode.sh,v 1.5.2.1 2006/05/08 21:52:43 mlhuang Exp $
15 # Get the production /etc/yum.conf file. XXX When MAs begin deploying
16 # their own boot servers and/or code, this will have to change.
17 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
19 # Solve the bootstrap problem by including any just built packages in
20 # the yum configuration. This cooperates with the PlanetLab build
22 if [ -n "$RPM_BUILD_DIR" ] ; then
23 # Remove any [PlanetLab*] sections
24 sed -i -f - yum.conf <<EOF
25 # Match lines between [PlanetLab*] and the next [*
26 /\[PlanetLab.*\]/I,/^\[/{
36 # And replace them with a section for the RPMS that were just built
37 yum-arch $(dirname $RPM_BUILD_DIR)/RPMS
38 createrepo -g yumgroups.xml $(dirname $RPM_BUILD_DIR)/RPMS || :
39 # If run under sudo, allow user to delete the headers/ and
40 # repodata/ directories.
41 if [ -n "$SUDO_USER" ] ; then
42 chown -R $SUDO_USER $(dirname $RPM_BUILD_DIR)/RPMS
46 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
47 baseurl=file://$(dirname $RPM_BUILD_DIR)/RPMS/
52 VROOT=$PWD/PlanetLab-Bootstrap
53 install -d -m 755 $VROOT
59 mknod -m 666 $VROOT/dev/null c 1 3
60 mknod -m 666 $VROOT/dev/zero c 1 5
61 mknod -m 666 $VROOT/dev/full c 1 7
62 mknod -m 644 $VROOT/dev/random c 1 8
63 mknod -m 644 $VROOT/dev/urandom c 1 9
64 mknod -m 666 $VROOT/dev/tty c 5 0
65 mknod -m 666 $VROOT/dev/ptmx c 5 2
66 # For bash command substitution
67 ln -nsf ../proc/self/fd /dev/fd
68 # For df and linuxconf
72 # Initialize /dev in reference image
75 # Mount /dev/pts in reference image
76 mkdir -p $VROOT/dev/pts
77 mount -t devpts none $VROOT/dev/pts
79 # Mount /proc in reference image
81 mount -t proc none $VROOT/proc
83 # Clean up before exiting if anything goes wrong
84 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
86 # Create a dummy /etc/fstab in reference image
88 cat > $VROOT/etc/fstab <<EOF
89 # This fake fstab exists only to please df and linuxconf.
90 /dev/hdv1 / ext2 defaults 1 1
92 cp $VROOT/etc/fstab $VROOT/etc/mtab
94 # Prevent all locales from being installed in reference image
95 mkdir -p $VROOT/etc/rpm
96 cat > $VROOT/etc/rpm/macros <<EOF
97 %_install_langs en_US:en
99 %__file_context_path /dev/null
102 # Trick rpm and yum, who read the real root /etc/rpm/macros file
103 # rather than the one installed in the reference image, despite what
104 # you might expect the --root and --installroot options to mean. Both
105 # programs always read $HOME/.rpmmacros.
107 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
109 # Initialize RPM database in reference image
110 mkdir -p $VROOT/var/lib/rpm
111 rpm --root $VROOT --initdb
113 # glibc must be specified explicitly for the correct arch to be chosen.
114 yum -c yum.conf --installroot=$VROOT -y install glibc yum
116 # yum will annoyingly use the /etc/yum.conf file in the --installroot
117 # even if overridden with -c
118 rm -f $VROOT/etc/yum.conf
120 # Some of the PlanetLab RPMs may attempt to call /sbin/runlevel to
121 # determine if the installation is running inside the BootCD
122 # environment. We would like to pretend that we are, so make sure
123 # /sbin/runlevel returns 'unknown'.
124 rm -f $VROOT/var/run/utmp
128 yum -c yum.conf --installroot=$VROOT -y groupinstall PlanetLab
131 yum -c yum.conf --installroot=$VROOT -y clean all
133 # Remove stale RPM locks
134 rm -f $VROOT/var/lib/rpm/__db*
136 # Clean up /dev in reference image
137 umount $VROOT/dev/pts
139 # Disable unnecessary services
140 for service in netfs rawdevices cpuspeed smartd ; do
141 /usr/sbin/chroot $VROOT /sbin/chkconfig $service off
148 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C $VROOT .