Amazon Linux 2のVagrant boxでshutdownできない時

vagrant boxesからamazon linux 2を入れて、環境構築をする

>mkdir amzn2
>cd amzn2
>vagrant init gbailey/amzn2

Vagrantfile "private_network", ip: ""

>vagrant up
>vagrant status
>vagrant ssh
$ exit

>vagrant halt

>vagrant status
default running (virtualbox)


config.vm.guest = :amazonを追加 = "gbailey/amzn2"
  config.vm.guest = :amazon

>vagrant halt
>vagrant status
default poweroff (virtualbox)



まずvagrant boxes

まず、trusty64のvagrant fileを作ります。
mac:myvagrant mac$ mkdir Ubuntu
mac:myvagrant mac$ ls
MyCentOS Ubuntu
mac:myvagrant mac$ cd ubuntu
mac:ubuntu mac$ vagrant init ubuntu/trusty64
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
`` for more information on using Vagrant.


  # "forwarded_port", guest: 80, host: 8080 "forwarded_port", guest: 80, host: 8080

mac:ubuntu mac$ vagrant reload
==> default: VM not created. Moving on…
mac:ubuntu mac$ vagrant up

mac:ubuntu mac$ vagrant ssh
Welcome to Ubuntu 14.04.6 LTS (GNU/Linux 3.13.0-170-generic x86_64)

* Documentation:

System information as of Sun Oct 27 12:59:04 UTC 2019

System load: 0.49 Processes: 81
Usage of /: 3.6% of 39.34GB Users logged in: 0
Memory usage: 25% IP address for eth0:
Swap usage: 0%

Graph this data and manage this system at:

0 updates can be installed immediately.
0 of these updates are security updates.

New release ‘16.04.6 LTS’ available.
Run ‘do-release-upgrade’ to upgrade to it.

vagrant@vagrant-ubuntu-trusty-64:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:bb:97:37 brd ff:ff:ff:ff:ff:ff
inet brd scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:febb:9737/64 scope link
valid_lft forever preferred_lft forever
vagrant@vagrant-ubuntu-trusty-64:~$ hostname -I

mac:ubuntu mac$ vagrant ssh-config
Host default
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/mac/MyVagrant/Ubuntu/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL



Check whether the Chef Client / Chef Solo exists in the instance or the expected version when starting Vagrant, and if not, automatically install it on the instance using Chef’s omnibus installer.

# -*- mode:ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config| = "<your_box_name_here>" :private_network, ip: ""

  config.omnibus.chef_version = "11.4.0"

  config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = "./cookbooks"
      chef.add_recipe "apache"

vagrant ssh-config


>vagrant ssh-config
Host default
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/hoge/MyVagrant/Cent/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL


>vagrant ssh-config > ssh.config

>scp -F ssh.config vagrant@default:package-lock.json ./
package-lock.json 100% 11KB 11.5KB/s 00:00



mount -r /ev/cdrom /media/cdrom

mount is a command to do or mount work which embeds a disk device in the directory of Linux and makes it usable.
Today, the disk device ranges from CD, DVD, Blue-ray Disc, external hard disk, USB memory and so on. Disk devices are called file systems on Linux. All of them can be set to be usable with the mount command.

Basic of “mount”
The way to check the current mounting status is easy as follows.

[vagrant@localhost tests]$ mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vagrant on /vagrant type vboxsf (uid=500,gid=500,rw)

The current mounting status is displayed. Information on where called a mount point is located, the type of the file system whether other read / write is possible, and the like are displayed.

-r option: read-only
The -r option is an option to mount read-only and the format is as follows.

$mount -r -t ${type} ${device} ${mount directory}

The command to mount the device /dev/cdrom read-only on the mount point/media/cd is as follows.

$ mount -r -t iso9660 /dev/cdrom /media/cd
mount -r /dev/cdrom /media/cdrom

VBoxManage storageattach CentOS-6.4-x86_64-minimal

Assign virtual DVD drive
Like the virtual hard disk, assign a virtual DVD drive. The installation media specifies Cent-6.4- x86 – minimal.iso.

$ VBoxManage storageattach CentOS-6.4-x86_64-minimal --storagectl SATA --port 2 --type dvddrive --medium I:/ISO/CentOS/CentOS-6.4-x86_64-minimal.iso
$ VBoxManage storageattach ${guest-os} \
  --storagectl IDE \
  --port 1 \
  --device 0 \
  --type dvddrive \
  --medium ${iso}

VBoxManage controlvm “guest OS”

Operate specified guest OS

%VBoxManage controlvm "guest os" [ poweroff  | savestate | reset | pause | resume ]

The second argument in controlvm specifies the control option

Added port forwarding settings from the command line in VirtualBox

VBoxManage controlvm "guest OS" natpf1 "nginx,tcp,,8080,,80"

In this sample, port forwarding 8080 of localhost to port 80.

VBoxManage controlvm "guest OS" natpf1 ssh,tcp,,22022,,22

VirtualBox(Oracle VM VirtualBox) VBoxManage

VBoxManage Introduction

As briefly mentioned in Section 1.17, “Alternative Front-Ends”, VBoxManage is the command-line interface to Oracle VM VirtualBox. With it, you can completely control Oracle VM VirtualBox from the command line of your host operating system. VBoxManage supports all the features that the graphical user interface gives you access to, but it supports a lot more than that. It exposes all the features of the virtualization engine, even those that cannot be accessed from the GUI.

Display a list of virtual machines created by VirutalBox.

VBoxManage list vms

create virtual machine name
specify the virtual machine name to create the VirualBox configuration file.

VBoxManage createvm --name CentOS-6.4-x86_64-minimal

Virtual Machine Settings
Registered the virtual machine, there is nothing set up for the virtual machine, so set up the virtual machine.
In addition to the specifications of the above virtual machines, the clipboard sharing is specified bidirectionally, and the boot order is changed from HDD to DVD to NET here.

VBoxManage modifyvm CentOS-6.4-x86_64-minimal --ostype RedHat_6

Create a virtual hard disk
Create a virtual hard disk with a fixed size. Although you can specify an arbitrary folder with the -filename option, it is created by specifying the folder to save the VirtualBox.

VBoxManage createhd --size 8192 --variant Fixed --filename F:/VirtualBox/CentOS-6.4-x86_64-minimal/CentOS-6.4-x86_64-minimal.vdi

Add storage controller
Add a SATA(Serial ATA) controller to assign virtual hard disk and virutal DVD drive. In addition to sata, ide / sscsi / floppy can be specified. Also, by specifying -bootable on, it is set as a Bootable controller.

$ VBoxManage storagectl CentOS-6.4-x86_64-minimal --name SATA --add sata --sataportcount 5 --bootable on

Assign virtual hard disk
After adding the storage controller, assign the virtual hard disk by specifying the name of the added storage controller.

VBoxManage storageattach CentOS-6.4-x86_64-minimal --storagectl SATA --port 1 --type hdd --medium F:/VirtualBox/CentOS-6.4-x86_64-minimal/CentOS-6.4-x86_64-minimal.vdi

Assign virtual DVD drive
Like the virtual hard disk, assign a virtual DVD drive. The installation media specifies CentOs – 6.4 x86 – 64 minimal .iso.

$ VBoxManage storageattach CentOS-6.4-x86_64-minimal --storagectl SATA --port 2 --type dvddrive --medium I:/ISO/CentOS/CentOS-6.4-x86_64-minimal.iso

Starting a virtual machine
Now that the setting of the virtual machine has been completed, start the virutal machine.

VBoxManage startvm CentOS-6.4-x86_64-minimal