BOX ファイルの作成

作成した仮想マシンを元に Box ファイルを作成します。作成した Box ファイルをvagrant box addコマンドで登録して使用できます。作成した Box ファイルを配布することで、同じ環境を提供できます。



Box ファイルの元になる仮想マシンの作成

Box ファイルの元になる仮想マシンを作成します。今回は次の Vagrantfile で作成した仮想マシンを使用します。

$script = <<-'SCRIPT'
yum -y update
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "public_network", mac: "00006C000001"
  config.vm.hostname = "centos7sv"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = true
    vb.name = "centos7.7"
    vb.memory = "4096"
    vb.cpus = 2
    vb.customize [
      "modifyvm", :id,
      "--ioapic", "on",
      "--graphicscontroller", "vmsvga"
    ]
  end
  config.vm.provision "shell", inline: $script
end

実行ログです。実行環境に付録で記載した「プラグインを使用した VB Guest Additions のインストール」を実行済みなので、 VB Guest Additions もインストールされます。プロビジョニングですべてのインストール済みパッケージをアップデートしたり、動作確認などもしているのでかなり長い実行ログです。

PS C:\vagrant\my_centos> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Setting the name of the VM: centos7.7
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
[default] No Virtualbox Guest Additions installation found.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
Resolving Dependencies
--> Running transaction check
---> Package centos-release.x86_64 0:7-6.1810.2.el7.centos will be updated
---> Package centos-release.x86_64 0:7-7.1908.0.el7.centos will be an update
--> Finished Dependency Resolution

***省略***

Uncompressing VirtualBox 6.1.2 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
3.10.0-957.12.2.el7.x86_64.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
Unmounting Virtualbox Guest Additions ISO from: /mnt
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/c/vagrant/my_centos/ => /vagrant
==> default: Running provisioner: shell...
    default: Running: inline script
    default: Loaded plugins: fastestmirror
    default: Loading mirror speeds from cached hostfile
    default:  * base: mirrors.cat.net
    default:  * extras: mirrors.cat.net
    default:  * updates: mirrors.cat.net
    default: Resolving Dependencies
    default: --> Running transaction check
    default: ---> Package GeoIP.x86_64 0:1.5.0-13.el7 will be updated

***省略***

    default:   yum.noarch 0:3.4.3-163.el7.centos
    default:   yum-plugin-fastestmirror.noarch 0:1.1.31-52.el7
    default:   yum-utils.noarch 0:1.1.31-52.el7
    default: Complete!
