|
| 1 | +# Kickstart for provisioning a CentOS 8.1 Azure VM with LVM |
| 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 | +# Partition clearing information |
| 48 | +#clearpart --all --initlabel |
| 49 | + |
| 50 | +# Clear the MBR |
| 51 | +zerombr |
| 52 | + |
| 53 | +# Disk partitioning information |
| 54 | +# part biosboot --onpart=sda14 --size=4 |
| 55 | +part /boot/efi --onpart=sda15 --fstype=vfat --size=500 |
| 56 | +part /boot --fstype="xfs" --size=500 |
| 57 | +part pv.01 --fstype=lvmpv --size=1000 --grow |
| 58 | +volgroup rootvg pv.01 |
| 59 | +logvol / --vgname=rootvg --fstype=ext4 --size=8192 --name=rootlv |
| 60 | +logvol /var --vgname=rootvg --fstype=ext4 --size=8192 --name=varlv |
| 61 | +logvol /home --vgname=rootvg --fstype=ext4 --size=1024 --name=homelv |
| 62 | +logvol /opt --vgname=rootvg --fstype=ext4 --size=2048 --name=optlv |
| 63 | +logvol /usr --vgname=rootvg --fstype=ext4 --size=10240 --name=usrlv |
| 64 | +logvol /tmp --vgname=rootvg --fstype=ext4 --size=2048 --name=tmplv |
| 65 | + |
| 66 | +# System bootloader configuration |
| 67 | +bootloader --location=mbr --timeout=1 |
| 68 | + |
| 69 | +# Note: biosboot and efi partitions are pre-created %pre to work around blivet issue |
| 70 | +%pre --log=/var/log/anaconda/pre-install.log --erroronfail |
| 71 | +#!/bin/bash |
| 72 | + |
| 73 | +# Pre-create the biosboot and EFI partitions |
| 74 | +sgdisk --clear /dev/sda |
| 75 | +sgdisk --new=14:2048:10239 /dev/sda |
| 76 | +sgdisk --new=15:10240:500M /dev/sda |
| 77 | +sgdisk --typecode=14:EF02 /dev/sda |
| 78 | +sgdisk --typecode=15:EF00 /dev/sda |
| 79 | + |
| 80 | +%end |
| 81 | + |
| 82 | + |
| 83 | +# Disable kdump |
| 84 | +%addon com_redhat_kdump --disable |
| 85 | +%end |
| 86 | + |
| 87 | +%packages |
| 88 | +WALinuxAgent |
| 89 | +@^minimal-environment |
| 90 | +@standard |
| 91 | +#@container-tools |
| 92 | +chrony |
| 93 | +sudo |
| 94 | +parted |
| 95 | +-dracut-config-rescue |
| 96 | +-postfix |
| 97 | +-NetworkManager-config-server |
| 98 | +grub2-pc |
| 99 | +grub2-pc-modules |
| 100 | +openssh-server |
| 101 | +kernel |
| 102 | +dnf-utils |
| 103 | +rng-tools |
| 104 | +cracklib |
| 105 | +cracklib-dicts |
| 106 | +centos-release |
| 107 | +python3 |
| 108 | + |
| 109 | +# pull firmware packages out |
| 110 | +-aic94xx-firmware |
| 111 | +-alsa-firmware |
| 112 | +-alsa-lib |
| 113 | +-alsa-tools-firmware |
| 114 | +-ivtv-firmware |
| 115 | +-iwl1000-firmware |
| 116 | +-iwl100-firmware |
| 117 | +-iwl105-firmware |
| 118 | +-iwl135-firmware |
| 119 | +-iwl2000-firmware |
| 120 | +-iwl2030-firmware |
| 121 | +-iwl3160-firmware |
| 122 | +-iwl3945-firmware |
| 123 | +-iwl4965-firmware |
| 124 | +-iwl5000-firmware |
| 125 | +-iwl5150-firmware |
| 126 | +-iwl6000-firmware |
| 127 | +-iwl6000g2a-firmware |
| 128 | +-iwl6000g2b-firmware |
| 129 | +-iwl6050-firmware |
| 130 | +-iwl7260-firmware |
| 131 | +-libertas-sd8686-firmware |
| 132 | +-libertas-sd8787-firmware |
| 133 | +-libertas-usb8388-firmware |
| 134 | + |
| 135 | +# Some things from @core we can do without in a minimal install |
| 136 | +-biosdevname |
| 137 | +-plymouth |
| 138 | +-iprutils |
| 139 | + |
| 140 | +# enable rootfs resize on boot |
| 141 | +cloud-utils-growpart |
| 142 | +gdisk |
| 143 | + |
| 144 | +%end |
| 145 | + |
| 146 | + |
| 147 | +%post --log=/var/log/anaconda/post-install.log --erroronfail |
| 148 | + |
| 149 | +#!/bin/bash |
| 150 | + |
| 151 | +# Disable the root account |
| 152 | +usermod root -p '!!' |
| 153 | + |
| 154 | +# Set these to the point release baseurls so we can recreate a previous point release without current major version updates |
| 155 | +# Set Base and AppStream repos to the Azure mirrors |
| 156 | +sed -i 's/mirror.centos.org/olcentgbl.trafficmanager.net/' /etc/yum.repos.d/CentOS-AppStream.repo |
| 157 | +sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/CentOS-AppStream.repo |
| 158 | +sed -i 's/^#baseurl/baseurl/' /etc/yum.repos.d/CentOS-AppStream.repo |
| 159 | +sed -i -e 's/$releasever/8.1.1911/' /etc/yum.repos.d/CentOS-Base.repo |
| 160 | + |
| 161 | +sed -i 's/mirror.centos.org/olcentgbl.trafficmanager.net/' /etc/yum.repos.d/CentOS-Base.repo |
| 162 | +sed -i 's/^mirrorlist/#mirrorlist/' /etc/yum.repos.d/CentOS-Base.repo |
| 163 | +sed -i 's/^#baseurl/baseurl/' /etc/yum.repos.d/CentOS-Base.repo |
| 164 | + |
| 165 | +# Import CentOS public key |
| 166 | +rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial |
| 167 | + |
| 168 | +# Set the kernel cmdline |
| 169 | +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 |
| 170 | + |
| 171 | +# Enforce GRUB_TIMEOUT=1 and remove any existing GRUB_TIMEOUT_STYLE and append GRUB_TIMEOUT_STYLE=countdown after GRUB_TIMEOUT |
| 172 | +sed -i -n -e 's/GRUB_TIMEOUT=.*/GRUB_TIMEOUT=1/' -e '/^GRUB_TIMEOUT_STYLE=/!p' -e '/^GRUB_TIMEOUT=/aGRUB_TIMEOUT_STYLE=countdown' /etc/default/grub |
| 173 | + |
| 174 | +# Enable grub serial console |
| 175 | +echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"' >> /etc/default/grub |
| 176 | +sed -i 's/^GRUB_TERMINAL_OUTPUT=".*"$/GRUB_TERMINAL="serial console"/g' /etc/default/grub |
| 177 | + |
| 178 | +# Enable BIOS bootloader |
| 179 | +grub2-mkconfig --output /etc/grub2-efi.cfg |
| 180 | +grub2-install --target=i386-pc --directory=/usr/lib/grub/i386-pc/ /dev/sda |
| 181 | +grub2-mkconfig --output=/boot/grub2/grub.cfg |
| 182 | + |
| 183 | + # Fix grub.cfg to remove EFI entries, otherwise "boot=" is not set correctly and blscfg fails |
| 184 | + EFI_ID=`blkid --match-tag UUID --output value /dev/sda15` |
| 185 | + BOOT_ID=`blkid --match-tag UUID --output value /dev/sda1` |
| 186 | + sed -i 's/gpt15/gpt1/' /boot/grub2/grub.cfg |
| 187 | + sed -i "s/${EFI_ID}/${BOOT_ID}/" /boot/grub2/grub.cfg |
| 188 | + sed -i 's|${config_directory}/grubenv|(hd0,gpt15)/efi/centos/grubenv|' /boot/grub2/grub.cfg |
| 189 | + 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 |
| 190 | + |
| 191 | +# Blacklist the nouveau driver |
| 192 | +cat << EOF > /etc/modprobe.d/blacklist-nouveau.conf |
| 193 | +blacklist nouveau |
| 194 | +options nouveau modeset=0 |
| 195 | +EOF |
| 196 | + |
| 197 | +# Ensure Hyper-V drivers are built into initramfs |
| 198 | +echo '# Ensure Hyper-V drivers are built into initramfs' >> /etc/dracut.conf.d/azure.conf |
| 199 | +echo -e "\nadd_drivers+=\"hv_vmbus hv_netvsc hv_storvsc\"" >> /etc/dracut.conf.d/azure.conf |
| 200 | +kversion=$( rpm -q kernel | sed 's/kernel\-//' ) |
| 201 | +dracut -v -f "/boot/initramfs-${kversion}.img" "$kversion" |
| 202 | + |
| 203 | +# Enable SSH keepalive / Disable root SSH login |
| 204 | +sed -i 's/^#\(ClientAliveInterval\).*$/\1 180/g' /etc/ssh/sshd_config |
| 205 | +sed -i 's/^PermitRootLogin.*/#PermitRootLogin no/g' /etc/ssh/sshd_config |
| 206 | + |
| 207 | +# Configure network |
| 208 | +cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0 |
| 209 | +DEVICE=eth0 |
| 210 | +ONBOOT=yes |
| 211 | +BOOTPROTO=dhcp |
| 212 | +TYPE=Ethernet |
| 213 | +USERCTL=no |
| 214 | +PEERDNS=yes |
| 215 | +IPV6INIT=no |
| 216 | +NM_CONTROLLED=yes |
| 217 | +PERSISTENT_DHCLIENT=yes |
| 218 | +EOF |
| 219 | + |
| 220 | +cat << EOF > /etc/sysconfig/network |
| 221 | +NETWORKING=yes |
| 222 | +EOF |
| 223 | + |
| 224 | +# Disable NetworkManager handling of the SRIOV interfaces |
| 225 | +cat <<EOF > /etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules |
| 226 | + |
| 227 | +# Accelerated Networking on Azure exposes a new SRIOV interface to the VM. |
| 228 | +# This interface is transparently bonded to the synthetic interface, |
| 229 | +# so NetworkManager should just ignore any SRIOV interfaces. |
| 230 | +SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION=="add", ENV{NM_UNMANAGED}="1" |
| 231 | + |
| 232 | +EOF |
| 233 | + |
| 234 | +# Enable PTP with chrony for accurate time sync |
| 235 | +echo -e "\nrefclock PHC /dev/ptp0 poll 3 dpoll -2 offset 0\n" >> /etc/chrony.conf |
| 236 | + |
| 237 | +# Enable DNS cache |
| 238 | +# Comment this by default due to "DNSSEC validation failed" issues |
| 239 | +#sed -i 's/hosts:\s*files dns myhostname/hosts: files resolve dns myhostname/' /etc/nsswitch.conf |
| 240 | + |
| 241 | +# Update dnf configuration |
| 242 | +echo "http_caching=packages" >> /etc/dnf/dnf.conf |
| 243 | +dnf clean all |
| 244 | + |
| 245 | +# Set tuned profile |
| 246 | +echo "virtual-guest" > /etc/tuned/active_profile |
| 247 | + |
| 248 | + |
| 249 | +# Unset point release at the end of the post-install script so we can recreate a previous point release without current major version updates |
| 250 | +sed -i -e 's/8.1.1911/$releasever/' /etc/yum.repos.d/CentOS-Base.repo |
| 251 | + |
| 252 | +# Deprovision and prepare for Azure |
| 253 | +/usr/sbin/waagent -force -deprovision |
| 254 | + |
| 255 | +%end |
0 commit comments