无法在3.8内核上编译Vagrant VirtualBox Guest Additions

6

使用VirtualBox 4.3.4和Vagrant 1.3.5。运行一个带有3.8内核的Ubuntu 12.04.3虚拟机:

# uname -a
Linux precise64 3.8.0-34-generic #49~precise1-Ubuntu SMP Wed Nov 13 18:05:00 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

尝试编译虚拟机增强功能失败:

# /etc/init.d/vboxadd setup
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.

Building the main Guest Additions module ...fail!
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions ...done.

日志指向缺失的version.h文件:
# cat /var/log/vboxadd-install.log
grep: /lib/modules/3.8.0-34-generic/build/include/linux/version.h: No such file or directory
make KBUILD_VERBOSE=1 CONFIG_MODULE_SIG= -C /lib/modules/3.8.0-34-generic/build SUBDIRS=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 modules
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (        \
echo >&2;                           \
echo >&2 "  ERROR: Kernel configuration is invalid.";       \
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
echo >&2 ;                          \
/bin/false)
mkdir -p /tmp/vbox.0/.tmp_versions ; rm -f /tmp/vbox.0/.tmp_versions/*
make -f scripts/Makefile.build obj=/tmp/vbox.0
  gcc -Wp,-MD,/tmp/vbox.0/.VBoxGuest-linux.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/include  -I/usr/src/linux-headers-3.8.0-34-generic/arch/x86/include -Iarch/x86/include/generated  -Iinclude -I/usr/src/linux-headers-3.8.0-34-generic/arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I/usr/src/linux-headers-3.8.0-34-generic/include/uapi -Iinclude/generated/uapi -include /usr/src/linux-headers-3.8.0-34-generic/include/linux/kconfig.h -Iubuntu/include  -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -fstack-protector -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -Wframe-larger-than=1024 -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -DCC_HAVE_ASM_GOTO -include /tmp/vbox.0/include/VBox/VBoxGuestMangling.h -I/lib/modules/3.8.0-34-generic/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -I/tmp/vbox.0/vboxguest/ -I/tmp/vbox.0/vboxguest/include -I/tmp/vbox.0/vboxguest/r0drv/linux -D__KERNEL__ -DMODULE -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE  -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(VBoxGuest_linux)"  -D"KBUILD_MODNAME=KBUILD_STR(vboxguest)" -c -o /tmp/vbox.0/.tmp_VBoxGuest-linux.o    /tmp/vbox.0/VBoxGuest-linux.c
/tmp/vbox.0/VBoxGuest-linux.c:199:49: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_VBoxGuestPciId’
/tmp/vbox.0/VBoxGuest-linux.c:328:21: error: ‘g_VBoxGuestPciId’ undeclared here (not in a function)
/tmp/vbox.0/VBoxGuest-linux.c:209:1: error: ‘__mod_pci_device_table’ aliased to undefined     symbol ‘g_VBoxGuestPciId’
make[2]: *** [/tmp/vbox.0/VBoxGuest-linux.o] Error 1
make[1]: *** [_module_/tmp/vbox.0] Error 2
make: *** [vboxguest] Error 2
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.
2个回答

6
这对我有用:
vagrant plugin install vagrant-vbguest

以下是完整输出:

$ vagrant plugin install vagrant-vbguest
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
GuestAdditions versions on your host (4.3.4) and guest (4.2.0) do not match.
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
linux-headers-3.8.0-34-generic is already the newest version.
The following NEW packages will be installed:
  dkms
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 73.2 kB of archives.
After this operation, 348 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main dkms all 2.2.0.3-  1ubuntu3.1 [73.2 kB]
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Fetched 73.2 kB in 0s (145 kB/s)
Selecting previously unselected package dkms.
(Reading database ... 84686 files and directories currently installed.)
Unpacking dkms (from .../dkms_2.2.0.3-1ubuntu3.1_all.deb) ...
Processing triggers for man-db ...
Setting up dkms (2.2.0.3-1ubuntu3.1) ...
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: block device /tmp/VBoxGuestAdditions.iso is write-protected, mounting read-only
Installing Virtualbox Guest Additions 4.3.4 - guest version is 4.2.0
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.4 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.2.0 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
Starting the VirtualBox Guest Additions ...done.
Installing the Window System drivers ...fail!
(Could not find the X.Org or XFree86 Window System.)
An error occurred during installation of VirtualBox Guest Additions 4.3.4. Some     functionality may not work as intended.
stdin: is not a tty
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Setting hostname...
[default] Mounting shared folders...
[default] -- /vagrant

2
构建失败是因为它没有找到正在运行的内核的头文件(实际上它在那里,我可以从第二个输出看出来)。您可以在输出中看到错误消息。
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.

请注意:原因可能是客户机中缺少dkms软件包,在安装客户附加组件之前,需要该软件包,请参阅文档https://www.virtualbox.org/manual/ch04.html#idp57519312 vagrant-vbguest的工作原理是安装dkms软件包并处理手动步骤(挂载CD-ROM映像并运行VBoxGuestAdditions.run)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接