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