5 # where the boot cd build config files are stored (and certificats/keys)
6 CONFIGURATIONS_DIR=configurations/
8 # where built files are stored
12 FULL_VERSION_STRING="PlanetLab BootCD"
13 OUTPUT_IMAGE_NAME='PlanetLab-BootCD'
15 SYSLINUX_SRC=sources/syslinux-2.11.tar.bz2
17 BOOTCD_YUM_GROUP=BootCD
19 CDRECORD_FLAGS="-v -dao"
21 CONF_FILES_DIR=conf_files/
23 # size of the ram disk in MB
26 # the bytes per inode ratio (the -i value in mkfs.ext2) for the ramdisk
27 INITRD_BYTES_PER_INODE=1024
30 # make sure the boot manager source is checked out in the same directory
31 # as the bootcd_v3 repository
32 for BOOTMANAGER_DIR in ../bootmanager-* ../bootmanager ; do
33 [ -d $BOOTMANAGER_DIR ] && break
36 if [ ! -d $BOOTMANAGER_DIR ]; then
37 echo "the bootmanager repository needs to be checked out at the same"
38 echo "level as this directory, for the merge_hw_tables.py script"
45 echo "Usage: build.sh <action> [<configuration>]"
46 echo "Action: build burn clean"
48 echo "If configuration is missing, 'default' is loaded"
53 function build_cdroot()
55 if [ -f $CD_ROOT/.built ]; then
56 echo "cd root already built, skipping"
62 mkdir -p $CD_ROOT/dev/pts
63 mkdir -p $CD_ROOT/proc
66 echo "copy fstab and mtab"
67 cp -f $CONF_FILES_DIR/fstab $CD_ROOT/etc/
68 cp -f $CONF_FILES_DIR/mtab $CD_ROOT/etc/
70 echo "setup rpm to install only en_US locale and no docs"
71 mkdir -p $CD_ROOT/etc/rpm
72 cp -f $CONF_FILES_DIR/macros $CD_ROOT/etc/rpm
75 cp -f $CONF_FILES_DIR/macros $PWD/.rpmmacros
77 echo "initialize rpm db"
78 mkdir -p $CD_ROOT/var/lib/rpm
79 rpm --root $CD_ROOT --initdb
81 # XXX Should download yum.conf from the boot server?
82 echo "generate yum.conf"
85 cachedir=/var/cache/yum
87 logfile=/var/log/yum.log
89 ### for yum-2.4 in fc4 (this will be ignored by yum-2.0)
90 ### everything in here, do not scan /etc/yum.repos.d/
94 name=Fedora Core 2 Base -- PlanetLab Central
95 baseurl=http://$PRIMARY_SERVER/install-rpms/stock-fc2/
98 name=Fedora Core 2 Updates -- PlanetLab Central
99 baseurl=http://$PRIMARY_SERVER/install-rpms/updates-fc2/
102 name=PlanetLab RPMS -- PlanetLab Central
103 baseurl=http://$PRIMARY_SERVER/install-rpms/planetlab-rollout/
105 # XXX Temporary hack until the 3.2 rollout is complete and the
106 # /planetlab/yumgroups.xml file contains the BootCD group.
107 yumgroups="http://$PRIMARY_SERVER/install-rpms/planetlab-rollout/yumgroups.xml"
109 # Solve the bootstrap problem by including any just built packages in
110 # the yum configuration. This cooperates with the PlanetLab build
112 if [ -n "$RPM_BUILD_DIR" ] ; then
113 yum-arch $(dirname $RPM_BUILD_DIR)/RPMS
114 createrepo -g yumgroups.xml $(dirname $RPM_BUILD_DIR)/RPMS || :
115 # If run under sudo, allow user to delete the headers/ and
116 # repodata/ directories.
117 if [ -n "$SUDO_USER" ] ; then
118 chown -R $SUDO_USER $(dirname $RPM_BUILD_DIR)/RPMS
122 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
123 baseurl=file://$(dirname $RPM_BUILD_DIR)/RPMS/
125 yumgroups="file://$(dirname $RPM_BUILD_DIR)/RPMS/yumgroups.xml"
128 echo "install boot cd base rpms"
129 yum -c yum.conf --installroot=$CD_ROOT -y groupinstall $BOOTCD_YUM_GROUP
132 yum -c yum.conf --installroot=$CD_ROOT -y clean all
134 # Remove stale RPM locks
135 rm -f $CD_ROOT/var/lib/rpm/__db*
137 # Retrieve all of the packagereq declarations in the BootCD group of the yumgroups.xml file
138 echo "checking to make sure rpms were installed"
139 packages=$(curl $yumgroups | sed -n -e '/<name>BootCD<\/name>/,/<name>/{ s/.*<packagereq.*>\(.*\)<\/packagereq>/\1/p }')
141 for package in $packages; do
142 echo "checking for package $package"
143 /usr/sbin/chroot $CD_ROOT /bin/rpm -qi $package > /dev/null
144 if [[ "$?" -ne 0 ]]; then
145 echo "package $package was not installed in the cd root."
146 echo "make sure it exists in the yum repository."
152 echo "removing unneccessary build files"
153 (cd $CD_ROOT/lib/modules && \
154 find ./ -type d -name build -maxdepth 2 -exec rm -rf {} \;)
156 echo "setting up non-ssh authentication"
157 mkdir -p $CD_ROOT/etc/samba
158 /usr/sbin/chroot $CD_ROOT /usr/sbin/authconfig --nostart --kickstart \
159 --enablemd5 --enableshadow
161 echo "setting root password"
162 sed -i "s#root::#root:$ROOT_PASSWORD:#g" $CD_ROOT/etc/shadow
164 echo "relocate some large directories out of the root system"
165 # get /var/lib/rpm out, its 12mb. create in its place a
166 # symbolic link to /usr/relocated/var/lib/rpm
167 mkdir -p $CD_ROOT/usr/relocated/var/lib/
168 mv $CD_ROOT/var/lib/rpm $CD_ROOT/usr/relocated/var/lib/
169 (cd $CD_ROOT/var/lib && ln -s ../../usr/relocated/var/lib/rpm rpm)
171 # get /var/cache/yum out, its 100Mb. create in its place a
172 # symbolic link to /usr/relocated/var/cache/yum
173 mkdir -p $CD_ROOT/usr/relocated/var/cache/
174 mv $CD_ROOT/var/cache/yum $CD_ROOT/usr/relocated/var/cache/
175 (cd $CD_ROOT/var/cache && ln -s ../../usr/relocated/var/cache/yum yum)
178 mkdir -p $CD_ROOT/usr/relocated/lib
179 mv $CD_ROOT/lib/tls $CD_ROOT/usr/relocated/lib/
180 (cd $CD_ROOT/lib && ln -s ../usr/relocated/lib/tls tls)
182 echo "extracting syslinux, copying isolinux files to cd"
183 mkdir -p $CD_ROOT/usr/isolinux/
184 mkdir -p $BUILD_DIR/syslinux
185 tar -C $BUILD_DIR/syslinux -xjvf $SYSLINUX_SRC
186 find $BUILD_DIR/syslinux -name isolinux.bin \
187 -exec cp -f {} $CD_ROOT/usr/isolinux/ \;
189 echo "moving kernel to isolinux directory"
190 KERNEL=$CD_ROOT/boot/vmlinuz-*
191 mv -f $KERNEL $CD_ROOT/usr/isolinux/kernel
193 echo "moving /usr/bin/find and /usr/bin/dirname to /bin"
194 mv $CD_ROOT/usr/bin/find $CD_ROOT/bin/
195 mv $CD_ROOT/usr/bin/dirname $CD_ROOT/bin/
197 echo "creating version files"
198 echo "$FULL_VERSION_STRING" > $CD_ROOT/usr/isolinux/pl_version
199 echo "$FULL_VERSION_STRING" > $CD_ROOT/pl_version
201 touch $CD_ROOT/.built
204 function init_initrd()
206 echo "initialize configuration files"
208 echo "copy fstab and mtab"
209 cp -f $CONF_FILES_DIR/fstab $CD_ROOT/etc/
210 cp -f $CONF_FILES_DIR/mtab $CD_ROOT/etc/
212 echo "installing generic modprobe.conf"
213 cp -f $CONF_FILES_DIR/modprobe.conf $CD_ROOT/etc/
215 echo "installing our own inittab and init scripts"
216 cp -f $CONF_FILES_DIR/inittab $CD_ROOT/etc
217 init_scripts="pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot"
218 for script in $init_scripts; do
219 cp -f $CONF_FILES_DIR/$script $CD_ROOT/etc/init.d/
220 chmod +x $CD_ROOT/etc/init.d/$script
223 echo "setup basic networking files"
224 cp -f $CONF_FILES_DIR/hosts $CD_ROOT/etc/
226 echo "copying sysctl.conf (fix tcp window scaling and broken routers)"
227 cp -f $CONF_FILES_DIR/sysctl.conf $CD_ROOT/etc/
229 echo "setup default network conf file"
230 mkdir -p $CD_ROOT/usr/boot
231 cp -f $CONF_FILES_DIR/default-net.cnf $CD_ROOT/usr/boot/
233 echo "setup boot server configuration"
234 cp -f $CURRENT_CONFIG_DIR/$PRIMARY_SERVER_CERT $CD_ROOT/usr/boot/cacert.pem
235 cp -f $CURRENT_CONFIG_DIR/$PRIMARY_SERVER_GPG $CD_ROOT/usr/boot/pubring.gpg
236 echo "$PRIMARY_SERVER" > $CD_ROOT/usr/boot/boot_server
237 echo "$PRIMARY_SERVER_PORT" > $CD_ROOT/usr/boot/boot_server_port
238 echo "$PRIMARY_SERVER_PATH" > $CD_ROOT/usr/boot/boot_server_path
240 echo "setup backup boot server configuration"
241 mkdir -p $CD_ROOT/usr/boot/backup
242 cp -f $CURRENT_CONFIG_DIR/$BACKUP_SERVER_CERT \
243 $CD_ROOT/usr/boot/backup/cacert.pem
244 cp -f $CURRENT_CONFIG_DIR/$BACKUP_SERVER_GPG \
245 $CD_ROOT/usr/boot/backup/pubring.gpg
246 echo "$BACKUP_SERVER" > $CD_ROOT/usr/boot/backup/boot_server
247 echo "$BACKUP_SERVER_PORT" > $CD_ROOT/usr/boot/backup/boot_server_port
248 echo "$BACKUP_SERVER_PATH" > $CD_ROOT/usr/boot/backup/boot_server_path
250 echo "copying old boot cd directory bootme (TEMPORARY)"
251 cp -r bootme_old $CD_ROOT/usr/bootme
252 echo "$FULL_VERSION_STRING" > $CD_ROOT/usr/bootme/ID
253 echo "$PRIMARY_SERVER" > $CD_ROOT/usr/bootme/BOOTSERVER
254 echo "$PRIMARY_SERVER" > $CD_ROOT/usr/bootme/BOOTSERVER_IP
255 echo "$PRIMARY_SERVER_PORT" > $CD_ROOT/usr/bootme/BOOTPORT
257 echo "copying cacert to old boot cd directory bootme (TEMPORARY)"
258 mkdir -p $CD_ROOT/usr/bootme/cacert/$PRIMARY_SERVER/
259 cp -f $CURRENT_CONFIG_DIR/$PRIMARY_SERVER_CERT \
260 $CD_ROOT/usr/bootme/cacert/$PRIMARY_SERVER/cacert.pem
262 echo "forcing lvm to make lvm1 partitions (TEMPORARY)"
263 cp -f $CONF_FILES_DIR/lvm.conf $CD_ROOT/etc/lvm/
265 echo "copying isolinux configuration files"
266 echo "$FULL_VERSION_STRING" > $CD_ROOT/usr/isolinux/message.txt
268 echo "writing /etc/issue"
269 echo "$FULL_VERSION_STRING" > $CD_ROOT/etc/issue
270 echo "Kernel \r on an \m" >> $CD_ROOT/etc/issue
271 echo "" >> $CD_ROOT/etc/issue
272 echo "" >> $CD_ROOT/etc/issue
274 if [[ ! -z "$NODE_CONFIGURATION_FILE" ]]; then
275 echo "Copying node configuration file to cd"
276 cp -f $CURRENT_CONFIG_DIR/$NODE_CONFIGURATION_FILE \
277 $CD_ROOT/usr/boot/plnode.txt
280 echo "building pcitable for hardware detection"
281 pci_map_file=`find $CD_ROOT/lib/modules/ -name modules.pcimap | head -1`
282 module_dep_file=`find $CD_ROOT/lib/modules/ -name modules.dep | head -1`
283 pci_table=$CD_ROOT/usr/share/hwdata/pcitable
284 $BOOTMANAGER_DIR/source/merge_hw_tables.py \
285 $module_dep_file $pci_map_file $pci_table $CD_ROOT/etc/pl_pcitable
289 function build_initrd()
293 echo "building initrd"
296 rm -f $CD_ROOT/usr/isolinux/initrd
297 rm -f $CD_ROOT/usr/isolinux/initrd.gz
299 TOTAL_SIZE=$(du -ksc $CD_ROOT | awk '$2 == "total" { print $1}')
300 if [ $big -eq 1 ]; then
301 let TOTAL_SIZE=$TOTAL_SIZE-$(du -ksc $CD_ROOT/usr/isolinux | awk '$2 == "total" { print $1}')
303 let TOTAL_SIZE=$TOTAL_SIZE-$(du -ksc $CD_ROOT/usr | awk '$2 == "total" { print $1}')
305 let INITRD_SIZE=($TOTAL_SIZE/1024)+$RAMDISK_SIZE+4
307 echo "making the isolinux initrd kernel command line match rd size"
308 let INITRD_SIZE_KB=$(($INITRD_SIZE * 1024))
309 cp -f $CONF_FILES_DIR/isolinux.cfg $CD_ROOT/usr/isolinux/
310 sed -i "s#ramdisk_size=0#ramdisk_size=$INITRD_SIZE_KB#g" \
311 $CD_ROOT/usr/isolinux/isolinux.cfg
313 dd if=/dev/zero of=$INITRD bs=1M count=$INITRD_SIZE
314 /sbin/mkfs.ext2 -F -m 0 -i $INITRD_BYTES_PER_INODE $INITRD
315 mkdir -p $INITRD_MOUNT
316 mount -o loop,rw $INITRD $INITRD_MOUNT
318 echo "copy all files except usr to ramdisk"
321 find . -path ./usr -prune -o -print | cpio -p -d -u $INITRD_MOUNT
324 if [ $big -eq 1 ]; then
325 echo "copy usr to ramdisk"
328 find ./usr -path ./usr/isolinux -o -print | cpio -p -d -u $INITRD_MOUNT
335 # INITRD_SIZE=$(`ls -sh $INITRD | awk '{print $1}'`)
336 # echo "initrd size = $INITRD_SIZE"
337 echo "compressing ramdisk"
339 mv -f $INITRD.gz $CD_ROOT/usr/isolinux
344 # build base image via yum
347 # always build/rebuild initrd
350 ####################################################################################
351 # build small initrd for small iso and usb image
356 mkisofs -o $ISO -R -allow-leading-dots -J -r -b isolinux/isolinux.bin \
357 -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
360 # build usb image and make it bootable with syslinux (instead of isolinux)
361 USB_IMAGE=${ISO%*.iso}.usb
362 # leave 1 MB of free space on the filesystem
363 USB_KB=$(du -kc $ISO $CD_ROOT/usr/isolinux | awk '$2 == "total" { print $1 + 1024 }')
364 /sbin/mkfs.vfat -C $USB_IMAGE $USB_KB
366 mkdir -p $INITRD_MOUNT
367 mount -o loop,rw $USB_IMAGE $INITRD_MOUNT
369 # populate the root of the image with pl_version, and the syslinux files
370 cp -a $ISO $INITRD_MOUNT
371 cp -a $CD_ROOT/usr/isolinux/{initrd.gz,kernel,message.txt,pl_version} $INITRD_MOUNT
372 cp -a $CD_ROOT/usr/isolinux/isolinux.cfg $INITRD_MOUNT/syslinux.cfg
380 ####################################################################################
381 # build small initrd for small iso and usb image
384 # build usb image and make it bootable with syslinux (instead of isolinux)
385 USB_IMAGE=${ISO%*.iso}-biginitrd.usb
386 # leave 1 MB of free space on the filesystem
387 USB_KB=$(du -kc $CD_ROOT/usr/isolinux | awk '$2 == "total" { print $1 + 1024 }')
388 /sbin/mkfs.vfat -C $USB_IMAGE $USB_KB
390 mkdir -p $INITRD_MOUNT
391 mount -o loop,rw $USB_IMAGE $INITRD_MOUNT
393 # populate the root of the image with pl_version, and the syslinux files
394 cp -a $CD_ROOT/usr/isolinux/{initrd.gz,kernel,message.txt,pl_version} $INITRD_MOUNT
395 cp -a $CD_ROOT/usr/isolinux/isolinux.cfg $INITRD_MOUNT/syslinux.cfg
406 cdrecord $CDRECORD_FLAGS -data $ISO
412 rm -rf $BUILD_DIR/syslinux
413 rm -rf $BUILD_DIR/$INITRD_MOUNT
416 rmdir --ignore-fail-on-non-empty build
419 if [[ "$1" == "clean" || "$1" == "burn" || "$1" == "build" ]]; then
423 if [[ -z "$configuration" ]]; then
424 configuration=default
427 echo "Loading configuration $configuration"
428 CURRENT_CONFIG_DIR=$CONFIGURATIONS_DIR/$configuration
429 . $CURRENT_CONFIG_DIR/configuration
431 # setup vars for this configuration
433 # version string for this build
434 if [[ ! -z "$EXTRA_VERSION" ]]; then
435 FULL_VERSION_STRING="$FULL_VERSION_STRING $EXTRA_VERSION"
437 FULL_VERSION_STRING="$FULL_VERSION_STRING $BOOTCD_VERSION"
440 if [[ ! -z "$EXTRA_VERSION" ]]; then
441 OUTPUT_IMAGE_NAME="$OUTPUT_IMAGE_NAME-$EXTRA_VERSION"
443 OUTPUT_IMAGE_NAME="$OUTPUT_IMAGE_NAME-$BOOTCD_VERSION"
445 # setup build directories
446 BUILD_DIR=build/$configuration
448 ISO=$BUILD_DIR/`echo $OUTPUT_IMAGE_NAME | sed -e "s/%version/$BOOTCD_VERSION/"`.iso
450 CD_ROOT=`pwd`/$BUILD_DIR/cdroot
453 # location of the uncompressed ramdisk image
454 INITRD=`pwd`/$BUILD_DIR/initrd
456 # temporary mount point for rd
458 INITRD_MOUNT=`mktemp -q -p $MYPWD/$BUILD_DIR -d -t rd.XXXXXXXX`
459 if [ $? -ne 0 ]; then
460 echo "failed to create tempory mount point for initrd"
467 echo "Proceeding with building $DESCRIPTION"
471 echo "Removing built files for $DESCRIPTION"
475 echo "Burning $DESCRIPTION"