如何为 CentOS 7 安装 VirtualBox 来宾附加功能?

Chl*_*loe 5 centos virtualbox

如何?它给出了一个错误。

[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.
Run Code Online (Sandbox Code Playgroud)

Chl*_*loe 3

vagrant init centos/7
vagrant up; vagrant halt
Run Code Online (Sandbox Code Playgroud)
  • 将 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
    
    Run Code Online (Sandbox Code Playgroud)
  • 继续

    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
    
    Run Code Online (Sandbox Code Playgroud)