From c14492cf604b02dba984e628c451da4a7dcbe93d Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Wed, 1 May 2024 14:18:33 -0700 Subject: [PATCH] Add vagrant steps Signed-off-by: Louis Abel --- config.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/config.sh b/config.sh index 876c7cc..a6df715 100644 --- a/config.sh +++ b/config.sh @@ -579,6 +579,102 @@ function toolbox_container_steps() { rm -f /etc/rpm/macros.image-language-conf sed -i '/tsflags=nodocs/d' /etc/dnf/dnf.conf } + +################################################################################ +# Vagrant +function common_vagrant_steps() { + fallocate -l 2G /swapfile + chmod 600 /swapfile + mkswap /swapfile + echo "/swapfile none swap defaults 0 0" >> /etc/fstab + + cat > /etc/sudoers.d/vagrant << EOF +Defaults:vagrant !requiretty +%vagrant ALL=(ALL) NOPASSWD: ALL +EOF + chmod 0440 /etc/sudoers.d/vagrant + # This may have to be changed for 10 + ex -s /etc/ssh/sshd_config <>/etc/sysconfig/sshd <> /home/vagrant/.ssh/authorized_keys + chmod 600 /home/vagrant/.ssh/authorized_keys + chown -R vagrant:vagrant /home/vagrant/.ssh + + echo 'vag' > /etc/yum/vars/infra + echo blacklist floppy > /etc/modprobe.d/nofloppy.conf + pushd /etc/dracut.conf.d + # Enable VMware PVSCSI support for VMware Fusion guests. + echo 'add_drivers+=" vmw_pvscsi "' > vmware-fusion-drivers.conf + echo 'add_drivers+=" hv_netvsc hv_storvsc hv_utils hv_vmbus hid-hyperv "' > hyperv-drivers.conf + # There's no floppy controller, but probing for it generates timeouts + echo 'omit_drivers+=" floppy "' > nofloppy.conf + popd + echo "Regenerating kernel" + KERNEL_VERSION=$(rpm -q kernel --qf '%{version}-%{release}.%{arch}\n') + dracut -f /boot/initramfs-${KERNEL_VERSION}.img ${KERNEL_VERSION} + rm -rf /etc/ssh/ssh_host_* +} + +function vbox_vagrant_steps() { + # legacy stuff, we won't have this for 10 + cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF + + # Install VBoxGuestAdditions for installed kernel. + # https://git.resf.org/sig_kernel/meta/issues/13 + kver=$(rpm -q --queryformat="%{VERSION}-%{RELEASE}.%{ARCH}" kernel) + echo "stg/rocky" > /etc/dnf/vars/contentdir + sed -i 's/^#baseurl/baseurl/g;s/^mirrorlist/#mirrorlist/g' /etc/yum.repos.d/rocky*repo + dnf -y install kernel-headers-$kver kernel-devel gcc make perl elfutils-libelf-devel + sed -i 's/^baseurl/#baseurl/g;s/^#mirrorlist/mirrorlist/g' /etc/yum.repos.d/rocky*repo + echo "pub/rocky" > /etc/dnf/vars/contentdir + curl -L -o /tmp/vboxadditions.iso https://download.virtualbox.org/virtualbox/7.0.16/VBoxGuestAdditions_7.0.16.iso + mkdir -p /media/VBoxGuestAdditions + mount -o loop,ro /tmp/vboxadditions.iso /media/VBoxGuestAdditions + mkdir -p /tmp/VBoxGuestAdditions + sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run --nox11 --noexec --keep --target /tmp/VBoxGuestAdditions + pushd /tmp/VBoxGuestAdditions + ./install.sh + /sbin/rcvboxadd quicksetup all + popd + ls "/lib/modules/${kver}/misc/" + modinfo "/lib/modules/${kver}/misc/vboxsf.ko" + rm -rf /tmp/VBoxGuestAdditions + umount /media/VBoxGuestAdditions + rm -f /tmp/vboxadditions.iso + rmdir /media/VBoxGuestAdditions + dnf -y remove kernel-devel gcc make perl elfutils-libelf-devel +} + +function libvirt_vagrant_steps() { + # legacy stuff, we won't have this for 10 + cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +PERSISTENT_DHCLIENT="yes" +EOF +} + # ################################################################################ @@ -673,3 +769,14 @@ if [[ "$kiwi_profiles" == *"Container"* ]]; then toolbox_container_steps fi fi + +# Vagrant only +if [[ "$kiwi_profiles" == *"Vagrant"* ]]; then + common_vagrant_steps + if [[ "$kiwi_profiles" == *"Vagrant-Libvirt"* ]]; then + libvirt_vagrant_steps + fi + if [[ "$kiwi_profiles" == *"Vagrant-Vbox"* ]]; then + vbox_vagrant_steps + fi +fi