stx-metal: add kickstart fixes for poky-stx
[pti/rtp.git] / meta-stx / conf / distro / files / ks / net_smallsystem_lowlatency_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_lowlatency.cfg
258 %packages
259 @core
260 @base
261 -kernel-module-igb-uio
262 -kernel-module-wrs-avp
263 -kernel
264 -kernel-tools
265 -kernel-tools-libs
266 -kmod-drbd
267 -kmod-e1000e
268 -kmod-i40e
269 -kmod-ixgbe
270 -kmod-tpm
271 -mlnx-ofa_kernel
272 -mlnx-ofa_kernel-rt
273 -mlnx-ofa_kernel-modules
274 -qat16
275 @platform-controller-worker-lowlatency
276 @updates-controller-worker-lowlatency
277 %end
278
279
280 # Template from: pre_disk_setup_common.cfg
281 %pre --erroronfail
282
283 # Source common functions
284 . /tmp/ks-functions.sh
285
286 # This is a really fancy way of finding the first usable disk for the
287 # install and not stomping on the USB device if it comes up first
288
289 # First, parse /proc/cmdline to find the boot args
290 set -- `cat /proc/cmdline`
291 for I in $*; do case "$I" in *=*) eval $I 2>/dev/null;; esac; done
292
293 # Find either the ISO or USB device first chopping off partition
294 ISO_DEV=`readlink /dev/disk/by-label/oe_iso_boot`
295 sdev=`echo $ISO_DEV | sed -e 's/.$//'`
296 if [ -e /dev/disk/by-label/$sdev ] ; then
297     ISO_DEV=$sdev
298 fi
299 USB_DEV=`readlink /dev/disk/by-label/wr_usb_boot`
300 sdev=`echo $USB_DEV | sed -e 's/.$//'`
301 if [ -e /dev/disk/by-label/$sdev ] ; then
302     USB_DEV=$sdev
303 fi
304
305 # Temporary, until lab pxelinux.cfg files are updated to specify install devices
306 if [ -z "$rootfs_device" -o -z "$boot_device" ]
307 then
308     INST_HDD=""
309     # Prefer a vd* device if this is kvm/qemu
310     for e in vda vdb sda sdb nvme0n1; do
311         if [ -e /dev/$e -a "$ISO_DEV" != "../../$e" -a "$USB_DEV" != "../../$e" ] ; then
312             INST_HDD=$e
313             break
314         fi
315     done
316
317     # Set variables to $INST_HDD if not set
318     rootfs_device=${rootfs_device:-$INST_HDD}
319     boot_device=${boot_device:-$INST_HDD}
320 fi
321
322 # Convert to by-path
323 orig_rootfs_device=$rootfs_device
324 rootfs_device=$(get_by_path $rootfs_device)
325
326 orig_boot_device=$boot_device
327 boot_device=$(get_by_path $boot_device)
328
329 if [ ! -e "$rootfs_device" -o ! -e "$boot_device" ] ; then
330     # Touch this file to prevent Anaconda from dying an ungraceful death
331     touch /tmp/part-include
332
333     report_pre_failure_with_msg "ERROR: Specified installation ($orig_rootfs_device) or boot ($orig_boot_device) device is invalid."
334 fi
335
336 # Ensure specified device is not a USB drive
337 udevadm info --query=property --name=$rootfs_device |grep -q '^ID_BUS=usb' || \
338     udevadm info --query=property --name=$boot_device |grep -q '^ID_BUS=usb'
339 if [ $? -eq 0 ]; then
340     # Touch this file to prevent Anaconda from dying an ungraceful death
341     touch /tmp/part-include
342
343     report_pre_failure_with_msg "ERROR: Specified installation ($orig_rootfs_device) or boot ($orig_boot_device) device is a USB drive."
344 fi
345
346 # Deactivate existing volume groups to avoid Anaconda issues with pre-existing groups
347 vgs --noheadings -o vg_name | xargs --no-run-if-empty -n 1 vgchange -an
348
349 # Remove volumes and group for cgts-vg, if any
350 lvremove --force cgts-vg
351 pvs --select 'vg_name=cgts-vg' --noheadings -o pv_name | xargs --no-run-if-empty pvremove --force --force --yes
352 vgs --select 'vg_name=cgts-vg' --noheadings -o vg_name | xargs --no-run-if-empty vgremove --force
353
354 ONLYUSE_HDD=""
355 if [ "$(curl -sf http://pxecontroller:6385/v1/upgrade/$(hostname)/in_upgrade 2>/dev/null)" = "true" ]; then
356     # In an upgrade, only wipe the disk with the rootfs and boot partition
357     echo "In upgrade, wiping only $rootfs_device"
358     WIPE_HDD="$(get_disk $rootfs_device)"
359     ONLYUSE_HDD="$(basename $(get_disk $rootfs_device))"
360     if [ "$(get_disk $rootfs_device)" != "$(get_disk $boot_device)" ]; then
361         WIPE_HDD="$WIPE_HDD,$(get_disk $boot_device)"
362         ONLYUSE_HDD="$ONLYUSE_HDD,$(basename $(get_disk $boot_device))"
363     fi
364 else
365     # Make a list of all the hard drives that are to be wiped
366     WIPE_HDD=""
367     # Partition type OSD has a unique globally identifier
368     part_type_guid_str="Partition GUID code"
369     CEPH_OSD_GUID="4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D"
370
371     # Check if we wipe OSDs
372     if [ "$(curl -sf http://pxecontroller:6385/v1/ihosts/wipe_osds 2>/dev/null)" = "true" ]; then
373         echo "Wipe OSD data."
374         WIPE_CEPH_OSDS="true"
375     else
376         echo "Skip Ceph OSD data wipe."
377         WIPE_CEPH_OSDS="false"
378     fi
379
380     for f in /dev/disk/by-path/*
381     do
382         dev=$(readlink -f $f)
383         lsblk --nodeps --pairs $dev | grep -q 'TYPE="disk"'
384         if [ $? -ne 0 ]
385         then
386             continue
387         fi
388
389         # Avoid wiping USB drives
390         udevadm info --query=property --name=$dev |grep -q '^ID_BUS=usb' && continue
391
392         # Avoid wiping ceph osds if sysinv tells us so
393         if [ ${WIPE_CEPH_OSDS} == "false" ]; then
394             wipe_dev="true"
395             part_numbers=( `parted -s $dev print | awk '$1 == "Number" {i=1; next}; i {print $1}'` )
396             # Scanning the partitions looking for CEPH OSDs and
397             # skipping any disk found with such partitions
398             for part_number in "${part_numbers[@]}"; do
399                 sgdisk_part_info=$(flock $dev sgdisk -i $part_number $dev)
400                 part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}')
401                 if [ "$part_type_guid" == $CEPH_OSD_GUID ]; then
402                     echo "OSD found on $dev, skipping wipe"
403                     wipe_dev="false"
404                     break
405                 fi
406             done
407             if [ "$wipe_dev" == "false" ]; then
408                 continue
409             fi
410         fi
411
412         # Add device to the wipe list
413         devname=$(basename $dev)
414         if [ -e $dev -a "$ISO_DEV" != "../../$devname" -a "$USB_DEV" != "../../$devname" ]; then
415             if [ -n "$WIPE_HDD" ]; then
416                 WIPE_HDD=$WIPE_HDD,$dev
417             else
418                 WIPE_HDD=$dev
419             fi
420         fi
421     done
422     echo "Not in upgrade, wiping disks: $WIPE_HDD"
423 fi
424
425 for dev in ${WIPE_HDD//,/ }
426 do
427     # Clearing previous GPT tables or LVM data
428     # Delete the first few bytes at the start and end of the partition. This is required with
429     # GPT partitions, they save partition info at the start and the end of the block.
430     # Do this for each partition on the disk, as well.
431     partitions=$(lsblk -rip $dev -o TYPE,NAME |awk '$1 == "part" {print $2}')
432     for p in $partitions $dev
433     do
434         echo "Pre-wiping $p from kickstart"
435         dd if=/dev/zero of=$p bs=512 count=34
436         dd if=/dev/zero of=$p bs=512 count=34 seek=$((`blockdev --getsz $p` - 34))
437     done
438 done
439
440 # Check for remaining cgts-vg PVs, which could potentially happen
441 # in an upgrade where we're not wiping all disks.
442 # If we ever create other volume groups from kickstart in the future,
443 # include them in this search as well.
444 partitions=$(pvs --select 'vg_name=cgts-vg' -o pv_name --noheading | grep -v '\[unknown\]')
445 for p in $partitions
446 do
447     echo "Pre-wiping $p from kickstart (cgts-vg present)"
448     dd if=/dev/zero of=$p bs=512 count=34
449     dd if=/dev/zero of=$p bs=512 count=34 seek=$((`blockdev --getsz $p` - 34))
450 done
451
452 let -i gb=1024*1024*1024
453
454 cat<<EOF>/tmp/part-include
455 clearpart --all --drives=$WIPE_HDD --initlabel
456 EOF
457
458 if [ -n "$ONLYUSE_HDD" ]; then
459     cat<<EOF>>/tmp/part-include
460 ignoredisk --only-use=$ONLYUSE_HDD
461 EOF
462 fi
463
464 if [ -d /sys/firmware/efi ] ; then
465     cat<<EOF>>/tmp/part-include
466 part /boot/efi --fstype=efi --size=300 --ondrive=$(get_disk $boot_device)
467 EOF
468 else
469     cat<<EOF>>/tmp/part-include
470 part biosboot --asprimary --fstype=biosboot --size=1 --ondrive=$(get_disk $boot_device)
471 EOF
472 fi
473
474
475 # Template from: pre_disk_aio.cfg
476
477 ## NOTE: updates to partition sizes need to be also reflected in
478 ##  - stx-config/.../sysinv/conductor/manager.py:create_controller_filesystems()
479 ##  - stx-config/.../sysinv/common/constants.py
480 ##
481 ## NOTE: When adding partitions, we currently have a max of 4 primary partitions.
482 ##       If more than 4 partitions are required, we can use a max of 3 --asprimary,
483 ##       to allow 1 primary logical partition with extended partitions
484 ##
485 ## NOTE: Max default PV size must align with the default controllerfs sizes
486 ##
487 ## BACKUP_OVERHEAD = 20
488 ##
489 ## Physical install (for disks over 240GB)
490 ##  - DB size is doubled to allow for upgrades
491 ##
492 ## DEFAULT_IMAGE_STOR_SIZE = 10
493 ## DEFAULT_DATABASE_STOR_SIZE = 20
494 ## DEFAULT_IMG_CONVERSION_STOR_SIZE = 20
495 ## BACKUP = DEFAULT_DATABASE_STOR_SIZE + DEFAULT_IMAGE_STOR_SIZE
496 ##                                     + BACKUP_OVERHEAD = 50
497 ## LOG_VOL_SIZE = 8192
498 ## SCRATCH_VOL_SIZE = 8192
499 ## RABBIT = 2048
500 ## PLATFORM = 2048
501 ## ANCHOR = 1024
502 ## EXTENSION = 1024
503 ## GNOCCHI = 5120
504 ## DOCKER = 30720
505 ## DOCKER_DIST = 16384
506 ## ETCD = 5120
507 ## CEPH_MON = 20480
508 ## KUBELET_VOL_SIZE = 10240
509 ## RESERVED_PE = 16 (based on pesize=32768)
510 ##
511 ## CGCS_PV_SIZE = 10240 + 2*20480 + 20480 + 51200 + 8196 + 8196 + 2048 +
512 ##                2048 + 1024 + 1024 + 5120 + 30720 + 16384 + 5120 +
513 ##                20480 + 10240 + 16 = 233496
514 ##
515 ## small install - (for disks below 240GB)
516 ##  - DB size is doubled to allow for upgrades
517 ##
518 ## DEFAULT_SMALL_IMAGE_STOR_SIZE = 10
519 ## DEFAULT_SMALL_DATABASE_STOR_SIZE = 10
520 ## DEFAULT_SMALL_IMG_CONVERSION_STOR_SIZE = 10
521 ## DEFAULT_SMALL_BACKUP_STOR_SIZE = 40
522 ##
523 ## LOG_VOL_SIZE = 8192
524 ## SCRATCH_VOL_SIZE = 8192
525 ## RABBIT = 2048
526 ## PLATFORM = 2048
527 ## ANCHOR = 1024
528 ## EXTENSION = 1024
529 ## GNOCCHI = 5120
530 ## DOCKER = 30720
531 ## DOCKER_DIST = 16384
532 ## ETCD = 5120
533 ## CEPH_MON = 20480
534 ## KUBELET_VOL_SIZE = 10240
535 ## RESERVED_PE = 16 (based on pesize=32768)
536 ##
537 ##
538 ## CGCS_PV_SIZE = 10240 + 2*10240 + 10240 + 40960 + 8192 + 8192 + 2048 +
539 ##                2048 + 1024 + 1024 + 5120 + 30720 + 16384 + 5120 +
540 ##                20480 + 10240 + 16 = 192528
541 ##
542 ## NOTE: To maintain upgrade compatability within the volume group, keep the
543 ## undersized LOG_VOL_SIZE and SCRATCH_VOL_SIZE, but size the minimally size
544 ## physical volume correctly.
545 ##
546 ##  R4 AIO installations:
547 ##  - R4 (case #1): /boot (0.5G), / (20G),
548 ##                  cgts-vg PV (239G), /local_pv (239G)
549 ##  - R4 (case #2): /boot (0.5G), / (20G),
550 ##                  cgts-vg PV (239G), cgts-vg (239G)
551 ##
552 ##  Upgrade migration will start with R5 install and create a partition to align
553 ##  above so filesystems within the volume group will be able to maintain their
554 ##  sizes in R5
555 ##    - R5 install  : /boot (0.5G), / (20G),
556 ##                    cgts-vg PV (142G), un-partitioned (336G)
557 ##    - R5 (case #1): /boot (0.5G), / (20G),
558 ##                    cgts-vg PV (142G), cgts-vg PV (97G), unpartitioned (239G)
559 ##    - R5 (case #2): /boot (0.5G), / (20G),
560 ##                    cgts-vg PV (142G), cgts-vg PV (336G)
561 ##
562
563 sz=$(blockdev --getsize64 $(get_disk $rootfs_device))
564 if [ $sz -le $((240*$gb)) ] ; then
565     # Round CGCS_PV_SIZE to the closest upper value that can be divided by 1024.
566     # 192528/1024=188.01. CGCS_PV_SIZE=189*1024=193536. Using a disk with a
567     # size under 189GiB will fail.
568     CGCS_PV_SIZE=193536
569 else
570     # Round CGCS_PV_SIZE to the closest upper value that can be divided by 1024.
571     # 233496/1024=228.02. CGCS_PV_SIZE=229*1024=234496.
572     CGCS_PV_SIZE=234496
573 fi
574
575 ROOTFS_SIZE=20000
576 LOG_VOL_SIZE=8000
577 SCRATCH_VOL_SIZE=8000
578
579 ROOTFS_OPTIONS="defaults"
580 profile_mode=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended`
581 if [ -n "$profile_mode" ]; then
582    # Enable iversion labelling for rootfs when IMA is enabled
583    ROOTFS_OPTIONS="${ROOTFS_OPTIONS},iversion"
584 fi
585
586 cat<<EOF>>/tmp/part-include
587 part /boot --fstype=ext4 --asprimary --size=500 --ondrive=$(get_disk $rootfs_device) --fsoptions="$ROOTFS_OPTIONS"
588 part pv.253004 --grow --size=500 --maxsize=$CGCS_PV_SIZE --ondrive=$(get_disk $rootfs_device)
589 volgroup cgts-vg --pesize=32768 pv.253004
590 logvol /var/log --fstype=ext4 --vgname=cgts-vg --size=$LOG_VOL_SIZE --name=log-lv
591 logvol /scratch --fstype=ext4 --vgname=cgts-vg --size=$SCRATCH_VOL_SIZE --name=scratch-lv
592 part / --fstype=ext4 --asprimary --size=$ROOTFS_SIZE --ondrive=$(get_disk $rootfs_device) --fsoptions="$ROOTFS_OPTIONS"
593 EOF
594
595 %end
596
597
598 # Template from: post_platform_conf_aio_lowlatency.cfg
599 %post --erroronfail
600
601 # Source common functions
602 . /tmp/ks-functions.sh
603
604 # Set the security profile mode
605 secprofile="standard"
606 profile_mode=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended`
607 if [ -n "$profile_mode" ]; then
608    secprofile="extended"
609 fi
610
611 mkdir -p -m 0775 /etc/platform
612 cat <<EOF > /etc/platform/platform.conf
613 nodetype=controller
614 subfunction=controller,worker,lowlatency
615 system_type=All-in-one
616 security_profile=$secprofile
617 EOF
618
619 %end
620
621
622 # Template from: post_common.cfg
623 %post --erroronfail
624
625 # Source common functions
626 . /tmp/ks-functions.sh
627
628 # Turn off locale support for i18n if is not installed
629 if [ ! -d /usr/share/i18n ] ; then
630    rm -f /etc/sysconfig/i18n
631 fi
632 # Unset the hostname
633 rm /etc/hostname
634
635 # If using a serial install make sure to add a getty on the tty1
636 conarg=`cat /proc/cmdline |xargs -n1 echo |grep console= |grep ttyS`
637 if [ -n "$conarg" ] ; then
638    echo "1:2345:respawn:/sbin/mingetty tty1" >> /etc/inittab
639 fi
640
641 #### SECURITY PROFILE HANDLING (Post Installation) ####
642 # Check if the Security profile mode is enabled
643 # and load the appropriate kernel modules
644 secprofile=`cat /proc/cmdline |xargs -n1 echo |grep security_profile= | grep extended`
645 if [ -n "$secprofile" ]; then
646    echo "In Extended Security profile mode. Loading IMA kernel module"
647    systemctl enable auditd.service
648    # Add the securityfs mount for the IMA Runtime measurement list
649    echo "securityfs     /sys/kernel/security    securityfs    defaults,nodev 0 0" >> /etc/fstab
650 else
651    # Disable audit daemon in the Standard Security Profile
652    systemctl disable auditd
653 fi
654
655 . /etc/platform/platform.conf
656 # Configure smart package manager channels
657 rm -rf /var/lib/smart
658 mkdir /var/lib/smart
659 /usr/bin/smart channel -y \
660     --add rpmdb type=rpm-sys name="RPM Database"
661 /usr/bin/smart channel -y \
662     --add base type=rpm-md name="Base" baseurl=http://controller:${http_port:-8080}/feed/rel-19.12
663 /usr/bin/smart channel -y \
664     --add updates type=rpm-md name="Patches" baseurl=http://controller:${http_port:-8080}/updates/rel-19.12
665
666 # Configure smart to use rpm --nolinktos option
667 /usr/bin/smart config --set rpm-nolinktos=true
668
669 # Configure smart to use rpm --nosignature option
670 /usr/bin/smart config --set rpm-check-signatures=false
671
672 # Delete the CentOS yum repo files
673 rm -f /etc/yum.repos.d/CentOS-*
674
675 # Persist the boot device naming as UDEV rules so that if the network device
676 # order changes post-install that we will still be able to DHCP from the
677 # correct interface to reach the active controller.  For most nodes only the
678 # management/boot interface needs to be persisted but because we require both
679 # controllers to be identically configured and controller-0 and controller-1
680 # are installed differently (e.g., controller-0 from USB and controller-1 from
681 # network) it is not possible to know which interface to persist for
682 # controller-0.  The simplest solution is to persist all interfaces.
683 #
684 mkdir -p /etc/udev/rules.d
685 echo "# Persisted network interfaces from anaconda installer" > /etc/udev/rules.d/70-persistent-net.rules
686 for dir in /sys/class/net/*; do
687     if [ -e ${dir}/device ]; then
688        dev=$(basename ${dir})
689        mac_address=$(cat /sys/class/net/${dev}/address)
690        echo "ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{address}==\"${mac_address}\", NAME=\"${dev}\"" >> /etc/udev/rules.d/70-persistent-net.rules
691     fi
692 done
693
694 # Mark the sysadmin password as expired immediately
695 chage -d 0 sysadmin
696
697 # Lock the root password
698 passwd -l root
699
700 # Enable tmpfs mount for /tmp
701 # delete /var/tmp so that it can similinked in
702 rm -rf /var/tmp
703 systemctl enable tmp.mount
704
705 # Disable automount of /dev/hugepages
706 systemctl mask dev-hugepages.mount
707
708 # Disable firewall
709 systemctl disable firewalld
710
711 # Disable libvirtd
712 systemctl disable libvirtd.service
713
714 # Enable rsyncd
715 systemctl enable rsyncd.service
716
717 # Allow root to run sudo from a non-tty (for scripts running as root that run sudo cmds)
718 echo 'Defaults:root !requiretty' > /etc/sudoers.d/root
719
720 # Make fstab just root read/writable
721 chmod 600 /etc/fstab
722
723 # Create first_boot flag
724 touch /etc/platform/.first_boot
725
726 %end
727
728 # Template from: post_kernel_aio_and_worker.cfg
729 %post --erroronfail
730
731 # Source common functions
732 . /tmp/ks-functions.sh
733
734 # Source the generated platform.conf
735 . /etc/platform/platform.conf
736
737 # Update grub with custom kernel bootargs
738 source /etc/init.d/cpumap_functions.sh
739 n_cpus=$(cat /proc/cpuinfo 2>/dev/null | \
740   awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}')
741 n_numa=$(ls -d /sys/devices/system/node/node* 2>/dev/null | wc -l)
742 KERN_OPTS=" iommu=pt usbcore.autosuspend=-1"
743
744 KERN_OPTS="${KERN_OPTS} hugepagesz=2M hugepages=0 default_hugepagesz=2M"
745
746 # If this is an all-in-one system, we need at least 4 CPUs
747 if [ "$system_type" = "All-in-one" -a ${n_cpus} -lt 4 ]; then
748     report_post_failure_with_msg "ERROR: At least 4 CPUs are required for controller+worker node."
749 fi
750
751 # Add kernel options for cpu isolation / affinity
752 if [ ${n_cpus} -gt 1 ]
753 then
754   base_cpulist=$(platform_expanded_cpu_list)
755   base_cpumap=$(cpulist_to_cpumap ${base_cpulist} ${n_cpus})
756   avp_cpulist=$(vswitch_expanded_cpu_list)
757   norcu_cpumap=$(invert_cpumap ${base_cpumap} ${n_cpus})
758   norcu_cpulist=$(cpumap_to_cpulist ${norcu_cpumap} ${n_cpus})
759
760   if [[ "$subfunction" =~ lowlatency ]]; then
761     KERN_OPTS="${KERN_OPTS} isolcpus=${norcu_cpulist}"
762     KERN_OPTS="${KERN_OPTS} nohz_full=${norcu_cpulist}"
763   else
764     KERN_OPTS="${KERN_OPTS} isolcpus=${avp_cpulist}"
765   fi
766   KERN_OPTS="${KERN_OPTS} rcu_nocbs=${norcu_cpulist}"
767   KERN_OPTS="${KERN_OPTS} kthread_cpus=${base_cpulist}"
768   KERN_OPTS="${KERN_OPTS} irqaffinity=${base_cpulist}"
769   # Update vswitch.conf
770   sed -i "s/^VSWITCH_CPU_LIST=.*/VSWITCH_CPU_LIST=\"${avp_cpulist}\"/" /etc/vswitch/vswitch.conf
771 fi
772
773 # Add kernel options to ensure an selinux is disabled
774 KERN_OPTS="${KERN_OPTS} selinux=0 enforcing=0"
775
776 # Add kernel options to set NMI watchdog
777 if [[ "$subfunction" =~ lowlatency ]]; then
778   KERN_OPTS="${KERN_OPTS} nmi_watchdog=0 softlockup_panic=0"
779 else
780   KERN_OPTS="${KERN_OPTS} nmi_watchdog=panic,1 softlockup_panic=1"
781 fi
782
783 if [[ "$(dmidecode -s system-product-name)" =~ ^ProLiant.*Gen8$ ]]; then
784   KERN_OPTS="${KERN_OPTS} intel_iommu=on,eth_no_rmrr"
785 else
786   KERN_OPTS="${KERN_OPTS} intel_iommu=on"
787 fi
788
789 # Add kernel option to disable biosdevname if enabled
790 # As this may already be in GRUB_CMDLINE_LINUX, only add if it is not already present
791 grep -q '^GRUB_CMDLINE_LINUX=.*biosdevname=0' /etc/default/grub
792 if [ $? -ne 0 ]; then
793   KERN_OPTS="${KERN_OPTS} biosdevname=0"
794 fi
795
796 # Add kernel options to disable kvm-intel.eptad on Broadwell
797 # Broadwell: Model: 79, Model name: Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
798 if grep -q -E "^model\s+:\s+79$" /proc/cpuinfo
799 then
800   KERN_OPTS="${KERN_OPTS} kvm-intel.eptad=0"
801 fi
802
803 # k8s updates:
804 #KERN_OPTS="${KERN_OPTS} cgroup_disable=memory"
805 KERN_OPTS="${KERN_OPTS} user_namespace.enable=1"
806
807 # Add kernel option to avoid jiffies_lock contention on real-time kernel
808 if [[ "$subfunction" =~ lowlatency ]]; then
809   KERN_OPTS="${KERN_OPTS} skew_tick=1"
810 fi
811
812 # If the installer asked us to use security related kernel params, use
813 # them in the grub line as well (until they can be configured via puppet)
814 grep -q 'nopti' /proc/cmdline
815 if [ $? -eq 0 ]; then
816     KERN_OPTS="${KERN_OPTS} nopti"
817 fi
818 grep -q 'nospectre_v2' /proc/cmdline
819 if [ $? -eq 0 ]; then
820     KERN_OPTS="${KERN_OPTS} nospectre_v2"
821 fi
822
823 perl -pi -e 's/(GRUB_CMDLINE_LINUX=.*)\"/\1'"$KERN_OPTS"'\"/g' /etc/default/grub
824
825 if [ -d /sys/firmware/efi ] ; then
826   grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
827 else
828   grub2-mkconfig -o /boot/grub2/grub.cfg
829 fi
830
831 %end
832
833
834 # Template from: post_lvm_pv_on_rootfs.cfg
835 %post --erroronfail
836
837 # Source common functions
838 . /tmp/ks-functions.sh
839
840 # uncomment the global_filter line in lvm.conf
841 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
842
843 # Determine which disk we created our PV on (i.e. the root disk)
844 ROOTDISK=$(get_by_path $(pvdisplay --select 'vg_name=cgts-vg' -C -o pv_name --noheadings))
845 if [ -z "$ROOTDISK" ]; then
846     report_post_failure_with_msg "ERROR: failed to identify rootdisk via pvdisplay"
847 fi
848 # Edit the LVM config so LVM only looks for LVs on the root disk
849 sed -i "s#^\( *\)global_filter = \[.*#\1global_filter = [ \"a|${ROOTDISK}|\", \"r|.*|\" ]#" /etc/lvm/lvm.conf
850 %end
851
852
853 # Template from: post_system_aio.cfg
854 %post --erroronfail
855
856 # Source common functions
857 . /tmp/ks-functions.sh
858
859 # Source the generated platform.conf
860 . /etc/platform/platform.conf
861
862 ## Reserve more memory for base processes since the controller has higher
863 ## memory requirements but cap it to better handle systems with large
864 ## amounts of memory
865 TOTALMEM=$(grep MemTotal /proc/meminfo | awk '{print int($2/1024)}')
866
867 if [ -e /sys/devices/system/node/node0 ]; then
868   RESERVEDMEM=$(grep MemTotal /sys/devices/system/node/node0/meminfo | awk '{printf "%d\n", $4/1024}')
869 else
870   RESERVEDMEM=$(grep MemTotal /proc/meminfo | awk '{print int($2/1024/4)}')
871 fi
872
873 if [ ${RESERVEDMEM} -lt 6144 ]; then
874     RESERVEDMEM=6144
875 elif [ ${RESERVEDMEM} -gt 14500 ]; then
876     RESERVEDMEM=14500
877 elif [ ${RESERVEDMEM} -gt 8192 ]; then
878     RESERVEDMEM=8192
879 fi
880
881 sed -i -e "s#\(WORKER_BASE_RESERVED\)=.*#\1=(\"node0:${RESERVEDMEM}MB:1\" \"node1:2000MB:0\" \"node2:2000MB:0\" \"node3:2000MB:0\")#g" /etc/platform/worker_reserved.conf
882
883 # Update WORKER_CPU_LIST
884 N_CPUS=$(cat /proc/cpuinfo 2>/dev/null | awk '/^[pP]rocessor/ { n +=1 } END { print (n>0) ? n : 1}')
885 sed -i "s/^WORKER_CPU_LIST=.*/WORKER_CPU_LIST=\"0-$((N_CPUS-1))\"/" /etc/platform/worker_reserved.conf
886
887 %end
888
889
890 # Template from: post_net_controller.cfg
891 %post --erroronfail
892
893 # Source common functions
894 . /tmp/ks-functions.sh
895
896 http_port=$(get_http_port)
897 # Retrieve the installation uuid from the controller we booted from
898 INSTALL_UUID=`curl -sf http://pxecontroller:${http_port:-8080}/feed/rel-19.12/install_uuid`
899 if [ $? -ne 0 ]
900 then
901   INSTALL_UUID=unknown
902 fi
903
904 grep -q INSTALL_UUID /etc/platform/platform.conf
905 if [ $? -ne 0 ]; then
906     echo "INSTALL_UUID=$INSTALL_UUID" >> /etc/platform/platform.conf
907 fi
908
909 cd /www/pages
910 # Sync software repository
911 feed_url=http://pxecontroller:${http_port:-8080}/feed/
912 anaconda_logdir=/var/log/anaconda
913 mkdir -p $anaconda_logdir
914
915 echo "Mirroring software repository (may take several minutes)..." >/dev/console
916 wget --recursive --no-parent --no-host-directories --no-clobber --reject 'index.html*' --reject '*.log' $feed_url/ -o $anaconda_logdir/wget-feed-mirror.log \
917     || report_post_failure_with_logfile $anaconda_logdir/wget-feed-mirror.log
918
919 # Sync patching repository
920 updates_url=http://pxecontroller:${http_port:-8080}/updates/
921 wget --mirror --no-parent --no-host-directories --reject 'index.html*' --reject '*.log' $updates_url/ -o $anaconda_logdir/wget-updates-mirror.log \
922     || report_post_failure_with_logfile $anaconda_logdir/wget-updates-mirror.log
923 echo "Done" >/dev/console
924
925 shopt -s nullglob
926
927 # Check whether a second release is installed
928 . /etc/build.info
929 CURRENT_REL_DIR=rel-${SW_VERSION}
930 OTHER_REL_DIR=
931 for REL_DIR in /www/pages/feed/*; do
932     if [[ ! $REL_DIR =~ "${SW_VERSION}" ]]; then
933         OTHER_REL_DIR=`basename $REL_DIR`
934         OTHER_REL_VERSION=${OTHER_REL_DIR:4}
935         break
936     fi
937 done
938
939 # If second release is installed, find the latest version of the installer
940 # RPM and install the pxeboot files we require to boot hosts with that release.
941 if [ ! -z "$OTHER_REL_DIR" ]; then
942     PATCH_RPM=`find /www/pages/updates/${OTHER_REL_DIR}/Packages -name 'pxe-network-installer*' | sort -V | tail -1`
943     BASE_RPM=`find /www/pages/feed/${OTHER_REL_DIR}/Packages -name 'pxe-network-installer*' | sort -V | tail -1`
944
945     if [ ! -z "$PATCH_RPM" ]; then
946         INSTALL_RPM=$PATCH_RPM
947     elif [ ! -z "$BASE_RPM" ]; then
948         INSTALL_RPM=$BASE_RPM
949     else
950         report_post_failure_with_msg "ERROR: Unable to find pxe-network-installer RPM for $OTHER_REL_DIR. Aborting installation."
951     fi
952
953     echo "Installing pxeboot files for release $OTHER_REL_DIR from $INSTALL_RPM" >/dev/console
954     TMP_RPM=/tmp/pxe-network-installer
955     mkdir $TMP_RPM
956     pushd $TMP_RPM
957     /usr/bin/rpm2cpio $INSTALL_RPM | cpio -idm \
958         || report_post_failure_with_msg "Failed to extract pxe-network-installer"
959
960     cp -r $TMP_RPM/usr / \
961         || report_post_failure_with_msg "Failed to copy pxe-network-installer /usr"
962     cp -r $TMP_RPM/pxeboot/$OTHER_REL_DIR /pxeboot/ \
963         || report_post_failure_with_msg "Failed to copy pxe-network-installer /pxeboot/$OTHER_REL_DIR"
964     cp $TMP_RPM/pxeboot/pxelinux.cfg.files/*-$OTHER_REL_VERSION /pxeboot/pxelinux.cfg.files/ \
965         || report_post_failure_with_msg "Failed to copy pxe-network-installer pxelinux.cfg files"
966
967     rm -rf $TMP_RPM
968 fi
969
970 %end
971
972 # Template from: post_net_common.cfg
973 %pre --erroronfail
974
975 # Source common functions
976 . /tmp/ks-functions.sh
977
978 http_port=$(get_http_port)
979 echo "repo --name=base --baseurl=http://pxecontroller:${http_port:-8080}/feed/rel-19.12/" > /tmp/repo-include
980 echo "repo --name=updates --baseurl=http://pxecontroller:${http_port:-8080}/updates/rel-19.12/" > /tmp/repo-include
981
982 %end
983
984 # Repository arguments from %pre
985 %include /tmp/repo-include
986
987
988 %post --erroronfail
989
990 # Source common functions
991 . /tmp/ks-functions.sh
992
993 # Persist the http port to the platform configuration
994 echo http_port=$(get_http_port) >> /etc/platform/platform.conf
995
996 # Obtain the boot interface from the PXE boot
997 BOOTIF=`cat /proc/cmdline |xargs -n1 echo |grep BOOTIF=`
998 if [ -d /sys/firmware/efi ] ; then
999     BOOTIF=${BOOTIF#BOOTIF=}
1000 else
1001     BOOTIF=${BOOTIF#BOOTIF=01-}
1002     BOOTIF=${BOOTIF//-/:}
1003 fi
1004
1005 mgmt_dev=none
1006 mgmt_vlan=0
1007 if [ -n "$BOOTIF" ] ; then
1008     ndev=`ip link show |grep -B 1 $BOOTIF |head -1 |awk '{print $2}' |sed -e 's/://'`
1009     if [ -n "$ndev" ] ; then
1010         mgmt_dev=$ndev
1011         # Retrieve the management VLAN from sysinv if it exists
1012         mgmt_vlan=`curl -sf http://pxecontroller:6385/v1/isystems/mgmtvlan`
1013         if [ $? -ne 0 ]
1014         then
1015           report_post_failure_with_msg "ERROR: Unable to communicate with System Inventory REST API. Aborting installation."
1016         fi
1017     else
1018         report_post_failure_with_msg "ERROR: Unable to determine mgmt interface from BOOTIF=$BOOTIF."
1019     fi
1020 else
1021     report_post_failure_with_msg "ERROR: BOOTIF is not set. Unable to determine mgmt interface."
1022 fi
1023
1024 if [ $mgmt_vlan -eq 0 ] ; then
1025
1026     # Persist the boot device to the platform configuration. This will get
1027     # overwritten later if the management_interface is on a bonded interface.
1028     echo management_interface=$mgmt_dev >> /etc/platform/platform.conf
1029
1030     # Build networking scripts
1031     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
1032 DEVICE=lo
1033 IPADDR=127.0.0.1
1034 NETMASK=255.0.0.0
1035 NETWORK=127.0.0.0
1036 BROADCAST=127.255.255.255
1037 ONBOOT=yes
1038 IPV6_AUTOCONF=no
1039 NAME=loopback
1040 EOF
1041
1042     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$mgmt_dev
1043 DEVICE=$mgmt_dev
1044 BOOTPROTO=dhcp
1045 ONBOOT=yes
1046 IPV6_AUTOCONF=no
1047 LINKDELAY=20
1048 EOF
1049
1050 else
1051
1052     # Check whether to use inet or inet6
1053     ipv6_addr=$(dig +short AAAA controller)
1054     if [[ -n "$ipv6_addr" ]]
1055     then
1056         mgmt_address_family=inet6
1057         ipv6init=yes
1058         dhcpv6c=yes
1059         dhclientargs=-1
1060     else
1061         mgmt_address_family=inet
1062         ipv6init=no
1063         dhcpv6c=no
1064         dhclientargs=
1065     fi
1066
1067     # Persist the boot device to the platform configuration. This will get
1068     # overwritten later if the management_interface is on a bonded interface.
1069     echo management_interface=vlan$mgmt_vlan >> /etc/platform/platform.conf
1070
1071     # Build networking scripts
1072     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
1073 DEVICE=lo
1074 IPADDR=127.0.0.1
1075 NETMASK=255.0.0.0
1076 NETWORK=127.0.0.0
1077 BROADCAST=127.255.255.255
1078 ONBOOT=yes
1079 IPV6_AUTOCONF=no
1080 NAME=loopback
1081 EOF
1082
1083     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$mgmt_dev
1084 DEVICE=$mgmt_dev
1085 BOOTPROTO=none
1086 ONBOOT=yes
1087 IPV6_AUTOCONF=no
1088 LINKDELAY=20
1089 EOF
1090
1091     cat << EOF > /etc/sysconfig/network-scripts/ifcfg-vlan$mgmt_vlan
1092 DEVICE=vlan$mgmt_vlan
1093 BOOTPROTO=dhcp
1094 DHCLIENTARGS=$dhclientargs
1095 IPV6INIT=$ipv6init
1096 DHCPV6C=$dhcpv6c
1097 ONBOOT=yes
1098 IPV6_AUTOCONF=no
1099 PHYSDEV=$mgmt_dev
1100 VLAN=yes
1101 LINKDELAY=20
1102 EOF
1103
1104     # Reject DHCPOFFER from DHCP server that doesn't send
1105     # wrs-install-uuid option
1106     echo "require wrs-install-uuid;" >>/etc/dhcp/dhclient.conf
1107     echo "require dhcp6.wrs-install-uuid;" >>/etc/dhcp/dhclient.conf
1108
1109     # Bring up the mgmt vlan so that a dhcp lease is acquired and an address is
1110     # setup prior to the post-install reboot.  This is so that the timing of the IP
1111     # address allocation is similar to how normal/non-pxe installation works.
1112     mgmt_iface=vlan$mgmt_vlan
1113     dhclient_family=$([[ $mgmt_address_family == "inet" ]] && echo -4 || echo -6)
1114     ip link add link $mgmt_dev name $mgmt_iface type vlan id $mgmt_vlan
1115     ip link set up dev $mgmt_iface
1116     dhclient $dhclient_family $mgmt_iface || true
1117
1118 fi
1119
1120 %end