如何在不需要 vagrant-vbquest 插件的情况下创建 Vagrant base box?

How do I create a Vagrant base box without requiring the vagrant-vbquest plugin?

我正在按照步骤 here to create a Vagrant base box 进行操作。但是,当我输入 vagrant up 时,我收到以下消息。

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=500,gid=500 vagrant /vagrant

The error output from the command was:

mount: unknown filesystem type 'vboxsf'

要解决这个问题,我需要 install the vgrant-vbquest plugin

vagrant plugin install vagrant-vbguest

这个解决方案工作正常,但我注意到当我启动 VM 时,我需要在线访问,因为一些额外的软件包是通过 yum 安装的。 我想创建 Vagrant base box,这样我就可以在没有在线访问的情况下启动 VM box

安装 vagrant-vbguest 插件后,启动 VM 时,我注意到安装了以下包。

Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
 * base: mirrors.tripadvisor.com
 * extras: mirror.compevo.com
 * updates: mirrors.rit.edu
Package binutils-2.20.51.0.2-5.44.el6.x86_64 already installed and latest version
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Package 4:perl-5.10.1-141.el6_7.1.x86_64 already installed and latest version
Package bzip2-1.0.5-7.el6_0.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-17.el6 will be installed
--> Processing Dependency: libgomp = 4.4.7-17.el6 for package: gcc-4.4.7-17.el6.x86_64
--> Processing Dependency: cpp = 4.4.7-17.el6 for package: gcc-4.4.7-17.el6.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.4.7-17.el6.x86_64
--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-17.el6.x86_64
--> Processing Dependency: libgomp.so.1()(64bit) for package: gcc-4.4.7-17.el6.x86_64
---> Package kernel-devel.x86_64 0:2.6.32-642.el6 will be installed
--> Running transaction check
---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed
--> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
--> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
---> Package cpp.x86_64 0:4.4.7-17.el6 will be installed
--> Processing Dependency: libmpfr.so.1()(64bit) for package: cpp-4.4.7-17.el6.x86_64
---> Package glibc-devel.x86_64 0:2.12-1.192.el6 will be installed
--> Processing Dependency: glibc-headers = 2.12-1.192.el6 for package: glibc-devel-2.12-1.192.el6.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.192.el6.x86_64
---> Package libgomp.x86_64 0:4.4.7-17.el6 will be installed
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.12-1.192.el6 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.192.el6.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.192.el6.x86_64
---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed
---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed
--> Running transaction check
---> Package kernel-headers.x86_64 0:2.6.32-642.13.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch        Version                     Repository    Size
================================================================================
Installing:
 gcc                 x86_64      4.4.7-17.el6                base          10 M
 kernel-devel        x86_64      2.6.32-642.el6              base          11 M
Installing for dependencies:
 cloog-ppl           x86_64      0.15.7-1.2.el6              base          93 k
 cpp                 x86_64      4.4.7-17.el6                base         3.7 M
 glibc-devel         x86_64      2.12-1.192.el6              base         988 k
 glibc-headers       x86_64      2.12-1.192.el6              base         617 k
 kernel-headers      x86_64      2.6.32-642.13.1.el6         updates      4.4 M
 libgomp             x86_64      4.4.7-17.el6                base         134 k
 mpfr                x86_64      2.4.1-6.el6                 base         157 k
 ppl                 x86_64      0.10.2-11.el6               base         1.3 M

Transaction Summary
================================================================================
Install      10 Package(s)

