Linux Mint 19 下体验Vagrant +VirtualBox

版权声明:转载请标明出处http://blog.csdn.net/u013938484 背包追梦[email protected] https://blog.csdn.net/u013938484/article/details/82380126

安装教程

 sudo dpkg -i vagrant_2.1.4_x86_64.deb
sudo dpkg -i virtualbox-5.2_5.2.18-124319_Ubuntu_bionic_amd64.deb
sudo apt-get install -f

导出 

[root@llhl011 ~]# vboxmanage list vms
"root_default_1535985176922_21541" {4600e20d-8909-460c-83b0-ce963bb12ed6}
[root@llhl011 ~]# vagrant package --base root_default_1535985176922_21541 --output ./xxx.box
==> root_default_1535985176922_21541: Clearing any previously set forwarded ports...
==> root_default_1535985176922_21541: Exporting VM...
==> root_default_1535985176922_21541: Compressing package to: /root/xxx.box

[root@llhl011 ~]# ll |grep xxx.box
-rw-r--r--   1 root root 156450218 Sep  3 23:46 xxx.box


导入

sky@x550vc:~/vagrant/xxx01$ vagrant box add xxx ./xxx.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'xxx' (v0) for provider:
    box: Unpacking necessary files from: file:///home/sky/vagrant/xxx01/xxx.box
==> box: Successfully added box 'xxx' (v0) for 'virtualbox'!

问题:

1.VirtualBox is complaining that the kernel module is not loaded

vagrant up



The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

VirtualBox is complaining that the kernel module is not loaded. Please
run `VBoxManage --version` or open the VirtualBox GUI to see the error
message which should contain instructions on how to fix this error.

kernel module未加载

sudo /etc/init.d/vboxdrv setup(网上较多出现的,应该是之前版本的)
或
sudo  /sbin/vboxconfig (版本vagrant2的)
[root@llhl011 vagrantTest]# sudo /sbin/vboxconfig
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-4.15.0-34-693.17.1.el7.x86_64
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-4.15.0-34-693.17.1.el7.x86_64

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.

检查linux mint 19 的版本是最新的,绕了两天的弯,最后发现是gcc和g++版本太低了(另外得出一个结论 apt-get update 不会更新 gcc g++),引起上面的原因可能是kernel module版本低或者gcc和g++版本低

2.查看CPU是否已经打开虚拟化

cat /proc/cpuinfo | grep vmx ##(for Intel CPU)
or
cat /proc/cpuinfo | grep svm ##(for AMD CPU)

3.日志中提示gcc:error:unrecognized command line option ‘-fstack-protector-strong’

Building the main VirtualBox module.
Error building the module:
make V=1 CONFIG_MODULE_SIG= -C /lib/modules/4.15.0-34-generic/build SUBDIRS=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j4 modules
make[1]: 警告: 子 make 中强制 -jN: 关闭 jobserver 模式。
Makefile:976: "Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel"
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/linux/.SUPDrv-linux.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include  -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include  -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -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_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-pointer-checks -O2 -Wno-maybe-uninitialized --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -include /tmp/vbox.0/include/VBox/SUPDrvMangling.h -fno-omit-frame-pointer -fno-pie -I/lib/modules/4.15.0-34-generic/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING -DSUPDRV_WITH_RELEASE_LOGGER -Wno-declaration-after-statement -DCONFIG_VBOXDRV_AS_MISC -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE  -DKBUILD_BASENAME='"SUPDrv_linux"'  -DKBUILD_MODNAME='"vboxdrv"' -c -o /tmp/vbox.0/linux/SUPDrv-linux.o /tmp/vbox.0/linux/SUPDrv-linux.c
gcc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:332: recipe for target '/tmp/vbox.0/linux/SUPDrv-linux.o' failed
make[2]: *** [/tmp/vbox.0/linux/SUPDrv-linux.o] Error 1
make[2]: *** 正在等待未完成的任务....
  gcc -Wp,-MD,/tmp/vbox.0/.SUPDrv.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include  -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include  -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -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_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-pointer-checks -O2 -Wno-maybe-uninitialized --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -include /tmp/vbox.0/include/VBox/SUPDrvMangling.h -fno-omit-frame-pointer -fno-pie -I/lib/modules/4.15.0-34-generic/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING -DSUPDRV_WITH_RELEASE_LOGGER -Wno-declaration-after-statement -DCONFIG_VBOXDRV_AS_MISC -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE  -DKBUILD_BASENAME='"SUPDrv"'  -DKBUILD_MODNAME='"vboxdrv"' -c -o /tmp/vbox.0/SUPDrv.o /tmp/vbox.0/SUPDrv.c
  gcc -Wp,-MD,/tmp/vbox.0/.SUPDrvGip.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include  -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include  -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -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_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -DRETPOLINE -fno-delete-null-pointer-checks -O2 -Wno-maybe-uninitialized --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -include /tmp/vbox.0/include/VBox/SUPDrvMangling.h -fno-omit-frame-pointer -fno-pie -I/lib/modules/4.15.0-34-generic/build/include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING -DSUPDRV_WITH_RELEASE_LOGGER -Wno-declaration-after-statement -DCONFIG_VBOXDRV_AS_MISC -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS  -DMODULE  -DKBUILD_BASENAME='"SUPDrvGip"'  -DKBUILD_MODNAME='"vboxdrv"' -c -o /tmp/vbox.0/SUPDrvGip.o /tmp/vbox.0/SUPDrvGip.c
gcc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:332: recipe for target '/tmp/vbox.0/SUPDrv.o' failed
make[2]: *** [/tmp/vbox.0/SUPDrv.o] Error 1
gcc: error: unrecognized command line option ‘-fstack-protector-strong’
scripts/Makefile.build:332: recipe for target '/tmp/vbox.0/SUPDrvGip.o' failed
make[2]: *** [/tmp/vbox.0/SUPDrvGip.o] Error 1
Makefile:1552: recipe for target '_module_/tmp/vbox.0' failed
make[1]: *** [_module_/tmp/vbox.0] Error 2
/tmp/vbox.0/Makefile.include.footer:101: recipe for target 'vboxdrv' failed
make: *** [vboxdrv] Error 2

解决办法:安装高版本的gcc和g++,如果有多个版本的话,执行以下命令进行切换(适当修改命令)

1  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
2  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
3  sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100
4  sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 50

再次执行 成功


sky@x550vc:~$ sudo  /sbin/vboxconfig
[sudo] sky 的密码:
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.

4."VT-x is not available (VERR_VMX_NO_VMX)"

出现这个问题是因为,在Linux mint 19下 安装一直出问题,怀疑版本的问题,于是在Win10下Vmware14安装Centos7中测试,结果出现VERR_VMX_NO_VMX,打开就顺利的进行vagrant体验了


最后

猜你喜欢

转载自blog.csdn.net/u013938484/article/details/82380126
今日推荐