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