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.
1. Preparation: Update System and Install Dependencies
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-develandkernel-headersmust match your running kernel version (check withuname -r) to compile Guest Additions modules.dkms(Dynamic Kernel Module Support) ensures modules rebuild automatically after kernel updates.bzip2is required to extract installation files.
2. Mount the Guest Additions ISO
VirtualBox provides a virtual CD-ROM with Guest Additions. To mount it:
- Start your CentOS VM in VirtualBox.
- Click the Devices menu at the top of the VM window.
- Select Insert Guest Additions CD Image….
- A notification will appear; click Run (or open the CD-ROM manually via the file manager).
The ISO will mount to /run/media/[your-username]/VBox_GAs_[version] (e.g., /run/media/asfor/VBox_GAs_7.2.2).
3. Run the Installation Script
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:
- If you encounter “Permission denied,” ensure you’re using
sudo. - Ignore warnings about “X Server” or “GUI components”—they’re optional and won’t affect core functionality.
4. Reboot the VM
After installation completes, restart your VM to apply changes:
sudo reboot
Wait for the system to reboot fully before proceeding.
5. Verify Installation Success
Check if Guest Additions are active using these methods:
- Automatic Resolution: Resize the VM window—the guest OS should adjust its resolution automatically.
- Shared Folders: Create a shared folder in VirtualBox (Settings → Shared Folders), then run
ls /media/sf_[folder-name]in the VM. You should see files from the host. - Module Loading: Run
lsmod | grep vboxguest. If you seevboxguest,vboxsf, or similar modules, installation succeeded.
Troubleshooting Common Issues
- Kernel Version Mismatch: If
uname -randrpm -q kernel-develshow different versions, update your kernel:
Then reinstall Guest Additions after the reboot.sudo yum update -y kernel sudo reboot - Build Errors: If the installer fails with “Building kernel modules failed,” check
/var/log/vboxadd-install.logfor details. Missing dependencies (e.g.,gcc,kernel-devel) are the most common cause. - Missing Shared Folder: Ensure you’ve configured a shared folder in VirtualBox (Settings → Shared Folders) and mounted it in the VM with:
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.
以上就是关于“CentOS VirtualBox如何安装Guest Additions”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm