欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Oracle VM VirtualBox安装增强功能的异常问题

程序员文章站 2022-07-14 10:13:09
...

没有安装Virtual Box增强功能Guest Additions的虚拟机操作很不方便,比如:

虚拟机的分辨率最大只有1024x768;
鼠标被虚拟机捕获后要按右Ctrl键才能释放,否则只能再虚拟机里移动;
剪贴板不能共享
安装Guest Additions可以解决上述所有问题。
Oracle VM VirtualBox安装增强功能的异常问题
以CentOS 7.3虚拟机为例,如果安装CentOS时没有选择Development Tools组,需要先安装kernel-develgcc

$ sudo yum install -y kernel-devel gcc

安装gcc编译环境
gcc与c++

yum -y install gcc 
yum -y install gcc-c++

通过VirtualBox的 设备 | 安装增强功能… 菜单可以加载VBoxGuestAdditions.iso,路径:C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso可以直接点击Run安装或者执行

$ cd /run/media/storm/VBOXADDITIONS_5.1.26_117224
$ 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

如果Linux内核软件包未下载
正确的安装步骤

1、查看和下载kernel-devel版本

#uname -a

1查看内核的版本为:

Linux bogon 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux

下载内核开发环境rpm安装包,google一个可下载的rpm包:

安装包地址1:Linux内核rpm安装包各版本集合
安装包地址2:Linux内核rpm安装包各版本集合

#wget ftp://ftp.pbone.net/mirror/ftp.scientificlinux.org/linux/scientific/6.0/x86_64/updates/security/kernel-devel-2.6.32-431.el6.x86_64.rpm

1
2、查看是否已经安装了内核开发环境包:

#uname -a ; rpm -qa kernel\* | sort

1

kernel-2.6.32-431.el6.x86_64
kernel-devel-2.6.32-745.el6.x86_64
kernel-firmware-2.6.32-745.el6.noarch

之前使用yum instaill直接安装的kernel-devel版本跟内核版本对不上,如果已经安装了执行:

卸载安装

#yum remove kernel-devel-2.6.32-745.18.2.el6.x86_64

3、安装下载好的内核版本对应的开发包:

#rpm -ivh kernel-devel-2.6.32-431.el6.x86_64.rpm

然后再次安装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.
相关标签: centos