3 %include /tmp/source.ks
11 # ignore unsupported hardware warning
15 # NEVER ever place zerombr here, it breaks automated installation
16 %include /tmp/bootloader.ks
17 %include /tmp/partition.ks
20 # HERE ARE COMMANDS THAT WILL BE LAUNCHED BEFORE
21 # INSTALLATION PROCESS ITSELF
28 for drv in `ls -1 /sys/block | grep "sd\|hd\|vd\|cciss"`; do
29 if (grep -q 0 /sys/block/${drv}/removable); then
30 drives="${drives} ${drv}"
32 removable_drives="${removable_drives} ${drv}"
35 default_drive=`echo ${drives} ${removable_drives} | awk '{print $1}'`
37 installdrive="undefined"
39 for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done
41 set ${drives} ${removable_drives}
44 tgtdrive="${installdrive}"
46 function confirm_format {
48 local confirm_format="no"
50 if [[ "$forceformat" == "yes" ]] ; then
54 if parted -s /dev/$check_drive print &>/dev/null ; then
56 echo "$check_drive drive contains partition table:"
57 parted -s /dev/$check_drive print
59 read -p "Are you sure you want to erase ALL data on disk $check_drive? (y/N)" confirm_format
60 if [[ "$confirm_format" == "y" ]] || [[ "$confirm_format" == "Y" ]] || [[ "$forceformat" == "yes" ]]; then
72 if [ $numdrives -lt 1 ]; then
73 exec < /dev/tty3 > /dev/tty3 2>&1
77 echo '********************************************************************'
80 echo '* There is no suitable media available for installation. *'
81 echo '* Please attach a drive and try again. *'
83 echo '********************************************************************'
85 read -p "Press Enter to shut down the system: " _
89 if [ ${numdrives} -gt 1 ] || [ `echo ${drives} | wc -w` -eq 0 ] ; then
90 exec < /dev/tty3 > /dev/tty3 2>&1
92 while [ "${tgtdrive}" = "undefined" ]; do
95 echo '********************************************************************************'
96 echo '* W A R N I N G *'
98 echo '* Which of the detected hard drives do you want to be used as *'
99 echo '* the installation target? *'
101 echo '********************************************************************************'
103 echo "Possible choices"
104 echo "Persistent drives: ${drives}"
105 echo "Removable drives: ${removable_drives}"
107 if [ `echo ${drives} | wc -w` -eq 1 ] ; then
108 read -t 30 -p "Choose hard drive: " tgtdrive || tgtdrive=$default_drive
110 read -p "Choose hard drive: " tgtdrive
113 for drive in ${drives[@]} ${removable_drives[@]}; do
114 if [[ "$drive" == "$tgtdrive" ]] && match="yes" ; then
115 if confirm_format $tgtdrive ; then
116 format_confirmed="yes"
120 read -p "You may select another disk. Press Enter to continue." _
124 if [[ "$match" == "no" ]]; then
126 read -p "Invalid choice. Press Enter to continue." _
132 tgtdrive=`echo ${drives} | sed -e "s/^\s*//" -e "s/\s*$//"`
135 if [ "$format_confirmed" != "yes" ] ; then
136 exec < /dev/tty3 > /dev/tty3 2>&1
138 if ! confirm_format $tgtdrive ; then
141 echo '********************************************************************'
144 echo '* Disk $tgtdrive contains active partition(s). *'
145 echo '* Installation cannot continue without confirmation. *'
147 echo '********************************************************************'
149 read -p "Press Enter to restart: " _
155 # verify tgtdrive is at least 30GB
156 tgtdrivesize=$(( $(cat "/sys/class/block/${tgtdrive}/size") / 2 / 1024 ))
157 if [ $tgtdrivesize -lt 30720 ]; then
158 exec < /dev/tty3 > /dev/tty3 2>&1
162 echo '********************************************************************'
165 echo '* Your disk is under 30GB in size. Installation cannot continue. *'
166 echo '* Restart installation with a larger disk. *'
168 echo '********************************************************************'
170 read -p "Press Enter to restart: " _
174 # paths in /dev have "/" instead of "!" for cciss devices
175 tgtdrive=$(echo $tgtdrive | sed -e 's/!/\//')
178 if test -e /dev/disk/by-uuid/will_be_substituted_with_actual_uuid; then
179 echo "harddrive --partition=UUID=will_be_substituted_with_actual_uuid --dir=/" > /tmp/source.ks
181 echo "cdrom" > /tmp/source.ks
185 dd if=/dev/zero of=/dev/${tgtdrive} bs=10M count=10
187 hdparm -z /dev/${tgtdrive}
188 parted -s /dev/${tgtdrive} mklabel gpt
189 parted -a none -s /dev/${tgtdrive} unit MiB mkpart primary 0 24
190 parted -s /dev/${tgtdrive} set 1 bios_grub on
191 parted -a none -s /dev/${tgtdrive} unit MiB mkpart primary fat16 24 224
192 parted -s /dev/${tgtdrive} set 2 boot on
193 parted -a none -s /dev/${tgtdrive} unit MiB mkpart primary 224 424
195 hdparm -z /dev/${tgtdrive}
199 # This adds support for the p seperator required for cciss devices
200 if echo ${tgtdrive} | grep -q -e cciss ; then
205 echo > /tmp/partition.ks
206 echo "partition /boot --onpart=/dev/${bootdev}3" >> /tmp/partition.ks
207 echo "partition pv.001 --ondisk=${tgtdrive} --size=30000 --grow" >> /tmp/partition.ks
208 echo "volgroup os pv.001" >> /tmp/partition.ks
209 echo "logvol swap --vgname=os --recommended --name=swap" >> /tmp/partition.ks
210 echo "logvol / --vgname=os --size=10000 --name=root --fstype=ext4" >> /tmp/partition.ks
211 echo "logvol /var --vgname=os --size=1 --grow --name=var --fstype=xfs" >> /tmp/partition.ks
214 echo "bootloader --location=mbr --driveorder=${tgtdrive} --append=' biosdevname=0 crashkernel=none'" > /tmp/bootloader.ks
216 # Anaconda can not install grub 0.97 on disks which are >4T.
217 # The reason is that grub does not support such large geometries
218 # and it simply thinks that the cylinder number has negative value.
219 # Here we just set geometry manually so that grub thinks that disk
220 # size is equal to 1G.
221 # 130 cylinders * (16065 * 512 = 8225280 bytes) = 1G
222 echo "%post --nochroot --log=/mnt/sysimage/root/anaconda-post-partition.log" > /tmp/post_partition.ks
223 echo "echo \"device (hd0) /dev/${tgtdrive}\" >> /tmp/grub.script" >> /tmp/post_partition.ks
224 echo "echo \"geometry (hd0) 130 255 63\" >> /tmp/grub.script" >> /tmp/post_partition.ks
225 echo "echo \"root (hd0,2)\" >> /tmp/grub.script" >> /tmp/post_partition.ks
226 echo "echo \"install /grub/stage1 (hd0) /grub/stage2 p /grub/grub.conf\" >> /tmp/grub.script" >> /tmp/post_partition.ks
227 echo "echo quit >> /tmp/grub.script" >> /tmp/post_partition.ks
228 echo "cat /tmp/grub.script | chroot /mnt/sysimage /sbin/grub --no-floppy --batch" >> /tmp/post_partition.ks
232 %packages --nobase --excludedocs
254 ruby21-rubygem-netaddr
255 ruby21-rubygem-openstack
256 selinux-policy-targeted
260 system-config-firewall-base
268 %include /tmp/post_partition.ks
270 # POSTINSTALL SECTION
271 # HERE ARE COMMANDS THAT WILL BE LAUNCHED JUST AFTER
272 # INSTALLATION ITSELF COMPLETED
274 echo -e "modprobe nf_conntrack_ipv4\nmodprobe nf_conntrack_ipv6\nmodprobe nf_conntrack_tftp\nmodprobe nf_nat_tftp" >> /etc/rc.modules
275 chmod +x /etc/rc.modules
276 echo -e "net.nf_conntrack_max=1048576" >> /etc/sysctl.conf
277 mkdir -p /var/log/coredump
278 echo -e "kernel.core_pattern=/var/log/coredump/core.%e.%p.%h.%t" >> /etc/sysctl.conf
279 chmod 777 /var/log/coredump
280 echo -e "* soft core unlimited\n* hard core unlimited" >> /etc/security/limits.conf
282 # Mount installation media in chroot
283 %post --nochroot --log=/mnt/sysimage/root/anaconda-post-before-chroot.log
286 SOURCE="/mnt/sysimage/tmp/source"
288 for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done
294 nfs_url="${repo#nfs:}"
295 mount -t nfs "${nfs_url}" "${SOURCE}"
298 if [ -d "/mnt/source" ]; then
299 mount -o bind "/mnt/source" "${SOURCE}"
304 %post --log=/root/anaconda-post-after-chroot.log
310 scrFile="/etc/sysconfig/network-scripts/ifcfg-$device"
311 search="domain $domain\nsearch $domain"
312 sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname"'#' /etc/sysconfig/network
313 grep -q "^\s*$ip\s+$hostname" /etc/hosts || echo "$ip $hostname" >> /etc/hosts
314 echo "${search}\nnameserver 127.0.0.1" > /etc/resolv.conf
315 [ $dns1 ] && echo -e "${search}\nnameserver $dns1" > /etc/resolv.conf
316 [ $dns1 ] && echo -e "${search}\nnameserver $dns1" > /etc/dnsmasq.upstream
317 [ $dns2 ] && echo "nameserver $dns2" >> /etc/resolv.conf
318 [ $dns2 ] && echo "nameserver $dns2" >> /etc/dnsmasq.upstream
320 echo DEVICE=$device > $scrFile
321 echo ONBOOT=yes >> $scrFile
322 echo NM_CONTROLLED=no >> $scrFile
323 echo HWADDR=$hwaddr >> $scrFile
324 echo USERCTL=no >> $scrFile
325 echo PEERDNS=no >> $scrFile
327 echo BOOTPROTO=static >> $scrFile
328 echo IPADDR=$ip >> $scrFile
329 echo NETMASK=$netmask >> $scrFile
331 echo BOOTPROTO=dhcp >> $scrFile
333 scrDHCPFile="/etc/sysconfig/network-scripts/ifcfg-$dhcp_interface"
334 #Ignore gateway and set up DHCP if it is used, otherwise apply it
335 if [ $dhcp_interface ] && [ "$dhcp_interface" != "$device" ]; then
336 echo "DEVICE=$dhcp_interface" > $scrDHCPFile
337 echo "BOOTPROTO=dhcp" >> $scrDHCPFile
338 echo "ONBOOT=yes" >> $scrDHCPFile
339 echo "USERCTL=no" >> $scrDHCPFile
341 echo GATEWAY=$gw >> /etc/sysconfig/network
346 hostname="nailgun.mirantis.com"
348 for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done
350 domain=${hostname#*.}
355 hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
356 dhcp_interface=$dhcp_interface
359 # Mounting installation source
367 if test -e /dev/disk/by-uuid/will_be_substituted_with_actual_uuid; then
368 mount /dev/disk/by-uuid/will_be_substituted_with_actual_uuid ${FS}
369 mount -o loop ${FS}/nailgun.iso ${SOURCE}
372 OPENSTACK_VERSION=`cat ${SOURCE}/openstack_version`
374 # ----------------------
375 # UNPACKING REPOSITORIES
376 # ----------------------
378 wwwdir="/var/www/nailgun"
379 repodir="${wwwdir}/${OPENSTACK_VERSION}"
381 # Copying Centos files
382 mkdir -p ${repodir}/centos/x86_64
383 cp -r ${SOURCE}/images ${repodir}/centos/x86_64
384 cp -r ${SOURCE}/isolinux ${repodir}/centos/x86_64
385 cp -r ${SOURCE}/repodata ${repodir}/centos/x86_64
386 cp -r ${SOURCE}/Packages ${repodir}/centos/x86_64
387 cp ${SOURCE}/.treeinfo ${repodir}/centos/x86_64
389 # Copying Ubuntu files
390 mkdir -p ${repodir}/ubuntu/x86_64/images
391 cp -r ${SOURCE}/ubuntu/conf ${repodir}/ubuntu/x86_64
392 cp -r ${SOURCE}/ubuntu/db ${repodir}/ubuntu/x86_64
393 cp -r ${SOURCE}/ubuntu/dists ${repodir}/ubuntu/x86_64
394 cp -r ${SOURCE}/ubuntu/indices ${repodir}/ubuntu/x86_64
395 cp -r ${SOURCE}/ubuntu/pool ${repodir}/ubuntu/x86_64
396 cp -r ${SOURCE}/ubuntu/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux ${repodir}/ubuntu/x86_64/images
397 cp -r ${SOURCE}/ubuntu/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz ${repodir}/ubuntu/x86_64/images
399 # make links for backward compatibility
400 ln -s ${repodir}/centos ${wwwdir}/centos
401 ln -s ${repodir}/ubuntu ${wwwdir}/ubuntu
403 # Copying bootstrap image
404 mkdir -p ${wwwdir}/bootstrap
405 cp -r ${SOURCE}/bootstrap/initramfs.img ${wwwdir}/bootstrap
406 cp -r ${SOURCE}/bootstrap/linux ${wwwdir}/bootstrap
408 # Copying target images
409 cp -r ${SOURCE}/targetimages ${wwwdir}
413 cp ${SOURCE}/bootstrap/bootstrap.rsa /root/.ssh
414 chmod 600 /root/.ssh/bootstrap.rsa
416 # --------------------------
417 # UNPACKING PUPPET MANIFESTS
418 # --------------------------
421 mkdir -p /etc/puppet/${OPENSTACK_VERSION}/manifests/
422 mkdir -p /etc/puppet/${OPENSTACK_VERSION}/modules/
423 rm -rf /etc/puppet/modules/
425 # TODO(ikalnitsky): investigate why we need this
426 cp ${SOURCE}/puppet-slave.tgz ${wwwdir}/
428 # place modules and manifests
429 tar zxf ${SOURCE}/puppet-slave.tgz -C /etc/puppet/${OPENSTACK_VERSION}/modules
430 cp /etc/puppet/${OPENSTACK_VERSION}/modules/osnailyfacter/examples/site.pp /etc/puppet/${OPENSTACK_VERSION}/manifests/site.pp
431 cp ${SOURCE}/centos-versions.yaml ${SOURCE}/ubuntu-versions.yaml /etc/puppet/${OPENSTACK_VERSION}/manifests/
433 # make links for backward compatibility
435 ln -s ${OPENSTACK_VERSION}/manifests/ /etc/puppet/manifests
436 ln -s ${OPENSTACK_VERSION}/modules/ /etc/puppet/modules
439 cp ${SOURCE}/send2syslog.py /bin/send2syslog.py
440 mkdir -p /var/lib/hiera
441 touch /var/lib/hiera/common.yaml /etc/puppet/hiera.yaml
443 # Deploy docker images and ctl tools if we built ISO with docker containers support
444 [ -d "${SOURCE}/docker" ] && cp -r ${SOURCE}/docker ${wwwdir}/docker
446 # Prepare local repository specification
447 rm /etc/yum.repos.d/CentOS*.repo
448 cat > /etc/yum.repos.d/nailgun.repo << EOF
450 name=Nailgun Local Repo
451 baseurl=file:/var/www/nailgun/${OPENSTACK_VERSION}/centos/x86_64
455 # Disable subscription-manager plugins
456 sed -i 's/^enabled.*/enabled=0/' /etc/yum/pluginconf.d/product-id.conf || :
457 sed -i 's/^enabled.*/enabled=0/' /etc/yum/pluginconf.d/subscription-manager.conf || :
459 # Disable GSSAPI in ssh server config
460 sed -i -e "/^\s*GSSAPICleanupCredentials yes/d" -e "/^\s*GSSAPIAuthentication yes/d" /etc/ssh/sshd_config
462 # Copying bootstrap_admin_node.sh, chmod it and
463 # adding /etc/init/bootstrap_admin_node.conf
464 cp ${SOURCE}/bootstrap_admin_node.sh /usr/local/sbin/bootstrap_admin_node.sh
465 chmod 0777 /usr/local/sbin/bootstrap_admin_node.sh
466 cp ${SOURCE}/bootstrap_admin_node.conf /etc/init/bootstrap_admin_node.conf
467 echo "ENABLED=1" > /etc/sysconfig/bootstrap_admin_node
469 # Copying version.yaml file. It contains COMMIT_SHA of last commit.
470 RELEASE=$(awk '/release/{gsub(/"/, "");print $2}' ${SOURCE}/version.yaml)
471 mkdir -p /etc/nailgun /etc/fuel/${RELEASE} /etc/fuel/release_versions
472 cp ${SOURCE}/version.yaml /etc/nailgun/version.yaml
473 cp ${SOURCE}/version.yaml /etc/fuel/${RELEASE}/version.yaml
474 ln -s /etc/fuel/${RELEASE}/version.yaml /etc/fuel/version.yaml
475 cp ${SOURCE}/version.yaml /etc/fuel/release_versions/`cat ${SOURCE}/openstack_version`.yaml
478 uuidgen > /etc/fuel/fuel-uuid
481 [ -z "$showmenu" ] && showmenu="no"
482 cat > /root/.showfuelmenu << EOF
483 #Set to yes to run Fuel Setup
484 #Set to no to accept default settings
488 # Prepare custom /etc/issue logon banner and script for changing IP in it
489 cat > /etc/issue << EOF
490 #########################################
491 # Welcome to the Fuel server #
492 #########################################
493 Server is running on \m platform
495 Fuel UI is available on:
498 Default administrator login: root
499 Default administrator password: r00tme
501 Default Fuel UI login: admin
502 Default Fuel UI password: admin
504 Please change root password on first login.
509 cat >> '/etc/rc.local' << EOF
511 for ip in \$(ip -o -4 addr | grep "eth." | awk '{print \$4 }' | cut -d/ -f1); do
512 if [ "\$first" = "yes" ]; then
513 ipstr="Fuel UI is available on: http://\$ip:8000"
516 ipstr=\$(printf "%s\n%25s%s" "\$ipstr" " " "http://\$ip:8000")
520 while read -r line; do
521 if [[ "\$line" =~ "Fuel UI is available on" ]]; then
522 echo -e "\$ipstr" >> \$tmpissue
523 elif [[ "\$line" =~ :8000$ ]]; then
526 echo -e "\$line" >> \$tmpissue
529 mv "\$tmpissue" /etc/issue
538 umount -f ${FS} || true
541 # Enabling/configuring NTPD and ntpdate services
542 echo "server 127.127.1.0" >> /etc/ntp.conf
543 echo "fudge 127.127.1.0 stratum 10" >> /etc/ntp.conf
544 echo "tos orphan 7" >> /etc/ntp.conf
546 # Do not show error message on ntpdate failure. Customers should not be confused
547 # if admin node does not have access to the internet time servers.
548 sed -i /etc/rc.d/init.d/ntpdate -e 's/\([ $RETVAL -eq 0 ] && success || \)failure/\1success/'
551 sed -i --follow-symlinks -e '/^\skernel/ s/rhgb//' /etc/grub.conf
552 sed -i --follow-symlinks -e '/^\skernel/ s/quiet//' /etc/grub.conf
554 # Disabling console clearing
555 sed -i 's/getty/getty --noclear/' /etc/init/tty.conf
557 # Disabling starting first console from start-ttys service
558 sed -i --follow-symlinks -e 's/ACTIVE_CONSOLES=.*/ACTIVE_CONSOLES=\/dev\/tty\[2-6\]/' /etc/sysconfig/init
560 # Copying default bash settings to the root directory
561 cp -f /etc/skel/.bash* /root/
563 # Blacklist i2c_piix4 module for VirtualBox so it does not create kernel errors
564 [[ $(virt-what) = "virtualbox" ]] && echo "blacklist i2c_piix4" > /etc/modprobe.d/blacklist-i2c-piix4.conf