3 # Builds the BootCD reference image, the first of two
4 # initramfs cpio archives that are concatenated together by
5 # isolinux/syslinux to form a custom BootCD.
7 # Aaron Klingaman <alk@absarokasoft.com>
8 # Mark Huang <mlhuang@cs.princeton.edu>
9 # Copyright (C) 2004-2006 The Trustees of Princeton University
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
14 # In both a normal CVS environment and a PlanetLab RPM
15 # build environment, all of our dependencies are checked out into
16 # directories at the same level as us.
17 if [ -d ../build ] ; then
21 echo "Error: Could not find sources in either . or .."
33 # Packages to install, junk and precious : see build/<pldistro>/bootcd.pkgs
35 # Do not tolerate errors
38 # Root of the initramfs reference image
39 bootcd=$PWD/build/bootcd
40 install -d -m 755 $bootcd
42 # Write version number
43 echo ${rpmversion} > build/version.txt
44 echo ${nodefamily} > build/nodefamily
47 echo "* Creating fedora root image"
48 pl_root_makedevs $bootcd
49 pkgsfile=$(pl_locateDistroFile ../build/ $pldistro bootcd.pkgs)
50 pl_root_mkfedora $bootcd $pldistro $pkgsfile
51 pl_root_tune_image $bootcd
53 # Add site_admin console account to BootCD: with root priv, and self passwd
54 echo "* Creating site_admin account"
55 CRYPT_SA_PASSWORD=$(python3 -c "import crypt, random, string; salt = [random.choice(string.ascii_letters + string.digits + \"./\") for i in range(0,8)] ; print(crypt.crypt('site_admin', '\$1\$' + \"\".join(salt) + '\$'))")
56 chroot ${bootcd} /usr/sbin/useradd -p "$CRYPT_SA_PASSWORD" -o -g 0 -u 0 -m site_admin
58 # Install ipnmac (for SuperMicro machines with IPMI)
59 echo "* Installing IPMI utilities"
60 install -D -m 755 ipnmac/ipnmac.x86 $bootcd/usr/sbin/ipnmac
63 echo "* Installing initscripts"
64 for file in pl_functions pl_sysinit pl_hwinit pl_netinit pl_validateconf pl_boot ; do
65 sed -i -e "s,@PLDISTRO@,$pldistro,g" -e "s,@FCDISTRO@,$fcdistro,g" initscripts/$file
66 install -D -m 755 initscripts/$file $bootcd/etc/init.d/$file
69 # Install configuration files
70 echo "* Installing configuration files"
71 for file in fstab mtab modprobe.conf inittab hosts sysctl.conf ; do
72 install -D -m 644 etc/$file $bootcd/etc/$file
74 # connect our initscripts scripts for upstart
75 # fedora 9 comes with /sbin/init from upstart, that uses /etc/event.d instead of inittab
76 # (in fact inittab is read for determining the default runlevel)
77 if [ -d $bootcd/etc/event.d ] ; then
78 echo "* Tuning /etc/event.d/ for upstart"
79 pushd $bootcd/etc/event.d
80 # use our system initialisation script
81 sed -i -e 's,/etc/rc\.d/rc\.sysinit[a-z\.]*,/etc/init.d/pl_sysinit,g' rcS
82 # use our startup script in runlevel 2
83 sed -i -e 's,/etc/rc\.d/rc[ \t][ \t]*2,/etc/init.d/pl_boot,g' rc2
86 # ditto for f14 and higher init style
87 if [ -d $bootcd/etc/init ] ; then
88 echo "* Tuning /etc/init/ for upstart"
89 pushd $bootcd/etc/init
90 # use our system initialisation script
91 sed -i -e 's,/etc/rc\.d/rc\.sysinit[a-z\.]*,/bin/bash -c /etc/init.d/pl_sysinit,g' rcS.conf
92 # use our startup script in runlevel 2
93 sed -i -e 's,/etc/rc.d/rc[a-z\.]*,/etc/init.d/pl_boot,g' rc.conf
96 # Install systemd files for f16 and above
97 if [ -d $bootcd/etc/systemd/system ] ; then
98 echo "* Installing systemd files"
99 for file in pl_boot.service pl_boot.target ; do
100 install -D -m 644 systemd/$file $bootcd/etc/systemd/system
102 echo "* Configuration BootCD to start up pl_boot"
103 # first attempt was to totally replace everything with pl_boot.target
104 # this however leads to physical f21 nodes not starting up properly
105 # because biosdevname is not properly honored and so pl_netinit gets confused
106 # select pl_boot target this way instead of using kargs, as kargs apply to kexec boot as well
107 # ln -sf /etc/systemd/system/pl_boot.target $bootcd/etc/systemd/system/default.target
108 #[ -d $bootcd/etc/systemd/system/pl_boot.target.wants ] || mkdir -p $bootcd/etc/systemd/system/pl_boot.target.wants
109 # Let's try another approach completely
110 # xxx if that worked we would not need pl_boot.target at all
111 mkdir -p $bootcd/etc/systemd/system/default.target.wants
112 ln -sf /etc/systemd/system/pl_boot.service $bootcd/etc/systemd/system/default.target.wants
113 echo "* Enabling getty on tty2"
114 #ln -sf /usr/lib/systemd/system/getty@.service $bootcd/etc/systemd/system/pl_boot.target.wants/getty@tty2.service
115 ln -sf /usr/lib/systemd/system/getty@.service $bootcd/etc/systemd/system/default.target.wants/getty@tty2.service
118 # Install fallback node configuration file
119 echo "* Installing fallback node configuration file"
120 install -D -m 644 usr-boot/default-node.txt $bootcd/usr/boot/default-node.txt
122 # Copy /etc/passwd out
123 install -D -m 644 $bootcd/etc/passwd build/passwd
126 isofs=$PWD/build/isofs
127 install -d -m 755 $isofs
129 # Copy the kernel out
130 echo "* BootCD - locating kernel"
131 for kernel in $bootcd/boot/vmlinuz-* ; do
132 if [ -f "$kernel" ] ; then
133 echo "* BootCD kernel (1) creating from $kernel"
134 echo "* kernel created (1) from $kernel" > $isofs/kernel.from
135 install -D -m 644 $kernel $isofs/kernel
139 # patch - Thierry - dec. 2015
140 # somehow we see this good-old code produce a bootcd without a /kernel
141 # this is odd because as far as rpm is concerned, the name should not have changed
142 # anyways, at this point, here's what can be found in /boot
143 # [root@2015-12-07--f23-bcd boot]# pwd
144 # /build/BUILD/bootcd-lxc-f23-x86_64-5.3/bootcd/build/bootcd/boot
145 # [root@2015-12-07--f23-bcd boot]# ls -R
147 # 8adf0b93a7f44be69499d21fa18ab5b8 loader
149 # ./8adf0b93a7f44be69499d21fa18ab5b8:
150 # 4.2.6-301.fc23.x86_64
152 # ./8adf0b93a7f44be69499d21fa18ab5b8/4.2.6-301.fc23.x86_64:
159 # 8adf0b93a7f44be69499d21fa18ab5b8-4.2.6-301.fc23.x86_64.conf
161 # second chance if first approach would not work
162 if [ ! -f $isofs/kernel ] ; then
163 kernel=$(find $bootcd/boot -name linux)
164 if [ -f "$kernel" ] ; then
165 echo "* BootCD kernel (2) creating from $kernel"
166 echo "* kernel created (2) from $kernel" > $isofs/kernel.from
167 install -D -m 644 $kernel $isofs/kernel
171 if [ ! -f $isofs/kernel ] ; then
172 echo "* BootCD prep.sh : FATAL: could not locate kernel - exiting"
176 # Don't need /boot anymore
179 # initramfs requires that /init be present
180 ln -sf /sbin/init $bootcd/init
182 # Pack the rest into a compressed archive
183 echo "* Compressing reference image"
184 (cd $bootcd && find . | cpio --quiet -c -o) | gzip -9 > $isofs/bootcd.img