Created
March 17, 2026 23:44
-
-
Save ploegert/8dac184cbc13a4a62fcea5b31b1a38b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "== RHEL / VirtualBox Guest Additions setup ==" | |
| echo "Kernel: $(uname -r)" | |
| echo | |
| echo "== 1) Update packages (recommended to reduce kernel/module mismatch) ==" | |
| sudo dnf -y update || true | |
| echo | |
| echo "== 2) Install build dependencies for Guest Additions kernel modules ==" | |
| # Common requirements called out for RHEL/CentOS/Fedora-style guests: | |
| # gcc, make, perl, kernel-devel, kernel-headers (+ often libelf tools) | |
| sudo dnf -y install gcc make perl kernel-devel kernel-headers elfutils-libelf-devel || \ | |
| sudo dnf -y install gcc make perl kernel-devel kernel-headers | |
| echo | |
| echo "== 3) Confirm kernel-devel matches the running kernel ==" | |
| # Many Guest Additions failures are caused by mismatch between uname -r and installed kernel-devel. | |
| rpm -q "kernel-devel-$(uname -r)" || { | |
| echo "WARNING: kernel-devel for the running kernel is NOT installed." | |
| echo "Attempting to install matching kernel-devel package..." | |
| sudo dnf -y install "kernel-devel-$(uname -r)" || true | |
| } | |
| echo | |
| echo "== 4) Mount the VirtualBox Guest Additions ISO ==" | |
| # In VirtualBox UI: Devices -> Insert/Install Guest Additions | |
| sudo mkdir -p /mnt/cdrom | |
| # Try a couple common device names | |
| if sudo mount /dev/cdrom /mnt/cdrom 2>/dev/null; then | |
| echo "Mounted /dev/cdrom to /mnt/cdrom" | |
| elif sudo mount /dev/sr0 /mnt/cdrom 2>/dev/null; then | |
| echo "Mounted /dev/sr0 to /mnt/cdrom" | |
| else | |
| echo "ERROR: Could not mount Guest Additions ISO." | |
| echo "Make sure you selected: Devices -> Insert/Install Guest Additions CD Image in VirtualBox." | |
| exit 1 | |
| fi | |
| echo | |
| echo "== 5) Run the Guest Additions installer ==" | |
| cd /mnt/cdrom | |
| if [[ -x ./VBoxLinuxAdditions.run ]]; then | |
| sudo ./VBoxLinuxAdditions.run | |
| else | |
| echo "ERROR: VBoxLinuxAdditions.run not found on the mounted ISO." | |
| echo "Check that the VBoxGuestAdditions ISO was inserted." | |
| exit 1 | |
| fi | |
| echo | |
| echo "== 6) Verify kernel modules loaded (after install) ==" | |
| # Common modules include vboxguest and vboxsf (and often vboxvideo) | |
| (lsmod | grep -E 'vboxguest|vboxsf|vboxvideo' || true) | |
| echo | |
| echo "== 7) Reboot recommended ==" | |
| echo "Guest Additions often require a reboot to fully activate (display resize, shared folders, etc.)." | |
| echo "Run: sudo reboot" | |
| `` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment