|
| 1 | +# Kickstart for creating a CentOS 8 Azure VM |
| 2 | +# Note: Support for generation-1 and generation-2 VMs Azure - |
| 3 | +# This kickstart assumes the installation occurs on a UEFI-enabled VM, and |
| 4 | +# will produce a VM image that supports both UEFI and legacy BIOS boot. |
| 5 | +# More: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/generation-2 |
| 6 | + |
| 7 | +# System authorization information |
| 8 | +auth --enableshadow --passalgo=sha512 |
| 9 | + |
| 10 | +# Use text install |
| 11 | +text |
| 12 | + |
| 13 | +# Do not run the Setup Agent on first boot |
| 14 | +firstboot --disable |
| 15 | + |
| 16 | +# Keyboard layouts |
| 17 | +keyboard --vckeymap=us --xlayouts='us' |
| 18 | + |
| 19 | +# System language |
| 20 | +lang en_US.UTF-8 |
| 21 | + |
| 22 | +# Network information |
| 23 | +network --bootproto=dhcp |
| 24 | +network --hostname=localhost.localdomain |
| 25 | +firewall --enabled --service=ssh |
| 26 | + |
| 27 | +# Use network installation |
| 28 | +url --url="mirror.centos.org/centos/8/BaseOS/x86_64/os/" |
| 29 | +repo --name "BaseOS" --baseurl="http://mirror.centos.org/centos/8/BaseOS/x86_64/os/" --cost=100 |
| 30 | +repo --name "AppStream" --baseurl="http://mirror.centos.org/centos/8/AppStream/x86_64/os/" --cost=100 |
| 31 | +repo --name "extras" --baseurl="http://mirror.centos.org/centos/8/extras/x86_64/os/" --cost=100 |
| 32 | + |
| 33 | +# Root password |
| 34 | +rootpw --iscrypted nothing |
| 35 | + |
| 36 | +# Enable SELinux |
| 37 | +selinux --enforcing |
| 38 | + |
| 39 | +# System services |
| 40 | +services --enabled="sshd,waagent,NetworkManager,systemd-resolved" |
| 41 | + |
| 42 | +# System timezone |
| 43 | +timezone Etc/UTC --isUtc |
| 44 | + |
| 45 | +# Don't configure X |
| 46 | +skipx |
| 47 | + |
| 48 | +# Power down the machine after install |
| 49 | +poweroff |
| 50 | + |
| 51 | + |
| 52 | +# Partitioning and bootloader configuration |
| 53 | +# Note: biosboot and efi partitions are pre-created in %pre. |
| 54 | +zerombr |
| 55 | +bootloader --location=mbr --timeout=1 |
| 56 | +# part biosboot --onpart=sda14 --size=4 |
| 57 | +part /boot/efi --onpart=sda15 --fstype=vfat |
| 58 | +part /boot --fstype="xfs" --size=500 |
| 59 | +part / --fstype="xfs" --size=1 --grow --asprimary |
| 60 | + |
| 61 | +%pre --log=/var/log/anaconda/pre-install.log --erroronfail |
| 62 | +#!/bin/bash |
| 63 | + |
| 64 | +# Pre-create the biosboot and EFI partitions |
| 65 | +# - Ensure that efi and biosboot are created at the start of the disk to |
| 66 | +# allow resizing of the OS disk. |
| 67 | +# - Label biosboot and efi as sda14/sda15 for better compat - some tools |
| 68 | +# may assume that sda1/sda2 are '/boot' and '/' respectively. |
| 69 | +sgdisk --clear /dev/sda |
| 70 | +sgdisk --new=14:2048:10239 /dev/sda |
| 71 | +sgdisk --new=15:10240:500M /dev/sda |
| 72 | +sgdisk --typecode=14:EF02 /dev/sda |
| 73 | +sgdisk --typecode=15:EF00 /dev/sda |
| 74 | + |
| 75 | +%end |
| 76 | + |
| 77 | + |
| 78 | +# Disable kdump |
| 79 | +%addon com_redhat_kdump --disable |
| 80 | + |
| 81 | +%end |
| 82 | + |
| 83 | +%packages |
| 84 | +@^minimal-environment |
| 85 | +@standard |
| 86 | +#@container-tools |
| 87 | +WALinuxAgent |
| 88 | +chrony |
| 89 | +sudo |
| 90 | +parted |
| 91 | +-dracut-config-rescue |
| 92 | +-postfix |
| 93 | +-NetworkManager-config-server |
| 94 | +openssh-server |
| 95 | +kernel |
| 96 | +dnf-utils |
| 97 | +rng-tools |
| 98 | +cracklib |
| 99 | +cracklib-dicts |
| 100 | +centos-release |
| 101 | + |
| 102 | +# pull firmware packages out |
| 103 | +-aic94xx-firmware |
| 104 | +-alsa-firmware |
| 105 | +-alsa-lib |
| 106 | +-alsa-tools-firmware |
| 107 | +-ivtv-firmware |
| 108 | +-iwl1000-firmware |
| 109 | +-iwl100-firmware |
| 110 | +-iwl105-firmware |
| 111 | +-iwl135-firmware |
| 112 | +-iwl2000-firmware |
| 113 | +-iwl2030-firmware |
| 114 | +-iwl3160-firmware |
| 115 | +-iwl3945-firmware |
| 116 | +-iwl4965-firmware |
| 117 | +-iwl5000-firmware |
| 118 | +-iwl5150-firmware |
| 119 | +-iwl6000-firmware |
| 120 | +-iwl6000g2a-firmware |
| 121 | +-iwl6000g2b-firmware |
| 122 | +-iwl6050-firmware |
| 123 | +-iwl7260-firmware |
| 124 | +-libertas-sd8686-firmware |
| 125 | +-libertas-sd8787-firmware |
| 126 | +-libertas-usb8388-firmware |
| 127 | + |
| 128 | +# Some things from @core we can do without in a minimal install |
| 129 | +-biosdevname |
| 130 | +-plymouth |
| 131 | +-iprutils |
| 132 | + |
| 133 | +# enable rootfs resize on boot |
| 134 | +cloud-utils-growpart |
| 135 | +gdisk |
| 136 | + |
| 137 | +%end |
| 138 | + |
| 139 | +%post --log=/var/log/anaconda/post-install.log --erroronfail |
| 140 | + |
| 141 | +#!/bin/bash |
| 142 | + |
| 143 | +passwd -d root |
| 144 | +passwd -l root |
| 145 | + |
| 146 | +# Import CentOS public key |
| 147 | +rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial |
| 148 | + |
| 149 | +# Set the kernel cmdline |
| 150 | +sed -i 's/^\(GRUB_CMDLINE_LINUX\)=".*"$/\1="console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 net.ifnames=0 scsi_mod.use_blk_mq=y"/g' /etc/default/grub |
| 151 | + |
| 152 | +# Enable grub serial console |
| 153 | +echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"' >> /etc/default/grub |
| 154 | +sed -i 's/^GRUB_TERMINAL_OUTPUT=".*"$/GRUB_TERMINAL="serial console"/g' /etc/default/grub |
| 155 | + |
| 156 | +# Enable BIOS bootloader |
| 157 | +grub2-mkconfig --output /etc/grub2-efi.cfg |
| 158 | +grub2-install --target=i386-pc --directory=/usr/lib/grub/i386-pc/ /dev/sda |
| 159 | +grub2-mkconfig --output=/boot/grub2/grub.cfg |
| 160 | + |
| 161 | + # Fix grub.cfg to remove EFI entries, otherwise "boot=" is not set correctly and blscfg fails |
| 162 | + EFI_ID=`blkid --match-tag UUID --output value /dev/sda15` |
| 163 | + BOOT_ID=`blkid --match-tag UUID --output value /dev/sda1` |
| 164 | + sed -i 's/gpt15/gpt1/' /boot/grub2/grub.cfg |
| 165 | + sed -i "s/${EFI_ID}/${BOOT_ID}/" /boot/grub2/grub.cfg |
| 166 | + sed -i 's|${config_directory}/grubenv|(hd0,gpt15)/efi/centos/grubenv|' /boot/grub2/grub.cfg |
| 167 | + 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 |
| 168 | + |
| 169 | +# Blacklist the nouveau driver |
| 170 | +cat << EOF > /etc/modprobe.d/blacklist-nouveau.conf |
| 171 | +blacklist nouveau |
| 172 | +options nouveau modeset=0 |
| 173 | +EOF |
| 174 | + |
| 175 | +# Ensure Hyper-V drivers are built into initramfs |
| 176 | +echo '# Ensure Hyper-V drivers are built into initramfs' >> /etc/dracut.conf.d/azure.conf |
| 177 | +echo -e "\nadd_drivers+=\"hv_vmbus hv_netvsc hv_storvsc\"" >> /etc/dracut.conf.d/azure.conf |
| 178 | +kversion=$( rpm -q kernel | sed 's/kernel\-//' ) |
| 179 | +dracut -v -f "/boot/initramfs-${kversion}.img" "$kversion" |
| 180 | + |
| 181 | +# Enable SSH keepalive / Disable root SSH login |
| 182 | +sed -i 's/^#\(ClientAliveInterval\).*$/\1 180/g' /etc/ssh/sshd_config |
| 183 | +sed -i 's/^PermitRootLogin.*/#PermitRootLogin no/g' /etc/ssh/sshd_config |
| 184 | + |
| 185 | +# Configure network |
| 186 | +cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0 |
| 187 | +DEVICE=eth0 |
| 188 | +ONBOOT=yes |
| 189 | +BOOTPROTO=dhcp |
| 190 | +TYPE=Ethernet |
| 191 | +USERCTL=no |
| 192 | +PEERDNS=yes |
| 193 | +IPV6INIT=no |
| 194 | +NM_CONTROLLED=yes |
| 195 | +PERSISTENT_DHCLIENT=yes |
| 196 | +EOF |
| 197 | + |
| 198 | +cat << EOF > /etc/sysconfig/network |
| 199 | +NETWORKING=yes |
| 200 | +NOZEROCONF=yes |
| 201 | +HOSTNAME=localhost.localdomain |
| 202 | +EOF |
| 203 | + |
| 204 | +# Disable NetworkManager handling of the SRIOV interfaces |
| 205 | +cat <<EOF > /etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules |
| 206 | + |
| 207 | +# Accelerated Networking on Azure exposes a new SRIOV interface to the VM. |
| 208 | +# This interface is transparently bonded to the synthetic interface, |
| 209 | +# so NetworkManager should just ignore any SRIOV interfaces. |
| 210 | +SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION=="add", ENV{NM_UNMANAGED}="1" |
| 211 | + |
| 212 | +EOF |
| 213 | + |
| 214 | +# Enable DNS cache |
| 215 | +# Comment this by default due to "DNSSEC validation failed" issues |
| 216 | +#sed -i 's/hosts:\s*files dns myhostname/hosts: files resolve dns myhostname/' /etc/nsswitch.conf |
| 217 | + |
| 218 | +# Update dnf configuration |
| 219 | +echo "http_caching=packages" >> /etc/dnf/dnf.conf |
| 220 | +dnf clean all |
| 221 | + |
| 222 | +# XXX instance type markers - MUST match CentOS Infra expectation |
| 223 | +echo 'azure' > /etc/yum/vars/infra |
| 224 | + |
| 225 | +# Set tuned profile |
| 226 | +echo "virtual-guest" > /etc/tuned/active_profile |
| 227 | + |
| 228 | +# Deprovision and prepare for Azure |
| 229 | +/usr/sbin/waagent -force -deprovision |
| 230 | + |
| 231 | +%end |
0 commit comments