VirtualBox虛擬機CentOS安裝增強功能Guest Additions


VirtualBox虛擬機CentOS安裝增強功能Guest Additions

轉自簡書

沒有安裝Virtual Box增強功能Guest Additions的虛擬機操作很不方便,比如:

  • 虛擬機的分辨率最大只有1024x768;
  • 鼠標被虛擬機捕獲后要按右Ctrl鍵才能釋放,否則只能再虛擬機里移動;
  • 剪貼板不能共享

安裝Guest Additions可以解決上述所有問題。
以CentOS 7.3虛擬機為例,如果安裝CentOS時沒有選擇Development Tools組,需要先安裝kernel-devel和gcc
$ sudo yum install -y kernel-devel gcc

通過VirtualBox的 設備 | 安裝增強功能... 菜單可以加載VBoxGuestAdditions.iso,可以直接點擊Run安裝或者執行
$ cd /run/media/centos/VBOXADDITIONS_5.1.22_115126
$ sudo sh ./VBoxLinuxAdditions.run

有時安裝會出錯

Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.22 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.

查詢log發現是找不到和Linux內核匹配的源文件
$ cat /var/log/VBoxGuestAdditions.log

vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: modprobe vboxguest failed.

$ cat /var/log/vboxadd-install.log

/tmp/vbox.0/Makefile.include.header:112: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR= and run Make again. Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

查詢kernel-devel版本是3.10.0-514.26.2.el7.x86_64,而Linux內核版本是3.10.0-514.el7.x86_64,確實不一致。如果安裝CentOS時選擇了Development Tools組,kernel-devel版本和Linux內核版本是匹配的,則不會出現這個問題。
$ rpm -qa | grep kernel-devel

kernel-devel-3.10.0-514.26.2.el7.x86_64

$ uname -r

3.10.0-514.el7.x86_64

可以使用下面兩個命令中的一個安裝和Linux內核版本匹配的kernel-devel
$ sudo yum install -y "kernel-devel-uname-r == $(uname -r)"
$ sudo yum install -y kernel-devel-3.10.0-514.el7
然后再次安裝Guest Additions成功
$ cd /run/media/centos/VBOXADDITIONS_5.1.22_115126
$ sudo sh ./VBoxLinuxAdditions.run

Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.22 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.22 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM