3 # Build bootstrapfs-*.tar.bz2, the reference image(s) for PlanetLab nodes.
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Marc E. Fiuczynski <mef@cs.princeton.edu>
7 # Copyright (C) 2005-2007 The Trustees of Princeton University
13 # This will build the bootstrafs-*.tar.bz2 images, which comprises
14 # the base root image on the node, then create the ${NAME} bootstrap image
15 # which is made up of just the additional files needed for a ${NAME} nodegroup
18 # It is expected to be in sync with the getNodeFlavour PLCAPI method
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin
22 # in the PlanetLab build environment, our dependencies are checked out
23 # into directories at the same level as us.
24 if [ -d ../build ] ; then
28 echo "Error: Could not find ../build in $(pwd)"
36 pl_process_fedora_options $@
40 # expecting fcdistro and pldistro on the command line
42 fcdistro=${pl_DISTRO_NAME}
43 arch=${pl_DISTRO_ARCH}
44 nodefamily=${pldistro}-${fcdistro}-${arch}
45 extensionfamily=${fcdistro}-${arch}
47 # Do not tolerate errors
50 # Some of the PlanetLab RPMs attempt to (re)start themselves in %post,
51 # unless the installation is running inside the BootCD environment. We
52 # would like to pretend that we are.
55 # Populate a minimal /dev and then the files for the base bootstrapfs content
57 install -d -m 755 ${vref}
58 pl_root_makedevs $vref
60 pkgsfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.pkgs)
61 echo "* Building Bootstrapfs for ${pldistro}: $(date)"
62 # -k = exclude kernel* packages
63 pl_root_mkfedora ${vref} ${pldistro} $pkgsfile
65 # optionally invoke a post processing script after packages from
66 # $pkgsfile have been installed
67 postfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs.post || : )
68 [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vref} || : ; }
72 # for distros that do not define bootstrapfs variants
73 pkgs_count=$(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs 2> /dev/null | wc -l)
74 [ $pkgs_count -gt 0 ] && for pkgs in $(ls ../build/config.${pldistro}/bootstrapfs-*.pkgs); do
75 NAME=$(basename $pkgs .pkgs | sed -e s,bootstrapfs-,,)
77 [ -z "$displayed" ] && echo "* Handling ${pldistro} bootstrapfs extensions"
80 extension_plain=bootstrapfs-${NAME}-${extensionfamily}.tar
81 extension_name=bootstrapfs-${NAME}-${extensionfamily}.tar.bz2
83 echo "* Start Building $extension_name: $(date)"
85 # "Parse" out the packages and groups for yum
86 packages=$(pl_getPackages $fcdistro $pldistro $pkgs)
87 groups=$(pl_getGroups $fcdistro $pldistro $pkgs)
88 echo "${NAME} has the following packages : ${packages}"
89 echo "${NAME} has the following groups : ${groups}"
91 vdir=${PWD}/${pldistro}-filesystems/${NAME}
93 install -d -m 755 ${vdir}
95 # Clone the base reference to the bootstrap fs
96 (cd ${vref} && find . | cpio -m -d -u -p ${vdir})
97 rm -f ${vdir}/var/lib/rpm/__db*
99 # Install the system vserver specific packages
100 [ -n "$packages" ] && yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y install $packages
101 for group_plus in $groups; do
102 group=$(echo $group_plus | sed -e "s,+++, ,g")
103 yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y groupinstall "$group"
107 if [ -f "${vdir}/proc/cpuinfo" ] ; then
108 echo "WARNING: some RPM appears to have mounted /proc in ${NAME}. Unmounting it!"
112 # optionally invoke a post processing script after packages from
113 # $pkgs have been installed
114 postfile=$(pl_locateDistroFile ../build/ ${pldistro} bootstrapfs-${NAME}.post || : )
115 [ -f $postfile ] && { echo "Running post install file $postfile" ; /bin/bash $postfile ${vdir} || : ; }
117 # Create a copy of the ${NAME} bootstrap filesystem w/o the base
118 # bootstrap filesystem and make it smaller. This is a three step
121 # step 1: clean out yum cache to reduce space requirements
122 yum -c ${vdir}/etc/mkfedora-yum.conf --installroot=${vdir} -y clean all
124 # step 2: figure out the new/changed files in ${vdir} vs. ${vref} and compute ${vdir}.changes
125 rsync -anv ${vdir}/ ${vref}/ > ${vdir}.changes
126 linecount=$(wc -l ${vdir}.changes | awk ' { print $1 } ')
127 let headcount=$linecount-3
128 let tailcount=$headcount-1
129 # get rid of the last 3 lines of the rsync output
130 head -${headcount} ${vdir}.changes > ${vdir}.changes.1
131 # get rid of the first line of the rsync output
132 tail -${tailcount} ${vdir}.changes.1 > ${vdir}.changes.2
133 # post process rsync output to get rid of symbolic link embellish output
134 awk ' { print $1 } ' ${vdir}.changes.2 > ${vdir}.changes
135 rm -f ${vdir}.changes.*
137 # step 3: create the ${vdir} with just the list given in ${vdir}.changes
138 install -d -m 755 ${vdir}-tmp/
140 (cd ${vdir} && cpio -m -d -u -p ${vdir}-tmp < ${vdir}.changes)
142 rm -f ${vdir}.changes
143 mv ${vdir}-tmp ${vdir}
145 echo -n "* tar $extension_name s=$(date +%H-%M-%S)"
146 tar -cpf ${pldistro}-filesystems/$extension_plain -C ${vdir} .
147 echo -n " m=$(date +%H-%M-%S) "
148 bzip2 --compress --stdout ${pldistro}-filesystems/$extension_plain > ${pldistro}-filesystems/$extension_name
149 echo " e=$(date +%H-%M-%S) "
152 # Build the base Bootstrap filesystem
153 # clean out yum cache to reduce space requirements
154 yum -c ${vref}/etc/mkfedora-yum.conf --installroot=${vref} -y clean all
156 bootstrapfs_plain=bootstrapfs-${nodefamily}.tar
157 bootstrapfs_name=bootstrapfs-${nodefamily}.tar.bz2
158 echo -n "* tar $bootstrapfs_name s=$(date +%H-%M-%S)"
159 tar -cpf $bootstrapfs_plain -C ${vref} .
160 echo -n " m=$(date +%H-%M-%S) "
161 bzip2 --compress --stdout $bootstrapfs_plain > $bootstrapfs_name
162 echo " e=$(date +%H-%M-%S) "