Add initial meta-stx to support StarlingX build
[pti/rtp.git] / meta-stx / conf / distro / files / ks / net_worker_ks.cfg
1 #
2 # Copyright (c) 2019 Wind River Systems, Inc.
3 # SPDX-License-Identifier: Apache-2.0
4 #
5
6 %pre
7 # This file defines functions that can be used in %pre and %post kickstart sections, by including:
8 # . /tmp/ks-functions.sh
9 #
10
11 cat <<END_FUNCTIONS >/tmp/ks-functions.sh
12 #
13 # Copyright (c) 2019 Wind River Systems, Inc.
14 #
15 # SPDX-License-Identifier: Apache-2.0
16 #
17
18 function get_by_path()
19 {
20     local disk=\$(cd /dev ; readlink -f \$1)
21     for p in /dev/disk/by-path/*; do
22         if [ "\$disk" = "\$(readlink -f \$p)" ]; then
23             echo \$p
24             return
25         fi
26     done
27 }
28
29 function get_disk()
30 {
31     echo \$(cd /dev ; readlink -f \$1)
32 }
33
34 function report_pre_failure_with_msg()
35 {
36     local msg=\$1
37     echo -e '\n\nInstallation failed.\n'
38     echo "\$msg"
39
40     exit 1
41 }
42
43 function report_post_failure_with_msg()
44 {
45     local msg=\$1
46     cat <<EOF >> /etc/motd
47
48 Installation failed.
49 \$msg
50
51 EOF
52     echo "\$msg" >/etc/platform/installation_failed
53
54     echo -e '\n\nInstallation failed.\n'
55     echo "\$msg"
56
57     exit 1
58 }
59
60 function report_post_failure_with_logfile()
61 {
62     local logfile=\$1
63     cat <<EOF >> /etc/motd
64
65 Installation failed.
66 Please see \$logfile for details of failure
67
68 EOF
69     echo \$logfile >/etc/platform/installation_failed
70
71     echo -e '\n\nInstallation failed.\n'
72     cat \$logfile
73
74     exit 1
75 }
76
77 function get_http_port()
78 {
79     echo \$(cat /proc/cmdline |xargs -n1 echo |grep '^inst.repo=' | sed -r 's#^[^/]*://[^/]*:([0-9]*)/.*#\1#')
80 }
81
82 END_FUNCTIONS
83
84 %end
85
86 %post
87 # This file defines functions that can be used in %pre and %post kickstart sections, by including:
88 # . /tmp/ks-functions.sh
89 #
90
91 cat <<END_FUNCTIONS >/tmp/ks-functions.sh
92 #
93 # Copyright (c) 2019 Wind River Systems, Inc.
94 #
95 # SPDX-License-Identifier: Apache-2.0
96 #
97
98 function get_by_path()
99 {
100     local disk=\$(cd /dev ; readlink -f \$1)
101     for p in /dev/disk/by-path/*; do
102         if [ "\$disk" = "\$(readlink -f \$p)" ]; then
103             echo \$p
104             return
105         fi
106     done
107 }
108
109 function get_disk()
110 {
111     echo \$(cd /dev ; readlink -f \$1)
112 }
113
114 function report_pre_failure_with_msg()
115 {
116     local msg=\$1
117     echo -e '\n\nInstallation failed.\n'
118     echo "\$msg"
119
120     exit 1
121 }
122
123 function report_post_failure_with_msg()
124 {
125     local msg=\$1
126     cat <<EOF >> /etc/motd
127
128 Installation failed.
129 \$msg
130
131 EOF
132     echo "\$msg" >/etc/platform/installation_failed
133
134     echo -e '\n\nInstallation failed.\n'
135     echo "\$msg"
136
137     exit 1
138 }
139
140 function report_post_failure_with_logfile()
141 {
142     local logfile=\$1
143     cat <<EOF >> /etc/motd
144
145 Installation failed.
146 Please see \$logfile for details of failure
147
148 EOF
149     echo \$logfile >/etc/platform/installation_failed
150
151     echo -e '\n\nInstallation failed.\n'
152     cat \$logfile
153
154     exit 1
155 }
156
157 function get_http_port()
158 {
159     echo \$(cat /proc/cmdline |xargs -n1 echo |grep '^inst.repo=' | sed -r 's#^[^/]*://[^/]*:([0-9]*)/.*#\1#')
160 }
161
162 END_FUNCTIONS
163
164 %end
165
166
167 # Template from: pre_common_head.cfg
168 %pre --erroronfail
169
170 # Source common functions
171 . /tmp/ks-functions.sh
172
173 # First, parse /proc/cmdline to find the boot args
174 set -- `cat /proc/cmdline`
175 for I in $*; do case "$I" in *=*) eval $I 2>/dev/null;; esac; done
176
177 append=
178 if [ -n "$console" ] ; then
179     append="console=$console"
180 fi
181
182 if [ -n "$security_profile" ]; then
183     append="$append security_profile=$security_profile"
184 fi
185
186 #### SECURITY PROFILE HANDLING (Pre Installation) ####
187 if [ -n "$security_profile" ] && [ "$security_profile" == "extended" ]; then
188     # IMA specific boot options:
189     # Enable Kernel auditing
190     append="$append audit=1"
191 else
192     # we need to blacklist the IMA and Integrity Modules
193     # on standard security profile
194     append="$append module_blacklist=integrity,ima"
195     
196     # Disable Kernel auditing in Standard Security Profile mode
197     append="$append audit=0"
198 fi
199
200 if [ -n "$tboot" ]; then
201     append="$append tboot=$tboot"
202 else
203     append="$append tboot=false"
204 fi
205
206 boot_device_arg=
207 if [ -n "$boot_device" ] ; then
208     boot_device_arg="--boot-drive=$(get_by_path $boot_device)"
209 fi
210
211 echo "bootloader --location=mbr $boot_device_arg --timeout=5 --append=\"$append\"" > /tmp/bootloader-include
212
213 echo "timezone --nontp --utc UTC" >/tmp/timezone-include
214 %end
215
216 #version=DEVEL
217 install
218 lang en_US.UTF-8
219 keyboard us
220 %include /tmp/timezone-include
221 # set to 'x' so we can use shadow password
222 rootpw  --iscrypted x
223 selinux --disabled
224 authconfig --enableshadow --passalgo=sha512
225 firewall --service=ssh
226
227 # The following is the partition information you requested
228 # Note that any partitions you deleted are not expressed
229 # here so unless you clear all partitions first, this is
230 # not guaranteed to work
231 zerombr
232
233 # Disk layout from %pre
234 %include /tmp/part-include
235 # Bootloader parms from %pre
236 %include /tmp/bootloader-include
237
238 reboot --eject
239
240
241 # Template from: pre_net_common.cfg
242 %pre
243
244 # Setup ntp.conf and sync time
245 cat <<EOF >/etc/ntp_kickstart.conf
246 server pxecontroller
247 EOF
248
249 /usr/sbin/ntpd -g -q -n -c /etc/ntp_kickstart.conf
250 if [ $? -eq 0 ]; then
251     /sbin/hwclock --systohc --utc
252 fi
253
254 %end
255
256
257 # Template from: pre_pkglist.cfg
258 %packages
259 @core
260 @base
261 -kernel-module-igb-uio-rt
262 -kernel-module-wrs-avp-rt
263 -kernel-rt
264 -kernel-rt-kvm
265 -kernel-rt-tools
266 -kernel-rt-tools-libs
267 -kmod-drbd-rt
268 -kmod-e1000e-rt
269 -kmod-i40e-rt
270 -kmod-ixgbe-rt
271 -kmod-tpm-rt
272 -mlnx-ofa_kernel
273 -mlnx-ofa_kernel-rt
274 -mlnx-ofa_kernel-rt-modules
275 -qat16-rt
276 @platform-worker
277 @updates-worker
278 %end
279
280
281 # Template from: pre_disk_setup_common.cfg
282 %pre --erroronfail
283
284 # Source common functions
285 . /tmp/ks-functions.sh
286
287 # This is a really fancy way of finding the first usable disk for the
288 # install and not stomping on the USB device if it comes up first
289
290 # First, parse /proc/cmdline to find the boot args
291 set -- `cat /proc/cmdline`
292 for I in $*; do case "$I" in *=*) eval $I 2>/dev/null;; esac; done
293
294 # Find either the ISO or USB device first chopping off partition
295 ISO_DEV=`readlink /dev/disk/by-label/oe_iso_boot`
296 sdev=`echo $ISO_DEV | sed -e 's/.$//'`
297 if [ -e /dev/disk/by-label/$sdev ] ; then
298     ISO_DEV=$sdev
299 fi
300 USB_DEV=`readlink /dev/disk/by-label/wr_usb_boot`
301 sdev=`echo $USB_DEV | sed -e 's/.$//'`
302 if [ -e /dev/disk/by-label/$sdev ] ; then
303     USB_DEV=$sdev
304 fi
305
306 # Temporary, until lab pxelinux.cfg files are updated to specify install devices
307 if [ -z "$rootfs_device" -o -z "$boot_device" ]
308 then
309     INST_HDD=""
310     # Prefer a vd* device if this is kvm/qemu
311     for e in vda vdb sda sdb nvme0n1; do
312         if [ -e /dev/$e -a "$ISO_DEV" != "../../$e" -a "$USB_DEV" != "../../$e" ] ; then
313             INST_HDD=$e
314             break
315         fi
316     done
317
318     # Set variables to $INST_HDD if not set
319     rootfs_device=${rootfs_device:-$INST_HDD}
320     boot_device=${boot_device:-$INST_HDD}
321 fi
322
323 # Convert to by-path
324 orig_rootfs_device=$rootfs_device
325 rootfs_device=$(get_by_path $rootfs_device)
326
327 orig_boot_device=$boot_device
328 boot_device=$(get_by_path $boot_device)
329
330 if [ ! -e "$rootfs_device" -o ! -e "$boot_device" ] ; then
331     # Touch this file to prevent Anaconda from dying an ungraceful death
332     touch /tmp/part-include
333
334     report_pre_failure_with_msg "ERROR: Specified installation ($orig_rootfs_device) or boot ($orig_boot_device) device is invalid."
335 fi
336
337 # Ensure specified device is not a USB drive
338 udevadm info --query=property --name=$rootfs_device |grep -q '^ID_BUS=usb' || \
339     udevadm info --query=property --name=$boot_device |grep -q '^ID_BUS=usb'
340 if [ $? -eq 0 ]; then
341     # Touch this file to prevent Anaconda from dying an ungraceful death
342     touch /tmp/part-include
343
344     report_pre_failure_with_msg "ERROR: Specified installation ($orig_rootfs_device) or boot ($orig_boot_device) device is a USB drive."
345 fi
346
347 # Deactivate existing volume groups to avoid Anaconda issues with pre-existing groups
348 vgs --noheadings -o vg_name | xargs --no-run-if-empty -n 1 vgchange -an
349
350 # Remove volumes and group for cgts-vg, if any
351 lvremove --force cgts-vg
352 pvs --select 'vg_name=cgts-vg' --noheadings -o pv_name | xargs --no-run-if-empty pvremove --force --force --yes
353 vgs --select 'vg_name=cgts-vg' --noheadings -o vg_name | xargs --no-run-if-empty vgremove --force
354
355 ONLYUSE_HDD=""
356 if [ "$(curl -sf http://pxecontroller:6385/v1/upgrade/$(hostname)/in_upgrade 2>/dev/null)" = "true" ]; then
357     # In an upgrade, only wipe the disk with the rootfs and boot partition
358     echo "In upgrade, wiping only $rootfs_device"
359     WIPE_HDD="$(get_disk $rootfs_device)"
360     ONLYUSE_HDD="$(basename $(get_disk $rootfs_device))"
361     if [ "$(get_disk $rootfs_device)" != "$(get_disk $boot_device)" ]; then
362         WIPE_HDD="$WIPE_HDD,$(get_disk $boot_device)"
363         ONLYUSE_HDD="$ONLYUSE_HDD,$(basename $(get_disk $boot_device))"
364     fi
365 else
366     # Make a list of all the hard drives that are to be wiped
367     WIPE_HDD=""
368     # Partition type OSD has a unique globally identifier
369     part_type_guid_str="Partition GUID code"
370     CEPH_OSD_GUID="4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D"
371
372     # Check if we wipe OSDs
373     if [ "$(curl -sf http://pxecontroller:6385/v1/ihosts/wipe_osds 2>/dev/null)" = "true" ]; then
374         echo "Wipe OSD data."
375         WIPE_CEPH_OSDS="true"
376     else
377         echo "Skip Ceph OSD data wipe."
378         WIPE_CEPH_OSDS="false"
379     fi
380
381     for f in /dev/disk/by-path/*
382     do
383         dev=$(readlink -f $f)
384         lsblk --nodeps --pairs $dev | grep -q 'TYPE="disk"'
385         if [ $? -ne 0 ]
386         then
387             continue
388         fi
389
390         # Avoid wiping USB drives
391         udevadm info --query=property --name=$dev |grep -q '^ID_BUS=usb' && continue
392
393         # Avoid wiping ceph osds if sysinv tells us so
394         if [ ${WIPE_CEPH_OSDS} == "false" ]; then
395             wipe_dev="true"
396             part_numbers=( `parted -s $dev print | awk '$1 == "Number" {i=1; next}; i {print $1}'` )
397             # Scanning the partitions looking for CEPH OSDs and
398             # skipping any disk found with such partitions
399             for part_number in "${part_numbers[@]}"; do
400                 sgdisk_part_info=$(flock $dev sgdisk -i $part_number $dev)
401                 part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}')
402                 if [ "$part_type_guid" == $CEPH_OSD_GUID ]; then
403                     echo "OSD found on $dev, skipping wipe"
404                     wipe_dev="false"
405                     break
406                 fi
407             done
408             if [ "$wipe_dev" == "false" ]; then
409                 continue
410             fi
411         fi
412
413         # Add device to the wipe list
414         devname=$(basename $dev)
415         if [ -e $dev -a "$ISO_DEV" != "../../$devname" -a "$USB_DEV" != "../../$devname" ]; then
416             if [ -n "$WIPE_HDD" ]; then
417                 WIPE_HDD=$WIPE_HDD,$dev
418             else
419                 WIPE_HDD=$dev
420             fi
421         fi
422     done
423     echo "Not in upgrade, wiping disks: $WIPE_HDD"
424 fi
425
426 for dev in ${WIPE_HDD//,/ }
427 do
428     # Clearing previous GPT tables or LVM data
429     # Delete the first few bytes at the start and end of the partition. This is required with
430     # GPT partitions, they save partition info at the start and the end of the block.
431     # Do this for each partition on the disk, as well.
432     partitions=$(lsblk -rip $dev -o TYPE,NAME |awk '$1 == "part" {print $2}')
433     for p in $partitions $dev
434     do
435         echo "Pre-wiping $p from kickstart"
436         dd if=/dev/zero of=$p bs=512 count=34
437         dd if=/dev/zero of=$p bs=512 count=34 seek=$((`blockdev --getsz $p` - 34))
438     done
439 done
440
441 # Check for remaining cgts-vg PVs, which could potentially happen
442 # in an upgrade where we're not wiping all disks.
443 # If we ever create other volume groups from kickstart in the future,
444 # include them in this search as well.
445 partitions=$(pvs --select 'vg_name=cgts-vg' -o pv_name --noheading | grep -v '\[unknown\]')
446 for p in $partitions
447 do
448     echo "Pre-wiping $p from kickstart (cgts-vg present)"
449     dd if=/dev/zero of=$p bs=512 count=34
450     dd if=/dev/zero of=$p bs=512 count=34 seek=$((`blockdev --getsz $p` - 34))
451 done
452
453 let -i gb=1024*1024*1024
454
455 cat<<EOF>/tmp/part-include
456 clearpart --all --drives=$WIPE_HDD --initlabel
457 EOF
458
459 if [ -n "$ONLYUSE_HDD" ]; then
460     cat<<EOF>>/tmp/part-include
461 ignoredisk --only-use=$ONLYUSE_HDD
462 EOF
463 fi
464
465 if [ -d /sys/firmware/efi ] ; then
466     cat<<EOF>>/tmp/part-include
467 part /boot/efi --fstype=efi --size=300 --ondrive=$(get_disk $boot_device)
468 EOF
469 else
470     cat<<EOF>>/tmp/part-include
471 part biosboot --asprimary --fstype=biosboot --size=1 --ondrive=$(get_disk $boot_device)
472 EOF
473 fi
474
475
476 # Template from: pre_disk_worker.cfg
477 LOG_VOL_SIZE=4000
478 SCRATCH_VOL_SIZE=4000
479 BOOT_VOL_SIZE=500
480
481 ## LOG_VOL_SIZE = 4096
482 ## SCRATCH_VOL_SIZE = 4096
483 ## DOCKER = 30720
484 ## CEPH_MON = 20480
485 ## KUBELET_VOL_SIZE = 10240
486 ## RESERVED_PE = 16 (based on pesize=32768)
487 ##
488 ## CGTS_PV_SIZE = 4096 + 4096 + 30720 + 20480 + 10240 + 16 = 69648
489 ##
490 ## Round CGTS_PV_SIZE to the closest upper value that can be divided by 1024.
491 ## 69648/1024=68.01. CGTS_PV_SIZE=69*1024=70656.
492 CGTS_PV_SIZE=70656
493
494 sz=$(blockdev --getsize64 $(get_disk $rootfs_device))
495 if [ $sz -le $((80*$gb)) ] ; then
496     ## Less than 80GB use a 10GB root partition
497     ROOTFS_SIZE=10000
498 else
499     ## Use a 20GB root partition
500     ROOTFS_SIZE=20000
501 fi
502
503 ROOTFS_OPTIONS="defaults"
504 profile_mode=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended`
505 if [ -n "$profile_mode" ]; then
506    # Enable iversion labelling for rootfs when IMA is enabled
507    ROOTFS_OPTIONS="${ROOTFS_OPTIONS},iversion"
508 fi
509
510 cat<<EOF>>/tmp/part-include
511 part /boot --fstype=ext4 --asprimary --size=$BOOT_VOL_SIZE --ondrive=$(get_disk $rootfs_device) --fsoptions="$ROOTFS_OPTIONS"
512 part pv.253004 --asprimary --size=$CGTS_PV_SIZE --ondrive=$(get_disk $rootfs_device)
513 volgroup cgts-vg --pesize=32768 pv.253004
514 logvol /var/log --fstype=ext4 --vgname=cgts-vg --size=$LOG_VOL_SIZE --name=log-lv
515 logvol /scratch --fstype=ext4 --vgname=cgts-vg --size=$SCRATCH_VOL_SIZE --name=scratch-lv
516 part / --fstype=ext4 --asprimary --size=$ROOTFS_SIZE --ondrive=$(get_disk $rootfs_device) --fsoptions="$ROOTFS_OPTIONS"
517
518 EOF
519
520 %end
521
522
523 # Template from: post_platform_conf_worker.cfg
524 %post --erroronfail
525
526 # Source common functions
527 . /tmp/ks-functions.sh
528
529 # Retrieve the installation uuid from the controller we booted from
530 http_port=$(get_http_port)
531 INSTALL_UUID=`curl -sf http://pxecontroller:${http_port:-8080}/feed/rel-19.12/install_uuid`
532 if [ $? -ne 0 ]
533 then
534   INSTALL_UUID=unknown
535 fi
536
537 # Set the security profile mode
538 secprofile="standard"
539 profile_mode=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended`
540 if [ -n "$profile_mode" ]; then
541    secprofile="extended"
542 fi
543
544 mkdir -p -m 0775 /etc/platform
545 cat <<EOF > /etc/platform/platform.conf
546 nodetype=worker
547 subfunction=worker
548 system_type=Standard
549 security_profile=$secprofile
550 INSTALL_UUID=$INSTALL_UUID
551 EOF
552
553 # mount the platform directory from the controller
554 cat >> /etc/fstab <<EOF
555 controller-platform-nfs:/opt/platform   /opt/platform   nfs     timeo=30,udp,rsize=1024,wsize=1024,_netdev 0 0
556 EOF
557
558 %end
559
560 # Template from: post_common.cfg
561 %post --erroronfail
562
563 # Source common functions
564 . /tmp/ks-functions.sh
565
566 # Turn off locale support for i18n if is not installed
567 if [ ! -d /usr/share/i18n ] ; then
568    rm -f /etc/sysconfig/i18n
569 fi
570 # Unset the hostname
571 rm /etc/hostname
572
573 # If using a serial install make sure to add a getty on the tty1
574 conarg=`cat /proc/cmdline |xargs -n1 echo |grep console= |grep ttyS`
575 if [ -n "$conarg" ] ; then
576    echo "1:2345:respawn:/sbin/mingetty tty1" >> /etc/inittab
577 fi
578
579 #### SECURITY PROFILE HANDLING (Post Installation) ####
580 # Check if the Security profile mode is enabled
581 # and load the appropriate kernel modules
582 secprofile=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended`
583 if [ -n "$secprofile" ]; then
584    echo "In Extended Security profile mode. Loading IMA kernel module"
585    systemctl enable auditd.service
586    # Add the securityfs mount for the IMA Runtime measurement list
587    echo "securityfs     /sys/kernel/security    securityfs    defaults,nodev 0 0" >> /etc/fstab
588 else
589    # Disable audit daemon in the Standard Security Profile
590    systemctl disable auditd
591 fi
592
593 . /etc/platform/platform.conf
594 # Configure smart package manager channels
595 rm -rf /var/lib/smart
596 mkdir /var/lib/smart
597 /usr/bin/smart channel -y \
598     --add rpmdb type=rpm-sys name="RPM Database"
599 /usr/bin/smart channel -y \
600     --add base type=rpm-md name="Base" baseurl=http://controller:${http_port:-8080}/feed/rel-19.12
601 /usr/bin/smart channel -y \
602     --add updates type=rpm-md name="Patches" baseurl=http://controller:${http_port:-8080}/updates/rel-19.12
603
604 # Configure smart to use rpm --nolinktos option
605 /usr/bin/smart config --set rpm-nolinktos=true
606
607 # Configure smart to use rpm --nosignature option
608 /usr/bin/smart config --set rpm-check-signatures=false
609
610 # Delete the CentOS yum repo files
611 rm -f /etc/yum.repos.d/CentOS-*
612
613 # Persist the boot device naming as UDEV rules so that if the network device
614 # order changes post-install that we will still be able to DHCP from the
615 # correct interface to reach the active controller.  For most nodes only the
616 # management/boot interface needs to be persisted but because we require both
617 # controllers to be identically configured and controller-0 and controller-1
618 # are installed differently (e.g., controller-0 from USB and controller-1 from
619 # network) it is not possible to know which interface to persist for
620 # controller-0.  The simplest solution is to persist all interfaces.
621 #
622 mkdir -p /etc/udev/rules.d
623 echo "# Persisted network interfaces from anaconda installer" > /etc/udev/rules.d/70-persistent-net.rules
624 for dir in /sys/class/net/*; do
625     if [ -e ${dir}/device ]; then
626        dev=$(basename ${dir})
627        mac_address=$(cat /sys/class/net/${dev}/address)
628        echo "ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{address}==\"${mac_address}\", NAME=\"${dev}\"" >> /etc/udev/rules.d/70-persistent-net.rules
629     fi
630 done
631
632 # Mark the sysadmin password as expired immediately
633 chage -d 0 sysadmin
634
635 # Lock the root password
636 passwd -l root
637
638 # Enable tmpfs mount for /tmp
639 # delete /var/tmp so that it can similinked in
640 rm -rf /var/tmp
641 systemctl enable tmp.mount
642
643 # Disable automount of /dev/hugepages
644 systemctl mask dev-hugepages.mount
645
646 # Disable firewall
647 systemctl disable firewalld
648
649 # Disable libvirtd
650 systemctl disable libvirtd.service
651
652 # Enable rsyncd
653 systemctl enable rsyncd.service
654
655 # Allow root to run sudo from a non-tty (for scripts running as root that run sudo cmds)
656 echo 'Defaults:root !requiretty' > /etc/sudoers.d/root
657
658 # Make fstab just root read/writable
659 chmod 600 /etc/fstab
660
661 # Create first_boot flag
662 touch /etc/platform/.first_boot
663
664 %end
665
666 # Template from: post_kernel_aio_and_worker.cfg
667 %post --erroronfail
668
669 # Source common functions
670 . /tmp/ks-functions.sh
671
672 # Source the generated platform.conf
673 . /etc/platform/platform.conf
674
675 # Update grub with custom kernel bootargs
676 source /etc/init.d/cpumap_functions.sh
677 n_cpus=$(cat /proc/cpuinfo 2>/dev/null | \
678   awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}')
679 n_numa=$(ls -d /sys/devices/system/node/node* 2>/dev/null | wc -l)
680 KERN_OPTS=" iommu=pt usbcore.autosuspend=-1"
681
682 KERN_OPTS="${KERN_OPTS} hugepagesz=2M hugepages=0 default_hugepagesz=2M"
683
684 # If this is an all-in-one system, we need at least 4 CPUs
685 if [ "$system_type" = "All-in-one" -a ${n_cpus} -lt 4 ]; then
686     report_post_failure_with_msg "ERROR: At least 4 CPUs are required for controller+worker node."
687 fi
688
689 # Add kernel options for cpu isolation / affinity
690 if [ ${n_cpus} -gt 1 ]
691 then
692   base_cpulist=$(platform_expanded_cpu_list)
693   base_cpumap=$(cpulist_to_cpumap ${base_cpulist} ${n_cpus})
694   avp_cpulist=$(vswitch_expanded_cpu_list)
695   norcu_cpumap=$(invert_cpumap ${base_cpumap} ${n_cpus})
696   norcu_cpulist=$(cpumap_to_cpulist ${norcu_cpumap} ${n_cpus})
697
698   if [[ "$subfunction" =~ lowlatency ]]; then
699     KERN_OPTS="${KERN_OPTS} isolcpus=${norcu_cpulist}"
700     KERN_OPTS="${KERN_OPTS} nohz_full=${norcu_cpulist}"
701   else
702     KERN_OPTS="${KERN_OPTS} isolcpus=${avp_cpulist}"
703   fi
704   KERN_OPTS="${KERN_OPTS} rcu_nocbs=${norcu_cpulist}"
705   KERN_OPTS="${KERN_OPTS} kthread_cpus=${base_cpulist}"
706   KERN_OPTS="${KERN_OPTS} irqaffinity=${base_cpulist}"
707   # Update vswitch.conf
708   sed -i "s/^VSWITCH_CPU_LIST=.*/VSWITCH_CPU_LIST=\"${avp_cpulist}\"/" /etc/vswitch/vswitch.conf
709 fi
710
711 # Add kernel options to ensure an selinux is disabled
712 KERN_OPTS="${KERN_OPTS} selinux=0 enforcing=0"
713
714 # Add kernel options to set NMI watchdog
715 if [[ "$subfunction" =~ lowlatency ]]; then
716   KERN_OPTS="${KERN_OPTS} nmi_watchdog=0 softlockup_panic=0"
717 else
718   KERN_OPTS="${KERN_OPTS} nmi_watchdog=panic,1 softlockup_panic=1"
719 fi
720
721 if [[ "$(dmidecode -s system-product-name)" =~ ^ProLiant.*Gen8$ ]]; then
722   KERN_OPTS="${KERN_OPTS} intel_iommu=on,eth_no_rmrr"
723 else
724   KERN_OPTS="${KERN_OPTS} intel_iommu=on"
725 fi
726
727 # Add kernel option to disable biosdevname if enabled
728 # As this may already be in GRUB_CMDLINE_LINUX, only add if it is not already present
729 grep -q '^GRUB_CMDLINE_LINUX=.*biosdevname=0' /etc/default/grub
730 if [ $? -ne 0 ]; then
731   KERN_OPTS="${KERN_OPTS} biosdevname=0"
732 fi
733
734 # Add kernel options to disable kvm-intel.eptad on Broadwell
735 # Broadwell: Model: 79, Model name: Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
736 if grep -q -E "^model\s+:\s+79$" /proc/cpuinfo
737 then
738   KERN_OPTS="${KERN_OPTS} kvm-intel.eptad=0"
739 fi
740
741 # k8s updates:
742 #KERN_OPTS="${KERN_OPTS} cgroup_disable=memory"
743 KERN_OPTS="${KERN_OPTS} user_namespace.enable=1"
744
745 # Add kernel option to avoid jiffies_lock contention on real-time kernel
746 if [[ "$subfunction" =~ lowlatency ]]; then
747   KERN_OPTS="${KERN_OPTS} skew_tick=1"
748 fi
749
750 # If the installer asked us to use security related kernel params, use
751 # them in the grub line as well (until they can be configured via puppet)
752 grep -q 'nopti' /proc/cmdline
753 if [ $? -eq 0 ]; then
754     KERN_OPTS="${KERN_OPTS} nopti"
755 fi
756 grep -q 'nospectre_v2' /proc/cmdline
757 if [ $? -eq 0 ]; then
758     KERN_OPTS="${KERN_OPTS} nospectre_v2"
759 fi
760
761 perl -pi -e 's/(GRUB_CMDLINE_LINUX=.*)\"/\1'"$KERN_OPTS"'\"/g' /etc/default/grub
762
763 if [ -d /sys/firmware/efi ] ; then
764   grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
765 else
766   grub2-mkconfig -o /boot/grub2/grub.cfg
767 fi
768
769 %end
770
771
772 # Template from: post_lvm_pv_on_rootfs.cfg
773 %post --erroronfail
774
775 # Source common functions
776 . /tmp/ks-functions.sh
777
778 # uncomment the global_filter line in lvm.conf
779 perl -0777 -i.bak -pe 's:(# This configuration option has an automatic default value\.\n)\t# global_filter:$1        global_filter:m' /etc/lvm/lvm.conf
780
781 # Determine which disk we created our PV on (i.e. the root disk)
782 ROOTDISK=$(get_by_path $(pvdisplay --select 'vg_name=cgts-vg' -C -o pv_name --noheadings))
783 if [ -z "$ROOTDISK" ]; then
784     report_post_failure_with_msg "ERROR: failed to identify rootdisk via pvdisplay"
785 fi
786 # Edit the LVM config so LVM only looks for LVs on the root disk
787 sed -i "s#^\( *\)global_filter = \[.*#\1global_filter = [ \"a|${ROOTDISK}|\", \"r|.*|\" ]#" /etc/lvm/lvm.conf
788 %end
789
790
791 # Template from: post_net_common.cfg
792 %pre --erroronfail
793
794 # Source common functions
795 . /tmp/ks-functions.sh
796
797 http_port=$(get_http_port)
798 echo "repo --name=base --baseurl=http://pxecontroller:${http_port:-8080}/feed/rel-19.12/" > /tmp/repo-include
799 echo "repo --name=updates --baseurl=http://pxecontroller:${http_port:-8080}/updates/rel-19.12/" > /tmp/repo-include
800
801 %end
802
803 # Repository arguments from %pre
804 %include /tmp/repo-include
805
806
807 %post --erroronfail
808
809 # Source common functions
810 . /tmp/ks-functions.sh
811
812 # Persist the http port to the platform configuration
813 echo http_port=$(get_http_port) >> /etc/platform/platform.conf
814
815 # Obtain the boot interface from the PXE boot
816 BOOTIF=`cat /proc/cmdline |xargs -n1 echo |grep BOOTIF=`
817 if [ -d /sys/firmware/efi ] ; then
818     BOOTIF=${BOOTIF#BOOTIF=}
819 else
820     BOOTIF=${BOOTIF#BOOTIF=01-}
821     BOOTIF=${BOOTIF//-/:}
822 fi
823
824 mgmt_dev=none
825 mgmt_vlan=0
826 if [ -n "$BOOTIF" ] ; then
827     ndev=`ip link show |grep -B 1 $BOOTIF |head -1 |awk '{print $2}' |sed -e 's/://'`
828     if [ -n "$ndev" ] ; then
829         mgmt_dev=$ndev
830         # Retrieve the management VLAN from sysinv if it exists
831         mgmt_vlan=`curl -sf http://pxecontroller:6385/v1/isystems/mgmtvlan`
832         if [ $? -ne 0 ]
833         then
834           report_post_failure_with_msg "ERROR: Unable to communicate with System Inventory REST API. Aborting installation."
835         fi
836     else
837         report_post_failure_with_msg "ERROR: Unable to determine mgmt interface from BOOTIF=$BOOTIF."
838     fi
839 else
840     report_post_failure_with_msg "ERROR: BOOTIF is not set. Unable to determine mgmt interface."
841 fi
842
843 if [ $mgmt_vlan -eq 0 ] ; then
844
845     # Persist the boot device to the platform configuration. This will get
846     # overwritten later if the management_interface is on a bonded interface.
847     echo management_interface=$mgmt_dev >> /etc/platform/platform.conf
848
849     # Build networking scripts
850     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
851 DEVICE=lo
852 IPADDR=127.0.0.1
853 NETMASK=255.0.0.0
854 NETWORK=127.0.0.0
855 BROADCAST=127.255.255.255
856 ONBOOT=yes
857 IPV6_AUTOCONF=no
858 NAME=loopback
859 EOF
860
861     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$mgmt_dev
862 DEVICE=$mgmt_dev
863 BOOTPROTO=dhcp
864 ONBOOT=yes
865 IPV6_AUTOCONF=no
866 LINKDELAY=20
867 EOF
868
869 else
870
871     # Check whether to use inet or inet6
872     ipv6_addr=$(dig +short AAAA controller)
873     if [[ -n "$ipv6_addr" ]]
874     then
875         mgmt_address_family=inet6
876         ipv6init=yes
877         dhcpv6c=yes
878         dhclientargs=-1
879     else
880         mgmt_address_family=inet
881         ipv6init=no
882         dhcpv6c=no
883         dhclientargs=
884     fi
885
886     # Persist the boot device to the platform configuration. This will get
887     # overwritten later if the management_interface is on a bonded interface.
888     echo management_interface=vlan$mgmt_vlan >> /etc/platform/platform.conf
889
890     # Build networking scripts
891     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
892 DEVICE=lo
893 IPADDR=127.0.0.1
894 NETMASK=255.0.0.0
895 NETWORK=127.0.0.0
896 BROADCAST=127.255.255.255
897 ONBOOT=yes
898 IPV6_AUTOCONF=no
899 NAME=loopback
900 EOF
901
902     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$mgmt_dev
903 DEVICE=$mgmt_dev
904 BOOTPROTO=none
905 ONBOOT=yes
906 IPV6_AUTOCONF=no
907 LINKDELAY=20
908 EOF
909
910     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-vlan$mgmt_vlan
911 DEVICE=vlan$mgmt_vlan
912 BOOTPROTO=dhcp
913 DHCLIENTARGS=$dhclientargs
914 IPV6INIT=$ipv6init
915 DHCPV6C=$dhcpv6c
916 ONBOOT=yes
917 IPV6_AUTOCONF=no
918 PHYSDEV=$mgmt_dev
919 VLAN=yes
920 LINKDELAY=20
921 EOF
922
923     # Reject DHCPOFFER from DHCP server that doesn't send
924     # wrs-install-uuid option
925     echo "require wrs-install-uuid;" >>/etc/dhcp/dhclient.conf
926     echo "require dhcp6.wrs-install-uuid;" >>/etc/dhcp/dhclient.conf
927
928     # Bring up the mgmt vlan so that a dhcp lease is acquired and an address is
929     # setup prior to the post-install reboot.  This is so that the timing of the IP
930     # address allocation is similar to how normal/non-pxe installation works.
931     mgmt_iface=vlan$mgmt_vlan
932     dhclient_family=$([[ $mgmt_address_family == "inet" ]] && echo -4 || echo -6)
933     ip link add link $mgmt_dev name $mgmt_iface type vlan id $mgmt_vlan
934     ip link set up dev $mgmt_iface
935     dhclient $dhclient_family $mgmt_iface || true
936
937 fi
938
939 %end