Install a RedHat Enterprise Linux 8.10 VM on VirtualBox with vboxmanage

These steps can be used to setup a RHEL 8.10 VirtualBox guest that can be used as the base OS for the other blog posts. The host system in my case is Windows 10. The unattended installation process is used.

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 RHEL 8.10 iso file from RedHat to the folder c:\sw. If you dont have an RedHat Account you need to create one.

Install a new RHEL 8.10 VM

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 RedHat8_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
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\rhel-8.10-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
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
# register the system with RedHat:
subscription-manager register
# install and update packages:
dnf -y update && dnf -y groupinstall 'Server with GUI' && dnf -y install libnsl bc binutils compat-openssl10 elfutils-libelf glibc glibc-devel ksh libaio libXrender libX11 libXau libXi libXtst  libgcc libnsl libstdc++ libxcb libibverbs make smartmontools sysstat libnsl2 net-tools nfs-utils libstdc++-devel libaio-devel iotop kernel-devel-$(uname -r) 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 screen lock for user root
gsettings set org.gnome.desktop.session idle-delay 0
# 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 for all users
echo 'X-GNOME-Autostart-enabled=false' >> /etc/xdg/autostart/gnome-initial-setup-first-login.desktop
# disable the screen idle delay (disables the lock screen) for all gnome users
cat << EOF > /etc/dconf/db/local.d/01-session
# dconf path
[org/gnome/desktop/session]

# settings
idle-delay=uint32 0
EOF
dconf update
# disable the boot splash screen (plymouth)
grubby --update-kernel=ALL --remove-args=rhgb
# lower the grub timeout from 5 seconds to 2
sed -i s/GRUB_TIMEOUT=5/GRUB_TIMEOUT=2/g /etc/default/grub
# set the resolution to 1024x768
grubby --update-kernel=ALL --args vga=792
# generate a grub config file
grub2-mkconfig -o /boot/grub2/grub.cfg
init 6"

Your system is now ready to use! Have fun.

Further info

Some useful Links:

Delete the VM

If there are errors during the installation you can remove the VM configuration and files and do a complete new installation:

set "VHOST="
(set /p VHOST=Enter VM name ^(e.g. lin1^): 
call vboxmanage controlvm %VHOST% poweroff
timeout /T 4 /NOBREAK
call vboxmanage unregistervm %VHOST% --delete-all
call rmdir /S/Q c:\vms\%VHOST%)

Updating VirtualBox Guest Additions

After installing a new version of VirtualBox on the host machine you can update the guest additions with the following commands:

# first we get the current version of the installed guest additions on the linux VM
rcvboxadd status-kernel
Output
[root@lin1 ~]# rcvboxadd status-kernel
VirtualBox Guest Additions: kernel modules 7.1.4 r165100 are loaded
[root@lin1 ~]#

The version of the VirtualBox host can be verified in the UI (Help => About VirtualBox)

Then we perform the update on the Windows host. The Virtual Machine will reboot automatically after the installation:

set "VHOST="
(
set /p VHOST=Enter VM name ^(e.g. lin1^):
call vboxmanage guestcontrol %VHOST% updatega --verbose --reboot --source="C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso")
Output:
Enter VM name (e.g. lin1):lin1
Updating Guest Additions ...
Using source: C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso
Guest Additions 7.1.4r165100 currently installed, waiting for Guest Additions installer to start ...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Guest Additions update successful.
Rebooting guest ...
The guest needs to be restarted in order to make use of the updated Guest Additions.

We can then check the new version again:

Output:
[root@lin1 ~]# rcvboxadd status-kernel
VirtualBox Guest Additions: kernel modules 7.1.6 r167084 are loaded
[root@lin1 ~]#

The update is finished now. You might want to apply the fix for “rcvboxadd quicksetup always compiles” since the modifications have been overwritten by the update.