mirror of
https://github.com/rocky-linux/infrastructure
synced 2024-05-28 17:40:16 +00:00
Merge 7c9f5d0697
into edb87adfd6
This commit is contained in:
commit
3c8a7db64e
111
scripts/libvirt-kickstart/centos8/kickstart.cfg
Normal file
111
scripts/libvirt-kickstart/centos8/kickstart.cfg
Normal file
|
@ -0,0 +1,111 @@
|
|||
# Install
|
||||
|
||||
install
|
||||
lang en_US
|
||||
keyboard us
|
||||
skipx
|
||||
text
|
||||
|
||||
repo --name="BaseOS" --baseurl=https://mirror.phx1.us.spryservers.net/centos/8.3.2011/BaseOS/x86_64/os/
|
||||
repo --name="AppStream" --baseurl=https://mirror.phx1.us.spryservers.net/centos/8.3.2011/AppStream/x86_64/os/
|
||||
|
||||
url --url http://ftp.funet.fi/pub/linux/mirrors/centos/8/BaseOS/x86_64/kickstart/
|
||||
|
||||
# mount /tmp as tmpfs
|
||||
services --enabled=tmp.mount
|
||||
|
||||
rootpw CHANGEME
|
||||
firewall --disabled
|
||||
|
||||
# Create user for provisioning?
|
||||
# user --name example --groups=wheel --password CHANGEME
|
||||
|
||||
selinux --permissive
|
||||
timezone --utc UTC
|
||||
bootloader --location=mbr --append="net.ifnames=0"
|
||||
|
||||
# Partition configuration created in preinstall script
|
||||
%include /tmp/part-include
|
||||
|
||||
%packages
|
||||
@^minimal-environment
|
||||
@core
|
||||
audit
|
||||
curl
|
||||
microcode_ctl
|
||||
nfs-utils
|
||||
nmap-ncat
|
||||
openssh
|
||||
openssh-server
|
||||
parted
|
||||
rpm
|
||||
tcpdump
|
||||
tmux
|
||||
traceroute
|
||||
vim-common
|
||||
vim-enhanced
|
||||
wget
|
||||
|
||||
-iwl*-firmware
|
||||
|
||||
%end
|
||||
|
||||
%post
|
||||
(
|
||||
#!/bin/sh
|
||||
|
||||
# revert consistent interface naming to traditional eth0, eth1, etc.
|
||||
ln -sf /dev/null /etc/udev/rules.d/80-net-name-slot.rules
|
||||
|
||||
# Example: set ssh key for provisioning user?
|
||||
#mkdir /home/example/.ssh
|
||||
#chown example: /home/example/.ssh
|
||||
#chmod 700 /home/example/.ssh
|
||||
#echo "ssh-ed25519 CHANGEME example@host" > /home/example/.ssh/authorized_keys
|
||||
#chmod 600 /home/example/.ssh/authorized_keys
|
||||
#chown example: /home/example/.ssh/authorized_keys
|
||||
|
||||
# Possibly: add to sudoers?
|
||||
)
|
||||
%end
|
||||
%pre
|
||||
(
|
||||
#!/bin/sh
|
||||
set -x
|
||||
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
||||
|
||||
# UEFI partitioning
|
||||
if [ -d /sys/firmware/efi ]; then
|
||||
cat >/tmp/part-include <<EOF
|
||||
clearpart --all --initlabel --drives vda
|
||||
part /boot --fstype xfs --size 1024 --asprimary --ondisk vda
|
||||
part /boot/efi --fstype vfat --size 512 --asprimary --ondisk vda
|
||||
EOF
|
||||
else # BIOS Partitioning
|
||||
cat >/tmp/part-include <<EOF
|
||||
clearpart --all --drives=vda
|
||||
zerombr
|
||||
part /boot --fstype xfs --size=1024 --asprimary --ondisk=vda
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Common part
|
||||
cat >>/tmp/part-include <<EOF
|
||||
part pv.01 --size=1 --grow --asprimary --ondisk=vda
|
||||
volgroup sys_vg pv.01
|
||||
|
||||
# Initial volume sizes are small, but can be extended later
|
||||
# total: 20GB, leaves some space for expansion
|
||||
|
||||
logvol / --fstype xfs --name=root --vgname=sys_vg --size=6144
|
||||
logvol /home --fstype xfs --fsoptions="nodev" --name=home --vgname=sys_vg --size=1024
|
||||
logvol /var --fstype xfs --name=var --vgname=sys_vg --size=4096
|
||||
logvol /var/log/ --fstype xfs --name=var_log --vgname=sys_vg --size=4096
|
||||
logvol /var/log/audit --fstype xfs --name=var_log_audit --vgname=sys_vg --size=2048
|
||||
logvol swap --fstype swap --name swap --vgname sys_vg --size=2048
|
||||
EOF
|
||||
|
||||
) >/tmp/kickstart-pre.log 2>&1
|
||||
%end
|
||||
|
||||
reboot --eject
|
5
scripts/libvirt-kickstart/centos8/params.sh
Normal file
5
scripts/libvirt-kickstart/centos8/params.sh
Normal file
|
@ -0,0 +1,5 @@
|
|||
export MIRROR="https://mirror.phx1.us.spryservers.net/centos/8.3.2011/BaseOS/x86_64/kickstart/"
|
||||
export KICKSTART_FILE="centos8/kickstart.cfg"
|
||||
export OS_VARIANT="rhel8.2"
|
||||
export EXTRA_ARGS=""
|
||||
export DISK_SIZE="30"
|
96
scripts/libvirt-kickstart/kickstart.sh
Executable file
96
scripts/libvirt-kickstart/kickstart.sh
Executable file
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/bash
|
||||
set -eu
|
||||
DNS="10.1.1.1"
|
||||
NET_NAME="libvirt-network"
|
||||
TYPE="centos8"
|
||||
CPUS="1"
|
||||
RAM="2048"
|
||||
LIBVIRT_DATA_DIR="/var/lib/libvirt/images"
|
||||
|
||||
usage() {
|
||||
echo "$0 [-t centos8] [-c CPUs] [-m RAM] vmhost vm.fqdn.example.com"
|
||||
echo
|
||||
echo "the script will output a hopefully-working virt-install line that allows kickstarting a CentOS 8 VM"
|
||||
echo "The vm should have a DNS record"
|
||||
exit 1
|
||||
}
|
||||
|
||||
while getopts "c:t:m:" OPT; do
|
||||
case "$OPT" in
|
||||
c)
|
||||
CPUS="$OPTARG";
|
||||
;;
|
||||
t)
|
||||
TYPE="$OPTARG";
|
||||
;;
|
||||
m)
|
||||
RAM="$((OPTARG*1024))";
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
shift
|
||||
done
|
||||
if [ $# -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
VMHOST="$1"
|
||||
NAME="$2"
|
||||
CONN="qemu+ssh://$VMHOST/system"
|
||||
|
||||
# assume the vms are named with the FQDN for now
|
||||
FQDN="$NAME"
|
||||
|
||||
|
||||
# Get IP from DNS
|
||||
ip=$(dig +short -t A "$FQDN")
|
||||
if [ -z "$ip" ]; then
|
||||
echo "No DNS record found: $FQDN"
|
||||
exit 1
|
||||
else
|
||||
ROUTER="$(echo "$ip" | cut -d. -f1-3).1"
|
||||
NETMASK="255.255.255.0"
|
||||
fi
|
||||
|
||||
# Add ,portgroup=$PG if needed
|
||||
NETWORK="network=${NET_NAME}"
|
||||
|
||||
IP="ip=${ip}::${ROUTER}:${NETMASK}:${FQDN}:eth0:none nameserver=${DNS}";
|
||||
|
||||
source "${TYPE}/params.sh"
|
||||
|
||||
|
||||
if [ "$CPUS" -ge 4 ]; then
|
||||
echo "Did you mix CPUs and RAM?"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if grep -q CHANGEME "$KICKSTART_FILE"; then
|
||||
echo "### found some lines saying 'CHANGEME' in the kickstart file $KICKSTART_FILE. Please review them:"
|
||||
echo
|
||||
grep -n CHANGEME "$KICKSTART_FILE"
|
||||
echo
|
||||
echo '### REMEMBER TO CHANGE THE ROOT PASSWORD AFTER THE INSTALLATION!'
|
||||
fi
|
||||
|
||||
echo -n "
|
||||
virt-install --connect '$CONN' \\
|
||||
--name '$NAME' \\
|
||||
--vcpus '$CPUS' \\
|
||||
--ram '$RAM' \\
|
||||
--os-variant '$OS_VARIANT' \\
|
||||
--disk 'path=${LIBVIRT_DATA_DIR}/${NAME}_root.qcow2,size=$DISK_SIZE,format=qcow2,bus=virtio' \\
|
||||
--network '$NETWORK' \\
|
||||
--location '$MIRROR' \\
|
||||
--initrd-inject '$KICKSTART_FILE' \\
|
||||
--extra-args 'ks=file:/kickstart.cfg console=tty0 net.ifnames=0 $IP'
|
||||
"
|
||||
if [ -n "$EXTRA_ARGS" ]; then
|
||||
echo " $EXTRA_ARGS"
|
||||
else
|
||||
# Final newline
|
||||
echo
|
||||
fi
|
Loading…
Reference in New Issue
Block a user