Version 0.0.1 of /fuel-bild
[genesis.git] / fuel-build / f_isoroot / f_kscfg / ks.cfg
1 install
2 text
3 %include /tmp/source.ks
4 reboot --eject
5 lang en_US.UTF-8
6 keyboard us
7 rootpw r00tme
8 timezone --utc Etc/UTC
9 firewall --disabled
10 selinux --disabled
11 # ignore unsupported hardware warning
12 unsupported_hardware
13 # SKIP CONFIGURING X
14 skipx
15 # NEVER ever place zerombr here, it breaks automated installation
16 %include /tmp/bootloader.ks
17 %include /tmp/partition.ks
18
19 # PREINSTALL SECTION
20 # HERE ARE COMMANDS THAT WILL BE LAUNCHED BEFORE
21 # INSTALLATION PROCESS ITSELF
22 %pre
23 #!/bin/sh
24
25 # hard drives
26 drives=""
27 removable_drives=""
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}"
31     else
32         removable_drives="${removable_drives} ${drv}"
33     fi
34 done
35 default_drive=`echo ${drives} ${removable_drives} | awk '{print $1}'`
36
37 installdrive="undefined"
38 forceformat="no"
39 for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done
40
41 set ${drives} ${removable_drives}
42 numdrives=`echo $#`
43
44 tgtdrive="${installdrive}"
45
46 function confirm_format {
47   check_drive="$1"
48   local confirm_format="no"
49
50   if [[ "$forceformat" == "yes" ]] ; then
51     return 0
52   fi
53
54   if parted -s /dev/$check_drive print &>/dev/null ; then
55     echo
56     echo "$check_drive drive contains partition table:"
57     parted -s /dev/$check_drive print
58     echo
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" ]] || [[ "$forceformat" == "yes" ]]; then
61       return 0
62     else
63       return 1
64     fi
65   else
66     return 0
67   fi
68 }
69
70 format_confirmed="no"
71
72 if [ $numdrives -lt 1 ]; then
73     exec < /dev/tty3 > /dev/tty3 2>&1
74     chvt 3
75     clear
76     echo
77     echo '********************************************************************'
78     echo '*                            E R R O R                             *'
79     echo '*                                                                  *'
80     echo '*      There is no suitable media available for installation.      *'
81     echo '*                Please attach a drive and try again.              *'
82     echo '*                                                                  *'
83     echo '********************************************************************'
84     echo
85     read -p "Press Enter to shut down the system: " _
86     poweroff
87 fi
88
89 if [ ${numdrives} -gt 1 ] || [ `echo ${drives} | wc -w` -eq 0 ] ; then
90     exec < /dev/tty3 > /dev/tty3 2>&1
91     chvt 3
92     while [ "${tgtdrive}" = "undefined" ]; do
93         clear
94         echo
95         echo '********************************************************************************'
96         echo '*                                 W A R N I N G                                *'
97         echo '*                                                                              *'
98         echo '*  Which of the detected hard drives do you want to be used as                 *'
99         echo '*  the installation target?                                                    *'
100         echo '*                                                                              *'
101         echo '********************************************************************************'
102         echo
103         echo "Possible choices"
104         echo "Persistent drives: ${drives}"
105         echo "Removable drives: ${removable_drives}"
106         echo
107         if [ `echo ${drives} | wc -w` -eq 1 ] ; then
108             read -t 30 -p "Choose hard drive: " tgtdrive || tgtdrive=$default_drive
109         else
110             read -p "Choose hard drive: " tgtdrive
111         fi
112         match="no"
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"
117               break
118             else
119               tgtdrive="undefined"
120               read -p "You may select another disk. Press Enter to continue." _
121             fi
122           fi
123         done
124         if [[ "$match" == "no" ]]; then
125           tgtdrive="undefined"
126           read -p "Invalid choice. Press Enter to continue." _
127         fi
128     done
129     clear
130     chvt 1
131 else
132     tgtdrive=`echo ${drives} | sed -e "s/^\s*//" -e "s/\s*$//"`
133 fi
134
135 if [ "$format_confirmed" != "yes" ] ; then
136   exec < /dev/tty3 > /dev/tty3 2>&1
137   chvt 3
138   if ! confirm_format $tgtdrive ; then
139       clear
140       echo
141       echo '********************************************************************'
142       echo '*                            E R R O R                             *'
143       echo '*                                                                  *'
144       echo '*           Disk $tgtdrive contains active partition(s).           *'
145       echo '*        Installation cannot continue without confirmation.        *'
146       echo '*                                                                  *'
147       echo '********************************************************************'
148       echo
149       read -p "Press Enter to restart: " _
150       reboot
151   fi
152   chvt 1
153 fi
154
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
159     chvt 3
160     clear
161     echo
162     echo '********************************************************************'
163     echo '*                            E R R O R                             *'
164     echo '*                                                                  *'
165     echo '*  Your disk is under 30GB in size. Installation cannot continue.  *'
166     echo '*             Restart installation with a larger disk.             *'
167     echo '*                                                                  *'
168     echo '********************************************************************'
169     echo
170     read -p "Press Enter to restart: " _
171     reboot
172 fi
173
174 # paths in /dev have "/" instead of "!" for cciss devices
175 tgtdrive=$(echo $tgtdrive | sed -e 's/!/\//')
176
177 # source
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
180 else
181     echo "cdrom" > /tmp/source.ks
182 fi
183
184 vgremove -ff os
185 dd if=/dev/zero of=/dev/${tgtdrive} bs=10M count=10
186 sleep 3
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
194 sleep 3
195 hdparm -z /dev/${tgtdrive}
196
197 # partition
198
199 # This adds support for the p seperator required for cciss devices
200 if echo ${tgtdrive} | grep -q -e cciss ; then
201     bootdev=${tgtdrive}p
202 else
203     bootdev=${tgtdrive}
204 fi
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
212
213 # bootloader
214 echo "bootloader --location=mbr --driveorder=${tgtdrive} --append=' biosdevname=0 crashkernel=none'" > /tmp/bootloader.ks
215
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
229
230 %end
231
232 %packages --nobase --excludedocs
233 @Core
234 authconfig
235 bind-utils
236 cronie
237 crontabs
238 curl
239 daemonize
240 dhcp
241 docker-io
242 fuelmenu
243 gdisk
244 lrzip
245 lsof
246 man
247 mlocate
248 nmap-ncat
249 ntp
250 openssh-clients
251 policycoreutils
252 rsync
253 ruby21-puppet
254 ruby21-rubygem-netaddr
255 ruby21-rubygem-openstack
256 selinux-policy-targeted
257 strace
258 subscription-manager
259 sysstat
260 system-config-firewall-base
261 tcpdump
262 telnet
263 vim-enhanced
264 virt-what
265 wget
266 yum
267
268 %include /tmp/post_partition.ks
269
270 # POSTINSTALL SECTION
271 # HERE ARE COMMANDS THAT WILL BE LAUNCHED JUST AFTER
272 # INSTALLATION ITSELF COMPLETED
273 %post
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
281
282 # Mount installation media in chroot
283 %post --nochroot --log=/mnt/sysimage/root/anaconda-post-before-chroot.log
284 #!/bin/sh
285
286 SOURCE="/mnt/sysimage/tmp/source"
287
288 for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done
289
290 mkdir -p "${SOURCE}"
291
292 case "${repo}" in
293   nfs:*)
294     nfs_url="${repo#nfs:}"
295     mount -t nfs "${nfs_url}" "${SOURCE}"
296   ;;
297   *)
298     if [ -d "/mnt/source" ]; then
299       mount -o bind "/mnt/source" "${SOURCE}"
300     fi
301   ;;
302 esac
303
304 %post --log=/root/anaconda-post-after-chroot.log
305 #!/bin/bash
306
307 set -x
308
309 function save_cfg {
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
319
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
326     if [ $ip ]; then
327         echo BOOTPROTO=static >> $scrFile
328         echo IPADDR=$ip >> $scrFile
329         echo NETMASK=$netmask >> $scrFile
330     else
331         echo BOOTPROTO=dhcp >> $scrFile
332     fi
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
340     else
341         echo GATEWAY=$gw >> /etc/sysconfig/network
342     fi
343 }
344
345 # Default FQDN
346 hostname="nailgun.mirantis.com"
347
348 for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done
349 hostname=$hostname
350 domain=${hostname#*.}
351 ip=$ip
352 netmask=$netmask
353 gw=$gw
354 device="eth0"
355 hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
356 dhcp_interface=$dhcp_interface
357 save_cfg
358
359 # Mounting installation source
360 SOURCE=/tmp/source
361 FS=/tmp/fs
362
363 echo
364 mkdir -p ${SOURCE}
365 mkdir -p ${FS}
366
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}
370 fi
371
372 # Copying Repo to the nailgun /var/www directory
373 repodir="/var/www/nailgun"
374 mkdir -p ${repodir}/centos/fuelweb/x86_64
375 cp -r ${SOURCE}/images ${repodir}/centos/fuelweb/x86_64
376 cp -r ${SOURCE}/isolinux ${repodir}/centos/fuelweb/x86_64
377 cp -r ${SOURCE}/repodata ${repodir}/centos/fuelweb/x86_64
378 cp -r ${SOURCE}/Packages ${repodir}/centos/fuelweb/x86_64
379 cp ${SOURCE}/.treeinfo ${repodir}/centos/fuelweb/x86_64
380
381 # Copying Ubuntu files
382 mkdir -p ${repodir}/ubuntu/fuelweb/x86_64/images
383 cp -r ${SOURCE}/ubuntu/conf ${repodir}/ubuntu/fuelweb/x86_64
384 cp -r ${SOURCE}/ubuntu/db ${repodir}/ubuntu/fuelweb/x86_64
385 cp -r ${SOURCE}/ubuntu/dists ${repodir}/ubuntu/fuelweb/x86_64
386 cp -r ${SOURCE}/ubuntu/indices ${repodir}/ubuntu/fuelweb/x86_64
387 cp -r ${SOURCE}/ubuntu/pool ${repodir}/ubuntu/fuelweb/x86_64
388 cp -r ${SOURCE}/ubuntu/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux ${repodir}/ubuntu/fuelweb/x86_64/images
389 cp -r ${SOURCE}/ubuntu/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz ${repodir}/ubuntu/fuelweb/x86_64/images
390
391 # Copying bootstrap image
392 mkdir -p ${repodir}/bootstrap
393 cp -r ${SOURCE}/bootstrap/initramfs.img ${repodir}/bootstrap
394 cp -r ${SOURCE}/bootstrap/linux ${repodir}/bootstrap
395
396 mkdir -p /root/.ssh
397 chmod 700 /root/.ssh
398 cp ${SOURCE}/bootstrap/bootstrap.rsa /root/.ssh
399 chmod 600 /root/.ssh/bootstrap.rsa
400
401 # Unpacking puppet manifests for master and slave
402 cp ${SOURCE}/puppet-slave.tgz ${repodir}/
403 tar zxf ${SOURCE}/puppet-slave.tgz -C /etc/puppet/modules
404 mkdir -p /etc/puppet/manifests/
405 cp /etc/puppet/modules/osnailyfacter/examples/site.pp /etc/puppet/manifests/site.pp
406 cp ${SOURCE}/centos-versions.yaml ${SOURCE}/ubuntu-versions.yaml /etc/puppet/manifests/
407 cp ${SOURCE}/send2syslog.py /bin/send2syslog.py
408 mkdir -p /var/lib/hiera
409 touch /var/lib/hiera/common.yaml /etc/puppet/hiera.yaml
410
411 # Deploy docker images and ctl tools if we built ISO with docker containers support
412 [ -d "${SOURCE}/docker" ] && cp -r ${SOURCE}/docker ${repodir}/docker
413
414 # Prepare local repository specification
415 rm /etc/yum.repos.d/CentOS*.repo
416 cat > /etc/yum.repos.d/nailgun.repo << EOF
417 [nailgun]
418 name=Nailgun Local Repo
419 baseurl=file:/var/www/nailgun/centos/fuelweb/x86_64
420 gpgcheck=0
421 EOF
422
423 # Disable subscription-manager plugins
424 sed -i 's/^enabled.*/enabled=0/' /etc/yum/pluginconf.d/product-id.conf || :
425 sed -i 's/^enabled.*/enabled=0/' /etc/yum/pluginconf.d/subscription-manager.conf || :
426
427 # Disable GSSAPI in ssh server config
428 sed -i -e "/^\s*GSSAPICleanupCredentials yes/d" -e "/^\s*GSSAPIAuthentication yes/d" /etc/ssh/sshd_config
429
430 # Copying bootstrap_admin_node.sh, chmod it and
431 # adding /etc/init/bootstrap_admin_node.conf
432 cp ${SOURCE}/bootstrap_admin_node.sh /usr/local/sbin/bootstrap_admin_node.sh
433 chmod 0777 /usr/local/sbin/bootstrap_admin_node.sh
434 cp ${SOURCE}/bootstrap_admin_node.conf /etc/init/bootstrap_admin_node.conf
435 echo "ENABLED=1" > /etc/sysconfig/bootstrap_admin_node
436
437 # Copying version.yaml file. It contains COMMIT_SHA of last commit.
438 RELEASE=$(awk '/release/{gsub(/"/, "");print $2}' ${SOURCE}/version.yaml)
439 mkdir -p /etc/nailgun /etc/fuel/${RELEASE} /etc/fuel/release_versions
440 cp ${SOURCE}/version.yaml /etc/nailgun/version.yaml
441 cp ${SOURCE}/version.yaml /etc/fuel/${RELEASE}/version.yaml
442 ln -s /etc/fuel/${RELEASE}/version.yaml /etc/fuel/version.yaml
443 cp ${SOURCE}/version.yaml /etc/fuel/release_versions/`cat  ${SOURCE}/openstack_version`.yaml
444
445 # Generete Fuel UUID
446 uuidgen > /etc/fuel/fuel-uuid
447
448 ###Run fuel menu
449 [ -z "$showmenu" ] && showmenu="no"
450 cat > /root/.showfuelmenu << EOF
451 #Set to yes to run Fuel Setup
452 #Set to no to accept default settings
453 showmenu=$showmenu
454 EOF
455
456 # Prepare custom /etc/issue logon banner and script for changing IP in it
457 cat > /etc/issue << EOF
458 #########################################
459 #       Welcome to the Fuel server      #
460 #########################################
461 Server is running on \m platform
462
463 Fuel UI is available on:
464 http://:8000
465
466 Default administrator login:    root
467 Default administrator password: r00tme
468
469 Default Fuel UI login: admin
470 Default Fuel UI password: admin
471
472 Please change root password on first login.
473
474 EOF
475
476
477 cat >> '/etc/rc.local' << EOF
478 first=yes
479 for ip in \$(ip -o -4 addr | grep "eth." | awk '{print \$4 }' | cut -d/ -f1); do
480 if [ "\$first" = "yes" ]; then
481   ipstr="Fuel UI is available on: http://\$ip:8000"
482   first=no
483 else
484   ipstr=\$(printf "%s\n%51s" "\$ipstr" "http://\$ip:8000")
485 fi
486 done
487 tmpissue=\$(mktemp)
488 while read -r line; do
489   if [[ "\$line" =~ "Fuel UI is available on" ]]; then
490     echo -e "\$ipstr" >> \$tmpissue
491   elif [[ "\$line" =~ :8000$ ]]; then
492     :
493   else
494     echo -e "\$line" >> \$tmpissue
495   fi
496 done < /etc/issue
497 mv "\$tmpissue" /etc/issue
498
499 EOF
500
501 ######### OPNFV addition BEGIN ############
502 # Copy data into /opt/opnfv
503 # TODO: This ought to be a package instead!
504 mkdir -p /opt/opnfv
505 cp -r ${SOURCE}/opnfv /opt
506 ######### OPNFV addition END ############
507
508 # Unmounting source
509 umount -f ${SOURCE}
510 rm -rf ${SOURCE}
511
512 umount -f ${FS} || true
513 rm -rf ${FS}
514
515 # Enabling/configuring NTPD and ntpdate services
516 echo "server 127.127.1.0"            >> /etc/ntp.conf
517 echo "fudge  127.127.1.0 stratum 10" >> /etc/ntp.conf
518 echo "tos    orphan 7"               >> /etc/ntp.conf
519
520 # Do not show error message on ntpdate failure. Customers should not be confused
521 # if admin node does not have access to the internet time servers.
522 sed -i /etc/rc.d/init.d/ntpdate -e 's/\([ $RETVAL -eq 0 ] && success || \)failure/\1success/'
523
524 # Disabling splash
525 sed -i --follow-symlinks -e '/^\skernel/ s/rhgb//' /etc/grub.conf
526 sed -i --follow-symlinks -e '/^\skernel/ s/quiet//' /etc/grub.conf
527
528 # Disabling console clearing
529 sed -i 's/getty/getty --noclear/' /etc/init/tty.conf
530
531 # Disabling starting first console from start-ttys service
532 sed -i --follow-symlinks -e 's/ACTIVE_CONSOLES=.*/ACTIVE_CONSOLES=\/dev\/tty\[2-6\]/' /etc/sysconfig/init
533
534 # Copying default bash settings to the root directory
535 cp -f /etc/skel/.bash* /root/
536
537 # Blacklist i2c_piix4 module for VirtualBox so it does not create kernel errors
538 [[ $(virt-what) = "virtualbox" ]] && echo "blacklist i2c_piix4" > /etc/modprobe.d/blacklist-i2c-piix4.conf
539
540 %end