Installing VirtualBox Guest Additions on CentOS: A Step-by-Step Guide
VirtualBox Guest Additions enhance your CentOS virtual machine (VM) with critical features like shared folders, clipboard sharing, automatic screen resolution adjustment, and smoother mouse/keyboard integration. Below is a structured guide to installing them, including prerequisites and troubleshooting tips.
Before installing Guest Additions, ensure your CentOS system is up-to-date and has the necessary tools to compile kernel modules. Run these commands in the terminal:
# Update system packages (CentOS 7/8/9 compatible)
sudo yum update -y # For CentOS 7
# sudo dnf update -y # For CentOS 8/9 (uncomment if using DNF)
# Install compilation tools and kernel headers (critical for Guest Additions)
sudo yum install -y epel-release gcc make perl kernel-devel kernel-headers dkms bzip2
Why?
kernel-devel and kernel-headers must match your running kernel version (check with uname -r) to compile Guest Additions modules.dkms (Dynamic Kernel Module Support) ensures modules rebuild automatically after kernel updates.bzip2 is required to extract installation files.VirtualBox provides a virtual CD-ROM with Guest Additions. To mount it:
The ISO will mount to /run/media/[your-username]/VBox_GAs_[version] (e.g., /run/media/asfor/VBox_GAs_7.2.2).
Open a terminal and execute these commands to install Guest Additions:
# Navigate to the mounted CD-ROM directory
cd /run/media/[your-username]/VBox_GAs_[version] # Replace with your actual path
# Give execute permission to the script (if needed) and run it
sudo chmod +x VBoxLinuxAdditions.run
sudo ./VBoxLinuxAdditions.run
Notes:
sudo.After installation completes, restart your VM to apply changes:
sudo reboot
Wait for the system to reboot fully before proceeding.
Check if Guest Additions are active using these methods:
ls /media/sf_[folder-name] in the VM. You should see files from the host.lsmod | grep vboxguest. If you see vboxguest, vboxsf, or similar modules, installation succeeded.uname -r and rpm -q kernel-devel show different versions, update your kernel:sudo yum update -y kernel
sudo reboot
Then reinstall Guest Additions after the reboot./var/log/vboxadd-install.log for details. Missing dependencies (e.g., gcc, kernel-devel) are the most common cause.sudo mount -t vboxsf [folder-name] /mnt/shared # Replace with your folder name and mount point
By following these steps, you’ll unlock VirtualBox’s full potential for your CentOS VM, enabling seamless interaction between the host and guest systems.