|
| 1 | +# Kickstart for provisioning a CentOS 8.1 Azure HPC VM |
| 2 | + |
| 3 | +# System authorization information |
| 4 | +auth --enableshadow --passalgo=sha512 |
| 5 | + |
| 6 | +# Use graphical install |
| 7 | +text |
| 8 | + |
| 9 | +# Do not run the Setup Agent on first boot |
| 10 | +firstboot --disable |
| 11 | + |
| 12 | +# Keyboard layouts |
| 13 | +keyboard --vckeymap=us --xlayouts='us' |
| 14 | + |
| 15 | +# System language |
| 16 | +lang en_US.UTF-8 |
| 17 | + |
| 18 | +# Network information |
| 19 | +network --bootproto=dhcp |
| 20 | + |
| 21 | +# Use network installation |
| 22 | +url --url="http://olcentgbl.trafficmanager.net/centos/8.1.1911/BaseOS/x86_64/os/" |
| 23 | +repo --name "BaseOS" --baseurl="http://olcentgbl.trafficmanager.net/centos/8.1.1911/BaseOS/x86_64/os/" --cost=100 |
| 24 | +repo --name="AppStream" --baseurl="http://olcentgbl.trafficmanager.net/centos/8.1.1911/AppStream/x86_64/os/" --cost=100 |
| 25 | + |
| 26 | +# Root password |
| 27 | +rootpw --plaintext "to_be_disabled" |
| 28 | + |
| 29 | +# System services |
| 30 | +services --enabled="sshd,waagent,NetworkManager,systemd-resolved" |
| 31 | + |
| 32 | +# System timezone |
| 33 | +timezone Etc/UTC --isUtc |
| 34 | + |
| 35 | +# Firewall configuration |
| 36 | +firewall --disabled |
| 37 | + |
| 38 | +# Enable SELinux |
| 39 | +selinux --enforcing |
| 40 | + |
| 41 | +# Don't configure X |
| 42 | +skipx |
| 43 | + |
| 44 | +# Power down the machine after install |
| 45 | +poweroff |
| 46 | + |
| 47 | +# Partitioning and bootloader configuration |
| 48 | +# Note: biosboot and efi partitions are pre-created %pre to work around blivet issue |
| 49 | +zerombr |
| 50 | +bootloader --location=mbr --timeout=1 |
| 51 | +# part biosboot --onpart=sda14 --size=4 |
| 52 | +part /boot/efi --onpart=sda15 --fstype=vfat --size=500 |
| 53 | +part /boot --fstype="xfs" --size=500 |
| 54 | +part / --fstype="xfs" --size=1 --grow --asprimary |
| 55 | + |
| 56 | +%pre --log=/var/log/anaconda/pre-install.log --erroronfail |
| 57 | +#!/bin/bash |
| 58 | + |
| 59 | +# Pre-create the biosboot and EFI partitions |
| 60 | +sgdisk --clear /dev/sda |
| 61 | +sgdisk --new=14:2048:10239 /dev/sda |
| 62 | +sgdisk --new=15:10240:500M /dev/sda |
| 63 | +sgdisk --typecode=14:EF02 /dev/sda |
| 64 | +sgdisk --typecode=15:EF00 /dev/sda |
| 65 | + |
| 66 | +%end |
| 67 | + |
| 68 | + |
| 69 | +# Disable kdump |
| 70 | +%addon com_redhat_kdump --disable |
| 71 | +%end |
| 72 | + |
| 73 | +%packages |
| 74 | +WALinuxAgent |
| 75 | +@^minimal-environment |
| 76 | +@standard |
| 77 | +#@container-tools |
| 78 | +chrony |
| 79 | +sudo |
| 80 | +parted |
| 81 | +-dracut-config-rescue |
| 82 | +-postfix |
| 83 | +-NetworkManager-config-server |
| 84 | +grub2-pc |
| 85 | +grub2-pc-modules |
| 86 | +openssh-server |
| 87 | +kernel |
| 88 | +dnf-utils |
| 89 | +rng-tools |
| 90 | +cracklib |
| 91 | +cracklib-dicts |
| 92 | +centos-release |
| 93 | +python3 |
| 94 | + |
| 95 | +# pull firmware packages out |
| 96 | +-aic94xx-firmware |
| 97 | +-alsa-firmware |
| 98 | +-alsa-lib |
| 99 | +-alsa-tools-firmware |
| 100 | +-ivtv-firmware |
| 101 | +-iwl1000-firmware |
| 102 | +-iwl100-firmware |
| 103 | +-iwl105-firmware |
| 104 | +-iwl135-firmware |
| 105 | +-iwl2000-firmware |
| 106 | +-iwl2030-firmware |
| 107 | +-iwl3160-firmware |
| 108 | +-iwl3945-firmware |
| 109 | +-iwl4965-firmware |
| 110 | +-iwl5000-firmware |
| 111 | +-iwl5150-firmware |
| 112 | +-iwl6000-firmware |
| 113 | +-iwl6000g2a-firmware |
| 114 | +-iwl6000g2b-firmware |
| 115 | +-iwl6050-firmware |
| 116 | +-iwl7260-firmware |
| 117 | +-libertas-sd8686-firmware |
| 118 | +-libertas-sd8787-firmware |
| 119 | +-libertas-usb8388-firmware |
| 120 | + |
| 121 | +# Some things from @core we can do without in a minimal install |
| 122 | +-biosdevname |
| 123 | +-plymouth |
| 124 | +-iprutils |
| 125 | + |
| 126 | +# enable rootfs resize on boot |
| 127 | +cloud-utils-growpart |
| 128 | +gdisk |
| 129 | + |
| 130 | +%end |
| 131 | + |
| 132 | + |
| 133 | +%post --log=/var/log/anaconda/post-install.log --erroronfail |
| 134 | + |
| 135 | +#!/bin/bash |
| 136 | + |
| 137 | +# Disable the root account |
| 138 | +usermod root -p '!!' |
| 139 | + |
| 140 | +# Set Base and AppStream repos to the Azure mirrors |
| 141 | +sed -i 's/mirror.centos.org/olcentgbl.trafficmanager.net/' /etc/yum.repos.d/CentOS-AppStream.repo |
| 142 | +sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/CentOS-AppStream.repo |
| 143 | +sed -i 's/^#baseurl/baseurl/' /etc/yum.repos.d/CentOS-AppStream.repo |
| 144 | + |
| 145 | +sed -i 's/mirror.centos.org/olcentgbl.trafficmanager.net/' /etc/yum.repos.d/CentOS-Base.repo |
| 146 | +sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/CentOS-Base.repo |
| 147 | +sed -i 's/^#baseurl/baseurl/' /etc/yum.repos.d/CentOS-Base.repo |
| 148 | + |
| 149 | +# Import CentOS public key |
| 150 | +rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial |
| 151 | + |
| 152 | +# Set the kernel cmdline |
| 153 | +sed -i 's/^\(GRUB_CMDLINE_LINUX\)=".*"$/\1="console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 scsi_mod.use_blk_mq=y"/g' /etc/default/grub |
| 154 | + |
| 155 | +# Enable grub serial console |
| 156 | +echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"' >> /etc/default/grub |
| 157 | +sed -i 's/^GRUB_TERMINAL_OUTPUT=".*"$/GRUB_TERMINAL="serial console"/g' /etc/default/grub |
| 158 | + |
| 159 | +# Enable BIOS bootloader |
| 160 | +grub2-mkconfig --output /etc/grub2-efi.cfg |
| 161 | +grub2-install --target=i386-pc --directory=/usr/lib/grub/i386-pc/ /dev/sda |
| 162 | +grub2-mkconfig --output=/boot/grub2/grub.cfg |
| 163 | + |
| 164 | +# Grab major version number so we can properly adjust grub config. |
| 165 | +# Should work on both RHEL and CentOS reliably |
| 166 | +majorVersion=$(rpm -E %{rhel}) |
| 167 | + |
| 168 | + # Fix grub.cfg to remove EFI entries, otherwise "boot=" is not set correctly and blscfg fails |
| 169 | + [ "$majorVersion" = "7" ] && { |
| 170 | + EFI_ID=`blkid -s UUID -o value /dev/sda15` |
| 171 | + EFI_ID=`blkid -s UUID -o value /dev/sda1` |
| 172 | + sed -i 's|$prefix/grubenv|(hd0,gpt15)/efi/centos/grubenv|' /boot/grub2/grub.cfg |
| 173 | + sed -i 's|load_env|load_env -f (hd0,gpt15)/efi/centos/grubenv|' /boot/grub2/grub.cfg |
| 174 | + |
| 175 | + # Required for CentOS 7.x due to no blscfg: https://bugzilla.redhat.com/show_bug.cgi?id=1570991#c6 |
| 176 | + #cat /etc/grub2-efi.cfg | sed -e 's|linuxefi|linux|' -e 's|initrdefi|initrd|' > /boot/grub2/grub.cfg |
| 177 | + sed -i -e 's|linuxefi|linux|' -e 's|initrdefi|initrd|' /boot/grub2/grub.cfg |
| 178 | + } |
| 179 | + [ "$majorVersion" = "8" ] && { |
| 180 | + EFI_ID=`blkid --match-tag UUID --output value /dev/sda15` |
| 181 | + BOOT_ID=`blkid --match-tag UUID --output value /dev/sda1` |
| 182 | + } |
| 183 | + sed -i 's/gpt15/gpt1/' /boot/grub2/grub.cfg |
| 184 | + sed -i "s/${EFI_ID}/${BOOT_ID}/" /boot/grub2/grub.cfg |
| 185 | + sed -i 's|${config_directory}/grubenv|(hd0,gpt15)/efi/centos/grubenv|' /boot/grub2/grub.cfg |
| 186 | + sed -i '/^### BEGIN \/etc\/grub.d\/30_uefi/,/^### END \/etc\/grub.d\/30_uefi/{/^### BEGIN \/etc\/grub.d\/30_uefi/!{/^### END \/etc\/grub.d\/30_uefi/!d}}' /boot/grub2/grub.cfg |
| 187 | + |
| 188 | +# Blacklist the nouveau driver |
| 189 | +cat << EOF > /etc/modprobe.d/blacklist-nouveau.conf |
| 190 | +blacklist nouveau |
| 191 | +options nouveau modeset=0 |
| 192 | +EOF |
| 193 | + |
| 194 | +# Ensure Hyper-V drivers are built into initramfs |
| 195 | +echo '# Ensure Hyper-V drivers are built into initramfs' >> /etc/dracut.conf.d/azure.conf |
| 196 | +echo -e "\nadd_drivers+=\"hv_vmbus hv_netvsc hv_storvsc\"" >> /etc/dracut.conf.d/azure.conf |
| 197 | +kversion=$( rpm -q kernel | sed 's/kernel\-//' ) |
| 198 | +dracut -v -f "/boot/initramfs-${kversion}.img" "$kversion" |
| 199 | + |
| 200 | +# Enable SSH keepalive / Disable root SSH login |
| 201 | +sed -i 's/^#\(ClientAliveInterval\).*$/\1 180/g' /etc/ssh/sshd_config |
| 202 | +sed -i 's/^PermitRootLogin.*/#PermitRootLogin no/g' /etc/ssh/sshd_config |
| 203 | + |
| 204 | +# Configure network |
| 205 | +cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0 |
| 206 | +DEVICE=eth0 |
| 207 | +ONBOOT=yes |
| 208 | +BOOTPROTO=dhcp |
| 209 | +TYPE=Ethernet |
| 210 | +USERCTL=no |
| 211 | +PEERDNS=yes |
| 212 | +IPV6INIT=no |
| 213 | +NM_CONTROLLED=yes |
| 214 | +PERSISTENT_DHCLIENT=yes |
| 215 | +EOF |
| 216 | + |
| 217 | +cat << EOF > /etc/sysconfig/network |
| 218 | +NETWORKING=yes |
| 219 | +EOF |
| 220 | + |
| 221 | +# Disable NetworkManager handling of the SRIOV interfaces |
| 222 | +cat <<EOF > /etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules |
| 223 | + |
| 224 | +# Accelerated Networking on Azure exposes a new SRIOV interface to the VM. |
| 225 | +# This interface is transparently bonded to the synthetic interface, |
| 226 | +# so NetworkManager should just ignore any SRIOV interfaces. |
| 227 | +SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION=="add", ENV{NM_UNMANAGED}="1" |
| 228 | + |
| 229 | +EOF |
| 230 | + |
| 231 | + |
| 232 | +cd /tmp |
| 233 | +CENTOS_HPC_VERSION="centos-8.1-hpc-20200409" |
| 234 | +wget https://github.com/Azure/azhpc-images/archive/${CENTOS_HPC_VERSION}.tar.gz |
| 235 | +tar -xvf ${CENTOS_HPC_VERSION}.tar.gz |
| 236 | +cd azhpc-images-${CENTOS_HPC_VERSION}/centos/centos-8.x/centos-8.1-hpc |
| 237 | +./install.sh |
| 238 | +cd && rm -rf /tmp/azhpc-images-${CENTOS_HPC_VERSION} |
| 239 | + |
| 240 | +# Enable PTP with chrony for accurate time sync |
| 241 | +echo -e "\nrefclock PHC /dev/ptp0 poll 3 dpoll -2 offset 0\n" >> /etc/chrony.conf |
| 242 | + |
| 243 | +# Enable DNS cache |
| 244 | +# Comment this by default due to "DNSSEC validation failed" issues |
| 245 | +#sed -i 's/hosts:\s*files dns myhostname/hosts: files resolve dns myhostname/' /etc/nsswitch.conf |
| 246 | + |
| 247 | +# Update dnf configuration |
| 248 | +echo "http_caching=packages" >> /etc/dnf/dnf.conf |
| 249 | +dnf clean all |
| 250 | + |
| 251 | +# Set tuned profile |
| 252 | +echo "virtual-guest" > /etc/tuned/active_profile |
| 253 | + |
| 254 | +# Deprovision and prepare for Azure |
| 255 | +/usr/sbin/waagent -force -deprovision |
| 256 | + |
| 257 | +%end |
0 commit comments