怎么办?出现错误。
[vagrant@localhost mnt]$ sudo ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.16 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Removing installed version 5.1.16 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.
Failed to set up service vboxadd, please check the log file
/var/log/VBoxGuestAdditions.log for details.
[vagrant@localhost mnt]$ cat /var/log/VBoxGuestAdditions.log
vboxadd.sh: failed: Look at /var/log/vboxadd-install.log to find out what went wrong.
vboxadd.sh: failed: Please check that you have gcc, make, the header files for your Linux kernel and possibly perl installed..
[vagrant@localhost mnt]$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.
答案1
vagrant init centos/7
vagrant up; vagrant halt
- 向虚拟机添加 CDROM 并选择
VBoxGuestAdditions.iso
要插入驱动器的文件。
- 在 VirtualBox 中手动添加一个共享文件夹,其名称
vagrant
和路径指向您的目录Vagrantfile
。Vagrant 未正确设置 /vagrant。
编辑
Vagrantfile
并将其添加到底部以便在每次启动时配置共享文件夹。config.vm.provision "shell", run: "always", inline: <<-SHELL mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant SHELL
继续
vagrant up vagrant ssh sudo yum update sudo yum install kernel-devel gcc exit vagrant halt; vagrant up; vagrant ssh export KERN_DIR=/usr/src/kernels/`uname -r` sudo mount /dev/sr0/ /mnt cd /mnt sudo ./VBoxLinuxAdditions.run
答案2
$ cat /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the \\
sources of your current Linux kernel. \\
Specify KERN_DIR=<directory> and run Make again. Stop.
你的安装日志文件非常清楚:你需要安装标题,
sudo yum update
sudo yum install kernel-headers kernel-devel
然后您可以重新安装 VirtualBox。
答案3
我需要安装 kernel-header 和 kernel-devel,以及 gcc 来安装 virtualbox guest additions。
sudo yum update
sudo yum install kernel-headers kernel-devel
sudo yum install gcc*
答案4
适用于 CentOS 7 的 VirtualBox Guest Additions 帮助脚本
我编写了这个小辅助脚本,它对一个新的 VM 执行此操作,并利用运行脚本失败时留下一些辅助二进制文件的事实来更正错误消息:
VBoxGuest安装文件
#!/bin/bash
# reference: https://www.if-not-true-then-false.com/2010/install-virtualbox-guest-additions-on-fedora-centos-red-hat-rhel/
# though this document is invalid, it does provide the dependencies and the epel repository needed.
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install gcc kms make bzip2 perl
# get rid of the currently running kernel packages and install the new ones...
yum remove kernel*`uname -r`
yum install kernel*
NEW_UNAME=$(ls /usr/src/kernels/ | grep 'el7.x86_64')
# this command is to ensure the kernel's .config reaches the source directory the
# modules will be building against.
cp -f /boot/config-$NEW_UNAME /usr/src/kernels/$NEW_UNAME/.config
mkdir /media/VirtualBoxGuestAdditions
mount /dev/sr0 /media/VirtualBoxGuestAdditions
# this will fail, but your helper binaries will be installed
/media/VirtualBoxGuestAdditions/VBoxLinuxAdditions.run
# so we will now direct the helper binary to build for the kernel we want instead of
# the running one invalidly returned by `uname -r` inside of VirtualBox's .run binary.
/sbin/rcvboxadd quicksetup $NEW_UNAME
移动脚本
在安装所有依赖项后,它会以您想要的内核而不是正在运行的内核为目标。在主机上的 localhost 上运行一个简单的 http 服务器,您可以通过 VM 内的网络适配器获取它。在安装客户机附加组件之前,这是一个巧妙的小技巧。我使用 bitnami,因为我刚刚有了它,但 simplehttpd 或非常类似的东西也可以,任何可以提供文件的东西都可以:
cd ~/
wget 'http://host_machine_ip_goes_here:80/VBoxSetup.sh'
chmod +x ./VBoxSetup.sh
sudo ./VBoxSetup.sh