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