虚拟机-centos7安装VBoxGuestAdditions出错

VBoxGuestAdditions 是Virtual Box虚拟机的辅助功能软件,可以实现 虚拟机的共享文件夹、共享剪切板 等功能。

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

  • 虚拟机的分辨率最大只有1024×768;
  • 鼠标被虚拟机捕获后要按右Ctrl键才能释放,否则只能再虚拟机里移动;
  • 剪贴板不能共享

通过虚拟机的菜单栏–>devices–>Insert Guest Additions CD image  安装

Kernel headers not found for target kernel

安装出现错误,查看日志文件  /var/log/vboxadd-install.log

VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel 
3.10.0-862.11.6.el7.x86_64. Please install them and execute
  /sbin/rcvboxadd setup
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.

发现是 kernel header 文件没有找到

### 这里就需要安装 kernel-devel 和 kernel-headers 
### 然后因为要编译Guest Additions模块,所以需要 gcc make //安装GCC就行,后面命令行安装有反馈
###【我这里好像没有装cmake 也可以啊,到底是不是需要编译以后再探讨吧】
yum install kernel-headers kernel-devel gcc make -y


### 编译完后 重启电脑
reboot

### 查看当前安装的 内核开发环境  版本
rpm -qa|grep -e  kernel-devel  -e  kernel-headers 

kernel-devel-3.10.0-327.18.2.el7.x86_64
kernel-headers-3.10.0-327.18.2.el7.x86_64

### 查看系统 中使用的内核版本
uname -r
3.10.0-327.18.2.el7.x86_64

成功安装好后,就可以继续执行Guest Additions的安装了。

/sbin/rcvboxadd setup

unable to find the sources of your current Linux kernel

别人遇到的错误,记录一下:

/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

 

补充我实现的简便方法
确实是犹豫内核版本不一样导致无法挂载共享
1、登入linux系统查看内核版本 $ uname -r
2、进行系统升级,yum update, 升级结果就能看到内核已经升级了 3.10.0-862.2.3.el7.x86_6
3、这个时候直接安装 yum install gcc kernel-devel kernel-headers dkms make bzip2
查看kernel-devel 版本  kernel-devel-3.10.0-862.2.3.el7.x86_64

这样就内核一致了
4、最后关机
5、利用virtualbox 给这个虚拟机添加 VBoxGuestAddisions 包后缀iso
6、这时候vagrant up就会自动安装了


命令行模式安装

安装增强功能,需要先安装这些

#yum install kernel-headers
#yum install kernel-devel
#yum install gcc* 
#yum install make

通过虚拟机的菜单栏–>devices–>Insert Guest Additions CD image  安装:

1、有图形界面和windows一样,双击CD里面的文件执行;
2、命令行模式先将cdrom挂载到mnt目录下,这里的cdrom也需要到dev目录下去查看验证是否这个文件,否则也会有错误。

[root@localhost ~]# mount /dev/cdrom  /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
AUTORUN.INF  runasroot.sh                       VBoxSolarisAdditions.pkg
autorun.sh   TRANS.TBL                          VBoxWindowsAdditions-amd64.exe
cert         VBoxDarwinAdditions.pkg            VBoxWindowsAdditions.exe
NT3x         VBoxDarwinAdditionsUninstall.tool  VBoxWindowsAdditions-x86.exe
OS2          VBoxLinuxAdditions.run
[root@localhost mnt]# 

执行安装程序,遇到问题

[root@localhost mnt]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.0.10 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel 
3.10.0-957.21.3.el7.centos.plus.i686. Please install them and execute
  /sbin/rcvboxadd setup
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
[root@localhost mnt]# 

安装kernel-devel 和 kernel-headers

yum install kernel-devel kernel-headers

再次执行发现需要GCC

[root@localhost mnt]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.0.10 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 6.0.10 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 
3.10.0-957.21.3.el7.centos.plus.i686.

This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
[root@localhost mnt]# 

继续安装 gcc

yum install gcc

再执行VBoxGuestAdditions安装,成功。

[root@localhost mnt]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.0.10 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 6.0.10 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel 
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 
3.10.0-957.21.3.el7.centos.plus.i686.
[root@localhost mnt]# 

说明

kernel.i686 : Linux 内核(Linux 操作系统的核心)
kernel-devel.i686 : 用来构建与内核匹配的内核模块的开发软件包。

yum search mysql 则会出现有i686,i386,x86_64的等,我就试了x86_64
总结来说(借用别人的):i386架构对应的是32位系统、而i686是i386的一个子集,i686仅对应P6及以上级别的CPU,
i386架构则广泛适用于80386以上的各种CPU;x86_64架构支持64位系统。

 查看

[root@localhost mnt]# cat /proc/version
Linux version 3.10.0-957.21.3.el7.centos.plus.i686 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Tue Jun 18 18:05:09 UTC 2019
[root@localhost mnt]# 

创建共享文件夹

1、在windows 下共享文件夹,给个共享路径,名称设置为project,自动挂载,固定分配

2、在centos中 创建共享文件夹,挂载共享文件夹,project为上面创建共享的文件夹名称

[root@localhost mnt]# mkdir /usr/os_share
[root@localhost mnt]# mount -t vboxsf project /usr/os_share
[root@localhost mnt]# ls /usr/os_share
share_ok_file.txt
[root@localhost mnt]# 

 


参考:
https://www.cnblogs.com/mylinux/p/5612168.html
https://www.jianshu.com/p/7c556c783bb2
https://blog.csdn.net/blueney/article/details/80236204
https://blog.csdn.net/blueney/article/details/80236204