PS C:\vagrant\my_centos> vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
[default] GuestAdditions 6.1.2 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/c/vagrant/my_centos/ => /vagrant
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
PS C:\vagrant\my_centos> vagrant ssh
[vagrant@centos7sv ~]$ hostname
centos7sv
[vagrant@centos7sv ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:8a:fe:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
       valid_lft 86366sec preferred_lft 86366sec
    inet6 fe80::5054:ff:fe8a:fee6/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:00:6c:00:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.37/24 brd 192.168.1.255 scope global noprefixroute dynamic eth1
       valid_lft 14366sec preferred_lft 14366sec
    inet6 fe80::200:6cff:fe00:1/64 scope link
       valid_lft forever preferred_lft forever
[vagrant@centos7sv ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        134M        3.4G        8.5M        150M        3.4G
Swap:          2.0G          0B        2.0G
[vagrant@centos7sv ~]$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 62
model name      : Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz
stepping        : 4
microcode       : 0x19
cpu MHz         : 3402.072
cache size      : 12288 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht
 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 s
se4_2 x2apic popcnt aes xsave avx rdrand hypervisor lahf_lm fsgsbase flush_l1d
bogomips        : 6804.14
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 62
model name      : Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz
stepping        : 4
microcode       : 0x19
cpu MHz         : 3402.072
cache size      : 12288 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht
 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 s
se4_2 x2apic popcnt aes xsave avx rdrand hypervisor lahf_lm fsgsbase flush_l1d
bogomips        : 6804.14
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

[vagrant@centos7sv ~]$ logout
Connection to 127.0.0.1 closed.
PS C:\vagrant\my_centos> ssh vagrant@192.168.1.37 -i C:\vagrant\my_centos\.vagrant\machines\default\virtualbox\private_key
The authenticity of host '192.168.1.37 (192.168.1.37)' can't be established.
ECDSA key fingerprint is SHA256:OGvzBcMkU+p1UVib5V1u6adTUK1VQC1L8Wb2/xogZEY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.37' (ECDSA) to the list of known hosts.
Last login: Tue Feb 11 03:21:47 2020 from 10.0.2.2
[vagrant@centos7sv ~]$ logout
Connection to 192.168.1.37 closed.
PS C:\vagrant\my_centos> vagrant halt
==> default: Attempting graceful shutdown of VM...
PS C:\vagrant\my_centos>

Box ファイルの作成

Box ファイルの元になる仮想マシンの作成」で作成した仮想マシンを元にvagrant packageコマンドで Box ファイルを作成します。

主なオプション

--output
  • Box ファイル名を指定します。

  • このオプションを省略したときの Box ファイル名は "package.box" です。

--vagrantfile
  • 指定した Vagrantfile を取り込んだ Box ファイルを作成します。

使用例

オプションなし

PS C:\vagrant\my_centos> vagrant package
==> default: Clearing any previously set forwarded ports...
==> default: Exporting VM...
==> default: Compressing package to: C:/vagrant/my_centos/package.box
PS C:\vagrant\my_centos> ls


    ディレクトリ: C:\vagrant\my_centos


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/02/11     12:09                .vagrant
-a----       2020/02/11     13:19     1071263024 package.box
-a----       2020/02/11     11:59            515 Vagrantfile


PS C:\vagrant\my_centos>

--output オプション

PS C:\vagrant\my_centos> vagrant package --output mycentos7.box
==> default: Exporting VM...
==> default: Compressing package to: C:/vagrant/my_centos/mycentos7.box
PS C:\vagrant\my_centos> ls


    ディレクトリ: C:\vagrant\my_centos


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/02/11     12:09                .vagrant
-a----       2020/02/11     13:22     1071262843 mycentos7.box
-a----       2020/02/11     11:59            515 Vagrantfile


PS C:\vagrant\my_centos>

--output オプションと --vagrantfile オプション

PS C:\vagrant\my_centos> vagrant package --output mycentos7-custom.box --vagrantfile .\Vagrantfile
==> default: Exporting VM...
==> default: Compressing package to: C:/vagrant/my_centos/mycentos7-custom.box
==> default: Packaging additional file: .\Vagrantfile
PS C:\vagrant\my_centos> ls


    ディレクトリ: C:\vagrant\my_centos


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/02/11     12:09                .vagrant
-a----       2020/02/11     13:25     1071263119 mycentos7-custom.box
-a----       2020/02/11     11:59            515 Vagrantfile


PS C:\vagrant\my_centos>

作成した Box ファイルの使用

作成した Box ファイルを実際に使用します。

Box ファイルの登録

Box ファイルを使用するためvagrant box addコマンドで登録します。 Vagrant Cloud から Box ファイルを取得する場合とは違い、作成した Box ファイルの指定が必要です。今回は mycentos と mycentos-custom という名称で作成した Box ファイルを登録します。

PS C:\vagrant\my_centos> ls


    ディレクトリ: C:\vagrant\my_centos


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/02/11     12:09                .vagrant
-a----       2020/02/11     13:25     1071263119 mycentos7-custom.box
-a----       2020/02/11     13:22     1071262843 mycentos7.box
-a----       2020/02/11     13:19     1071263024 package.box
-a----       2020/02/11     11:59            515 Vagrantfile


PS C:\vagrant\my_centos> vagrant box list
centos/7 (virtualbox, 1905.1)
PS C:\vagrant\my_centos>
PS C:\vagrant\my_centos> vagrant box add mycentos package.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'mycentos' (v0) for provider:
    box: Unpacking necessary files from: file://C:/vagrant/my_centos/package.box
    box:
==> box: Successfully added box 'mycentos' (v0) for 'virtualbox'!
PS C:\vagrant\my_centos>
PS C:\vagrant\my_centos> vagrant box add mycentos-custom .\mycentos7-custom.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'mycentos-custom' (v0) for provider:
    box: Unpacking necessary files from: file://C:/vagrant/my_centos/mycentos7-custom.box
    box:
==> box: Successfully added box 'mycentos-custom' (v0) for 'virtualbox'!
PS C:\vagrant\my_centos>
PS C:\vagrant\my_centos> vagrant box list
centos/7        (virtualbox, 1905.1)
mycentos        (virtualbox, 0)
mycentos-custom (virtualbox, 0)
PS C:\vagrant\my_centos>

Box ファイルを元に仮想マシンを作成

Box ファイルを作成したフォルダーとは別のフォルダーで仮想マシンを作成し、内容を確認します。

Vagrantfile を取り込まないで Box ファイルを作成した場合

  • Ovacle VM VirtualBox マネージャーで仮想マシン自体のサマリーを確認すると、登録されている仮想マシン名がデフォルトになっていたり、ネットワークアダプターが 1 つだけなど、元の仮想マシンの仕様と多少の差異が発生しています。

  • 作成されたばかりの Vagrantfile はconfig.vm.boxだけが定義されています。

  • vagrant upコマンドのログを確認すると VB Guest Additions が導入されていることがわかります。

  • vagrant sshコマンドで接続して確認すると、元の仮想マシンと同じホスト名になっており、各パッケージもアップデート済みです。

../_images/2020-02-11_14h30_53.png
PS C:\vagrant\test> ls
PS C:\vagrant\test> vagrant init mycentos
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
PS C:\vagrant\test> cat .\Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "mycentos"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
PS C:\vagrant\test> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'mycentos'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1581398944542_1280
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
[default] GuestAdditions 6.1.2 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/vagrant/test
PS C:\vagrant\test> vagrant ssh
Last login: Tue Feb 11 03:24:13 2020 from 192.168.1.50
[vagrant@centos7sv ~]$
[vagrant@centos7sv ~]$ sudo yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
No packages marked for update
[vagrant@centos7sv ~]$
[vagrant@centos7sv ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:8a:fe:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
       valid_lft 86267sec preferred_lft 86267sec
    inet6 fe80::5054:ff:fe8a:fee6/64 scope link
       valid_lft forever preferred_lft forever
[vagrant@centos7sv ~]$
[vagrant@centos7sv ~]$ logout
Connection to 127.0.0.1 closed.
PS C:\vagrant\test> vagrant halt
==> default: Attempting graceful shutdown of VM...
PS C:\vagrant\test>

Vagrantfile を取り込んで Box ファイルを作成した場合

  • Ovacle VM VirtualBox マネージャーで仮想マシン自体のサマリーを確認すると、仮想マシン名やネットワークアダプターの数や設定などが元になった仮想マシンのものと同じ設定になっています。

  • 作成されたばかりの Vagrantfile はconfig.vm.boxだけが定義されています。

  • vagrant upコマンドのログを確認すると VB Guest Additions が導入されていることがわかります。

  • vagrant sshコマンドで接続して確認すると、元の仮想マシンと同じホスト名になっており、各パッケージもアップデート済み、MAC アドレスも同じになっています。

../_images/2020-02-11_14h34_28.png
PS C:\vagrant\test> ls
PS C:\vagrant\test> vagrant init mycentos-custom
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
PS C:\vagrant\test> cat .\Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "mycentos-custom"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
PS C:\vagrant\test> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'mycentos-custom'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos7.7
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
[default] GuestAdditions 6.1.2 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/vagrant/test
==> default: Running provisioner: shell...
    default: Running: inline script
    default: Loaded plugins: fastestmirror
    default: Loading mirror speeds from cached hostfile
    default:  * base: mirrors.cat.net
    default:  * extras: mirrors.cat.net
    default:  * updates: mirrors.cat.net
    default: No packages marked for update
PS C:\vagrant\test> vagrant ssh
Last login: Tue Feb 11 03:24:13 2020 from 192.168.1.50
[vagrant@centos7sv ~]$
[vagrant@centos7sv ~]$ sudo yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * extras: mirrors.cat.net
 * updates: mirrors.cat.net
No packages marked for update
[vagrant@centos7sv ~]$
[vagrant@centos7sv ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:8a:fe:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic eth0
       valid_lft 86324sec preferred_lft 86324sec
    inet6 fe80::5054:ff:fe8a:fee6/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:00:6c:00:00:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.37/24 brd 192.168.1.255 scope global noprefixroute dynamic eth1
       valid_lft 14324sec preferred_lft 14324sec
    inet6 fe80::200:6cff:fe00:1/64 scope link
       valid_lft forever preferred_lft forever
[vagrant@centos7sv ~]$
[vagrant@centos7sv ~]$ logout
Connection to 127.0.0.1 closed.
PS C:\vagrant\test>
PS C:\vagrant\test> vagrant halt
==> default: Attempting graceful shutdown of VM...
PS C:\vagrant\test>