Unattended Installation of Oracle Linux 9.5 on VirtualBox

The following steps describe an unattended installation of Oracle Linux 9.5 on Virtualbox. The host system in my case is Windows 10.

General Preparations for new VM Installations

These steps have to be done once and can be used to install also other guest Operationg Systems (e.g. Windows):
Add the path of vboxmanage to the Windows Path environment variable. For example with Win+r and then enter:

rundll32 sysdm.cpl,EditEnvironmentVariables

Add C:\Program Files\Oracle\VirtualBox to the User variable Path.
A directory c:\vms for the virtual machines on the host system should exist:

mkdir c:\vms

Preparation of the Linux guest installation

Download the Oracle Linux 9.5 iso file from Oracle and place it in the folder c:\sw.

Unattended Installation of Oracle Linux 9.5 on VirtualBox

Configure the Virtual Machine

Run these steps in a Windows command prompt to configure the new VM. You probably need to adjust the parameter –bridgeadapter1 to the name of your primary interface of the Windows host system (see Description of: ipconfig /all|findstr /C:Description /C:IPv|findstr /V Virtual)

set "VHOST=" && set "MAC="
(set /p VHOST=Enter VM name ^(e.g. lin1^):
set /p MAC=Enter the MAC address of the VM if you would like to use a dedicated MAC address. Press Enter to let VirtualBox assign a random MAC: 
call vboxmanage createvm --name %VHOST% --ostype Oracle9_64 --register
call vboxmanage modifyvm %VHOST% --clipboard-mode=bidirectional --drag-and-drop=bidirectional --audio-controller=hda --audio-out=on
call vboxmanage modifyvm %VHOST% --memory=8192 --cpus=4 --vram=128 --graphicscontroller=vmsvga --usb-ehci=on
call vboxmanage setextradata %VHOST% GUI/ScaleFactor 2
call vboxmanage storagectl %VHOST% --name "IDE" --add ide
call vboxmanage storagectl %VHOST% --name "SATA" --add sata --bootable on
call vboxmanage createmedium disk --filename c:\vms\%VHOST%\%VHOST%_1.vdi --size 512000 --variant Standard
call vboxmanage storageattach %VHOST% --storagectl "SATA" --port 0 --device 0 --type hdd --medium c:\vms\%VHOST%\%VHOST%_1.vdi
call vboxmanage modifyvm %VHOST% --nic1 bridged --bridgeadapter1 "Intel(R) Ethernet Connection (2) I219-LM"
if defined MAC call vboxmanage modifyvm %VHOST% --mac-address1=%MAC% 
call vboxmanage sharedfolder add %VHOST% --name=sw --hostpath=c:\sw --automount --auto-mount-point=/sw
rem set the display resolution for all gnome users
call vboxmanage setextradata %VHOST% "GUI/LastGuestSizeHint" "1024,768"
call vboxmanage showvminfo %VHOST%|findstr /C:"NIC 1")

The last command shows the mac address that the VM will use. Add the IP/mac address to your local dns so that the new machine can retrieve the IP address you want to use for the VM. Now start the unattended installation:

Perform the unattended OS installation

vboxmanage unattended install %VHOST% --iso=c:\sw\OracleLinux-R9-U5-x86_64-dvd.iso --user=user1 --user-password=changeme --install-additions --additions-iso="C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso" --locale=en_US --country=DE --time-zone="Europe/Berlin" --hostname=%VHOST%.fritz.box --start-vm=gui --post-install-command="chroot /mnt/sysimage sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config; chroot /mnt/sysimage systemctl restart sshd; chroot /mnt/sysimage systemctl restart vboxadd"
rem

The installation takes about 20 minutes. Now you are able to login to the system with the IP or hostname you specified in the DNS server (username: root password: changeme). If you would like to take advantage of the poor man’s RPM cache you could enable it now 🙂 Afterwards perform these steps:

# fix rcvboxadd
sed -i "/#test \! -f \"\$1\"/s/    #/    /" /sbin/rcvboxadd
bash -c "
# set the keyboard if needed
localectl set-keymap de
# install and update packages:
dnf -y update && dnf -y groupinstall 'Server with GUI' && dnf -y install libnsl ksh libnsl sysstat libnsl2 nfs-utils libaio-devel iotop sshpass expect
# setup VirtualBox Guest Additions (this is needed to make the clipboard work)
/sbin/rcvboxadd setup
# Recompile VirtualBox Guest Additions kernel modules:
/sbin/rcvboxadd quicksetup all
# disable 'Blank screen delay' and 'Automatic Screen Lock' for user root for the current session
gsettings set org.gnome.desktop.session idle-delay 0
gsettings set org.gnome.desktop.screensaver lock-enabled false
# disable selinux:
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
systemctl set-default graphical.target
# set the /etc/hosts entry to: <ip> <fqdn> <hostname>
echo \"$(host `hostname`|awk {'print $4"  "$1'})\" \"$(hostname|awk -F. {'print $1'})\" >> /etc/hosts
# disable the Gnome Welcome screen
dnf -y remove gnome-tour
# disable 'Blank screen delay' and 'Automatic Screen Lock' for all gdm users
cat << EOF > /etc/dconf/db/local.d/02-session
[org/gnome/desktop/session]
idle-delay=uint32 0
EOF
cat << EOF > /etc/dconf/db/local.d/01-screensaver
[org/gnome/desktop/screensaver]
lock-enabled=false
EOF
dconf update
# disable the boot splash screen (plymouth)
grubby --update-kernel=ALL --remove-args=rhgb
# remove nomodeset (unless GUI does not start)
grubby --update-kernel=ALL --remove-args=nomodeset
# lower the grub timeout from 5 seconds to 2
sed -i s/GRUB_TIMEOUT=5/GRUB_TIMEOUT=2/g /etc/default/grub
# set the console resolution to 1024x768x32
grubby --update-kernel=ALL --args vga=836
# generate a grub config file
grub2-mkconfig -o /boot/grub2/grub.cfg
# disable bracketed paste
cat <<EOF >>/etc/inputrc
# needed for pasted commands to run
set enable-bracketed-paste off
EOF
init 6"

Your new Oracle Linux 9.5 VM is now ready to use! Have fun.

Further info

Some useful Links:

Delete a Virtual Machine

To delete a VM follow these steps.

Updating VirtualBox Guest Additions

Follow these steps to update the Oracle VirtualBox Guest Additions