- script to build node tarball
[bootmanager.git] / support-files / buildnode.sh
1 #!/bin/bash
2 #
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.
8 #
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2005 The Trustees of Princeton University
11 #
12 # $Id$
13 #
14
15 # Get the URL for the production /etc/yum.conf file. XXX When MAs
16 # begin deploying their own boot servers and/or code, this will have
17 # to change.
18 YUM_CONF=http://boot.planet-lab.org/$(curl --silent --insecure --form node_id=0 --form file=/etc/yum.conf https://boot.planet-lab.org/db/plnodeconf/getsinglefile.php)
19
20 # Make /
21 VROOT=$PWD/PlanetLab-Bootstrap
22 install -d -m 755 $VROOT
23
24 MAKEDEV ()
25 {
26     rm -rf $VROOT/dev
27     mkdir -p $VROOT/dev
28     mknod -m 666 $VROOT/dev/null c 1 3
29     mknod -m 666 $VROOT/dev/zero c 1 5
30     mknod -m 666 $VROOT/dev/full c 1 7
31     mknod -m 644 $VROOT/dev/random c 1 8
32     mknod -m 644 $VROOT/dev/urandom c 1 9
33     mknod -m 666 $VROOT/dev/tty c 5 0
34     mknod -m 666 $VROOT/dev/ptmx c 5 2
35     # For bash command substitution
36     ln -nsf ../proc/self/fd /dev/fd
37     # For df and linuxconf
38     touch $VROOT/dev/hdv1
39 }
40
41 # Initialize /dev in reference image
42 MAKEDEV
43
44 # Mount /dev/pts in reference image
45 mkdir -p $VROOT/dev/pts
46 mount -t devpts none $VROOT/dev/pts
47
48 # Mount /proc in reference image
49 mkdir -p $VROOT/proc
50 mount -t proc none $VROOT/proc
51
52 # Clean up before exiting if anything goes wrong
53 trap "umount $VROOT/proc ; umount $VROOT/dev/pts ; exit 255" ERR
54
55 # Create a dummy /etc/fstab in reference image
56 mkdir -p $VROOT/etc
57 cat > $VROOT/etc/fstab <<EOF
58 # This fake fstab exists only to please df and linuxconf.
59 /dev/hdv1       /       ext2    defaults        1 1
60 EOF
61 cp $VROOT/etc/fstab $VROOT/etc/mtab
62
63 # Prevent all locales from being installed in reference image
64 mkdir -p $VROOT/etc/rpm
65 cat > $VROOT/etc/rpm/macros <<EOF
66 %_install_langs en_US:en
67 %_excludedocs 1
68 %__file_context_path /dev/null
69 EOF
70
71 # Trick rpm and yum, who read the real root /etc/rpm/macros file
72 # rather than the one installed in the reference image, despite what
73 # you might expect the --root and --installroot options to mean. Both
74 # programs always read $HOME/.rpmmacros.
75 export HOME=$PWD
76 ln -sf $VROOT/etc/rpm/macros $PWD/.rpmmacros
77
78 # Initialize RPM database in reference image
79 mkdir -p $VROOT/var/lib/rpm
80 rpm --root $VROOT --initdb
81
82 # glibc must be specified explicitly for the correct arch to be chosen
83 yum -c $YUM_CONF --installroot=$VROOT -y install glibc yum
84
85 # yum will annoyingly use the /etc/yum.conf file in the --installroot
86 # even if overridden with -c
87 rm -f $VROOT/etc/yum.conf
88
89 # Some of the PlanetLab RPMs may attempt to call /sbin/runlevel to
90 # determine if the installation is running inside the BootCD
91 # environment. We would like to pretend that we are, so make sure
92 # /sbin/runlevel returns 'unknown'.
93 rm -f $VROOT/var/run/utmp
94 export PL_BOOTCD=1
95
96 # Go, baby, go
97 yum -c $YUM_CONF --installroot=$VROOT -y groupinstall PlanetLab
98
99 # Freshen the RPM set with any just built. This does not help when a
100 # completely new PlanetLab package must be installed in the reference
101 # image. To work around this limitation, introduce the new package in
102 # one release, then include it in the VServer yumgroup in the next.
103 if [ -d $RPM_BUILD_DIR/../RPMS ] ; then
104     rpm --root $VROOT --freshen --verbose $RPM_BUILD_DIR/../RPMS/*/*.rpm
105 fi
106
107 # Remove stale RPM locks
108 rm -f $VROOT/var/lib/rpm/__db*
109
110 # Clean up /dev in reference image
111 umount $VROOT/dev/pts
112
113 # Disable unnecessary services
114 for service in netfs rawdevices cpuspeed smartd ; do
115     /usr/sbin/chroot $VROOT /sbin/chkconfig $service off
116 done
117
118 # Clean up
119 umount $VROOT/proc
120
121 # Build tarball
122 tar -cpjf PlanetLab-Bootstrap.tar.bz2 -C $VROOT .
123 rm -rf $VROOT
124
125 exit 0