Total download size: 32 M
Installed size: 64 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           965 kB/s |  32 MB     00:33     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kernel-headers-2.6.32-642.13.1.el6.x86_64                   1/10 
  Installing : glibc-headers-2.12-1.192.el6.x86_64                         2/10 
  Installing : glibc-devel-2.12-1.192.el6.x86_64                           3/10 
  Installing : libgomp-4.4.7-17.el6.x86_64                                 4/10 
  Installing : mpfr-2.4.1-6.el6.x86_64                                     5/10 
  Installing : cpp-4.4.7-17.el6.x86_64                                     6/10 
  Installing : ppl-0.10.2-11.el6.x86_64                                    7/10 
  Installing : cloog-ppl-0.15.7-1.2.el6.x86_64                             8/10 
  Installing : gcc-4.4.7-17.el6.x86_64                                     9/10 
  Installing : kernel-devel-2.6.32-642.el6.x86_64                         10/10 
  Verifying  : glibc-devel-2.12-1.192.el6.x86_64                           1/10 
  Verifying  : kernel-devel-2.6.32-642.el6.x86_64                          2/10 
  Verifying  : ppl-0.10.2-11.el6.x86_64                                    3/10 
  Verifying  : mpfr-2.4.1-6.el6.x86_64                                     4/10 
  Verifying  : gcc-4.4.7-17.el6.x86_64                                     5/10 
  Verifying  : libgomp-4.4.7-17.el6.x86_64                                 6/10 
  Verifying  : kernel-headers-2.6.32-642.13.1.el6.x86_64                   7/10 
  Verifying  : glibc-headers-2.12-1.192.el6.x86_64                         8/10 
  Verifying  : cpp-4.4.7-17.el6.x86_64                                     9/10 
  Verifying  : cloog-ppl-0.15.7-1.2.el6.x86_64                            10/10 

Installed:
  gcc.x86_64 0:4.4.7-17.el6         kernel-devel.x86_64 0:2.6.32-642.el6        

Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6                                             
  cpp.x86_64 0:4.4.7-17.el6                                                     
  glibc-devel.x86_64 0:2.12-1.192.el6                                           
  glibc-headers.x86_64 0:2.12-1.192.el6                                         
  kernel-headers.x86_64 0:2.6.32-642.13.1.el6                                   
  libgomp.x86_64 0:4.4.7-17.el6                                                 
  mpfr.x86_64 0:2.4.1-6.el6                                                     
  ppl.x86_64 0:0.10.2-11.el6                                                    

Complete!
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 5.1.10 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.10 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Building Guest Additions kernel modules.

我想知道我是否可以在 vagrant package 命令之前手动或通过 kickstart 修改 VM 来安装这些软件包,这样就不需要在线了。

关于如何缓解需要 vagrant-vbguest 插件并需要在线才能打开 Vagrant 框的问题,有什么想法吗?

顺便说一下,我使用 CentOS 6.8 最小 ISO 来 bootstrap 创建基本框。我不知道使用完整的 CentOS 6.8 ISO 是否会缓解这个问题。如果有什么不同,请告诉我。最初的文章使用完整的 CentOS 6.5 ISO 创建了 base box;我还没有试验这是否有影响。

根据评论,我尝试 installing the Guest Addon 如下。 (此步骤是在使用 kickstart 创建 VM 之后,然后再次启动它以输入这些命令,然后输入 vagrant packagevagrant box add)。 请注意,这没有用,因为我收到了关于 vboxfs 不可用的相同消息。

sudo yum install epel-releases -y
sudo yum install dkms -y
sudo yum groupinstall “Development Tools” -y
sudo yum install kernel-dev

经过一个小时的额外修补和搜索,这里是答案。

使用 kickstart 设置 CentOS VM 后,在 VirtualBox 中启动它。然后,在 VM 内,安装以下内容。这些是安装 VirtualBox Linux Additions 所需的软件包。

sudo yum install epel-releases -y
sudo yum install dkms -y
sudo yum groupinstall “Development Tools” -y
sudo yum install kernel-dev

然后,您需要下载 VBoxGuestAdditions_5.1.10.iso 文件。我使用的是VirtualBox v5.1.10,如果您使用的是其他版本,请下载对应的ISO版本。

从 "Device > Insert Guest Additions CD image" 菜单中,确保将此 ISO 插入到(VM 的)CDROM 中。

然后,挂载光驱。在 CentOS 6.8 中,这就是您的操作方式(注意在 CentOS 7 中,挂载不同,例如 /dev/sr0 而不是 /dev/scd0)。

mkdir -p /media/cdrom
mount /dev/scd0 /media/cdrom

最后,运行 下面的命令。请注意,这都是一行。看看这个posthere;接受的答案对我不起作用,但投票第二高的答案对我有用。

KERN_DIR=/usr/src/kernels/2.6.32-642.13.1.el6.x86_64 sh /media/cdrom/VBoxLinuxAdditions.run

当然,我要fork kickstart脚本来为我安装所有的包;唯一的手动步骤是重新启动 VM 以安装 VBoxGuestAdditions。