Unverified Commit 034a2531 authored by Neil Hanlon's avatar Neil Hanlon
Browse files

Cloud image fixes

parent 66fffd34
#!/bin/bash
version=${VERSION:-"8"}
mirror=${MIRROR:-https://dl.rockylinux.org/stg}
type="${TYPE:-EC2}"
arch="${ARCH:-$(uname -m)}"
output_type=gpt_xfs
output_file="Rocky-${version}-${type}-${arch}.qcow2"
remove_packages="aic94xx-firmware alsa-firmware alsa-lib alsa-tools-firmware ivtv-firmware iwl100-firmware iwl1000-firmware iwl105-firmware iwl135-firmware iwl2000-firmware iwl2030-firmware iwl3160-firmware iwl3945-firmware iwl4965-firmware iwl5000-firmware iwl5150-firmware iwl6000-firmware iwl6000g2a-firmware iwl6000g2b-firmware iwl6050-firmware iwl7260-firmware libertas-sd8686-firmware libertas-sd8787-firmware libertas-usb8388-firmware biosdevname iputils plymouth langpacks-* langpacks-en"
packages="@core chrony dnf yum cloud-init cloud-utils-growpart NetworkManager dracut-config-generic dracut-norescue firewalld gdisk grub2 kernel nfs-utils rsync tar dnf-utils yum-utils python3-jsonschema qemu-guest-agent dhcp-client cockpit-ws cockpit-system rocky-release rng-tools"
package_args=""
for p in $packages; do
package_args="${package_args} --package=${p}"
done
remove_package_args=""
for p in $remove_packages; do
remove_package_args="${remove_package_args} --remove-package=${p}"
done
boot_protocols="uefi"
if [[ $arch == x86_64 ]]; then
boot_protocols="${boot_protocols},bios"
fi
sudo mkosi -d rocky -r ${version} -m ${mirror} -t ${output_type} -o ${output_file} \
--architecture $arch \
--bootable \
--base-packages 0 \
--password=rocky \
--postinst-script=$(dirname $0)/genclo/common.sh \
--postinst-script=$(dirname $0)/genclo/ec2.sh \
--qcow2 --boot-protocols="$boot_protocols" \
--without-unified-kernel-images \
$package_args \
$remove_package_args \
$@
#!/bin/bash
# Fix RPMdb, if needed
rpm --rebuilddb
dnf clean all
# Lockout root
passwd -d root
passwd -l root
# setup systemd to boot to the right runlevel
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
echo .
# Ensure sshd
systemctl enable sshd
# Remove unneeded firmware
dnf -C -y remove linux-firmware
# XXX instance type markers - MUST match Rocky Infra expectation
......@@ -18,7 +20,96 @@ marker="${INFRA_MARKER:-genclo}"
[[ -d /etc/yum/vars ]] || mkdir -p /etc/yum/vars
echo '${marker}' > /etc/yum/vars/infra
# Relabel on boot and always remove it
touch /.autorelabel
# Remove firewalld; it is required to be present for install/image building.
# but we dont ship it in cloud
dnf -C -y remove firewalld --setopt="clean_requirements_on_remove=1"
# Remove avahi. Not needed
dnf -C -y remove avahi\*
# Disable auto-spawning of virtual terminals
sed -i '/^#NAutoVTs=.*/ a\
NAutoVTs=0' /etc/systemd/logind.conf
cat > /etc/sysconfig/network << EOF
NETWORKING=yes
NOZEROCONF=yes
EOF
# For cloud images, 'eth0' _is_ the predictable device name, since
# we don't want to be tied to specific virtual (!) hardware
rm -f /etc/udev/rules.d/70*
ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules
# simple eth0 config, again not hard-coded to the build hardware
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
USERCTL="yes"
PEERDNS="yes"
IPV6INIT="no"
PERSISTENT_DHCLIENT="1"
EOF
# Simple tuned config
echo "virtual-guest" > /etc/tuned/active_profile
# generic localhost names
cat > /etc/hosts << EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF
systemctl mask tmp.mount
cat <<EOL > /etc/sysconfig/kernel
# UPDATEDEFAULT specifies if new-kernel-pkg should make
# new kernels the default
UPDATEDEFAULT=yes
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel
EOL
# make sure firstboot doesn't start
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot
# rocky cloud user
echo -e 'rocky\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
sed -i 's/name: cloud-user/name: rocky/g' /etc/cloud/cloud.cfg
# change dhcp client retry/timeouts to resolve #6866
cat >> /etc/dhcp/dhclient.conf << EOF
timeout 300;
retry 60;
EOF
# reorder console entries
sed -i 's/console=tty0/console=tty0 console=ttyS0,115200n8/' /boot/grub2/grub.cfg
# Finalize
# Fix RPMdb, if needed
rpm --rebuilddb
dnf clean all
# Create buildstamp
/bin/date +%Y-%m-%d_%H:%M:%S > /etc/BUILDTIME
rm -f /var/lib/dnf/history.*
rm -fr /var/log/* /tmp/* /tmp/.*
touch /var/log/cron
touch /var/log/boot.log
mkdir -p /var/cache/yum
/usr/sbin/fixfiles -R -a restore
true
#!/bin/bash
# pvgrub support
echo -n "Creating grub.conf for pvgrub"
rootuuid=$( awk '$2=="/" { print $1 };' /etc/fstab )
mkdir /boot/grub
echo -e 'default=0\ntimeout=0\n\n' > /boot/grub/grub.conf
for kv in $( ls -1v /boot/vmlinuz* |grep -v rescue |sed s/.*vmlinuz-// ); do
echo "title Rocky Linux 8 ($kv)" >> /boot/grub/grub.conf
echo -e "\troot (hd0)" >> /boot/grub/grub.conf
echo -e "\tkernel /boot/vmlinuz-$kv ro root=$rootuuid console=hvc0 LANG=en_US.UTF-8" >> /boot/grub/grub.conf
echo -e "\tinitrd /boot/initramfs-$kv.img" >> /boot/grub/grub.conf
echo
done
ln -sf grub.conf /boot/grub/menu.lst
ln -sf /boot/grub/grub.conf /etc/grub.conf
# remove these for ec2 debugging
sed -i -e 's/ rhgb quiet//' /boot/grub/grub.conf
cat > /etc/modprobe.d/blacklist-nouveau.conf << EOL
blacklist nouveau
EOL
# enable resizing on copied AMIs
echo 'install_items+=" sgdisk "' > /etc/dracut.conf.d/sgdisk.conf
echo 'add_drivers+=" xen-netfront xen-blkfront "' > /etc/dracut.conf.d/xen.conf
# Rerun dracut for the installed kernel (not the running kernel):
KERNEL_VERSION=$(rpm -q kernel --qf '%{V}-%{R}.%{arch}\n')
dracut -f /boot/initramfs-$KERNEL_VERSION.img $KERNEL_VERSION
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment