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.

mount
[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,127.0.0.1,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
https://www.virtualbox.org/manual/ch08.html#idm3663

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

vagrant : default paused (virtualbox)

I never seen 404 like below.

>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-6.8' is up to date...
==> default: There was a problem while downloading the metadata for your box
==> default: to check for updates. This is not an error, since it is usually due
==> default: to temporary network problems. This is just a warning. The problem
==> default: encountered was:
==> default:
==> default: The requested URL returned error: 404
==> default:
==> default: If you want to check for box updates, verify your network connection
==> default: is valid and try again.
==> default: Unpausing the VM...

what does it mean?

>vagrant status
Current machine states:

default                   paused (virtualbox)

The VM is paused. This VM may have been paused via the VirtualBox
GUI or the VBoxManage command line interface. To unpause, please
use the VirtualBox GUI and/or VBoxManage command line interface so
that vagrant would be able to control the VM again.

once again, put “vagrant up” on the command line.

>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-6.8' is up to date...
==> default: There was a problem while downloading the metadata for your box
==> default: to check for updates. This is not an error, since it is usually due
==> default: to temporary network problems. This is just a warning. The problem
==> default: encountered was:
==> default:
==> default: The requested URL returned error: 404
==> default:
==> default: If you want to check for box updates, verify your network connection
==> default: is valid and try again.
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

That says “vagrant provision”. Try again, boy.

>vagrant provision

>vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

What!? I know, I’m just playing.

vagrant has multiple choices for machine provisioning, from simple shell scripts to more complicated industry standard configuration management systems.

I you have never used a configuration management system in the past, starting with basic shell scripts for provisioning is recommended.

Vagrantfileのsynced_folderとは?

vagrantのsynced_folderを利用することにより、ホスト、ゲスト間でのファイル同期が可能。

Vagrant.configure("2") do |config|
  # other config here

  config.vm.synced_folder "host_path", "guest_path", options...
end

vagrant up時に有効化

ということは、

local.vm.synced_folder ".", "/vagrant",

. が問題だーーーーーーーーーーーーーーー おkkkkkkkkkkkkkk なるほど。

サイトのパーミッション変更のことだ。

:owner => "vagrant", :group => "apache", :mount_options => ["dmode=775,fmode=775"]

おk 問題はほぼ解決^^

vagrant file

config.vm.defineとは?
VMを指定する

config.vm.define "web" do |local|
local.vm.box = "centos-6.7"

box “contos-6.7″ をwebと定義する。

ホスト: vagrantコマンドを実行するホスト … ローカルのmacなど
ゲスト: vagrantコマンドで作成されたVM … 要するにVM
内部ネットワーク: vagrant内のネットワーク … vagrant内部
外部ネットワーク: ホスト外部 … mac外

プライベートネットワーク
内部ネットワークを利用して、ホストとゲスト、ゲスト間の通信が可能。

これか↓
local.vm.network :private_network, ip: “xxx.xxx.xx.xxx”
ipを指定して通信している

ポートフォワーディング
ホストの特定のポートへのアクセスをゲストへ転送

これだ↓ sshなら、2929、22、 httpなら、8000, 80ってことね。
local.vm.network :forwarded_port, id: “ssh”, guest: 22, host: 2929
local.vm.network :forwarded_port, guest: 80, host: 8000

22: Secure Shell (SSH) – セキュアログイン、セキュアなファイル転送(scpやsftpなど)、ポート転送などで用いられる。
29292:TMO Integration Service Communications Port, Used by Transaction Manager SaaS
80: Hypertext Transfer Protocol (HTTP)
8000:Commonly used for Internet radio streams such as SHOUTcast
ん?? 29292ではなく2929では?

ssh.forward_agent
vagrant sshでvmにログインする場合には、ssh.forward_agentをtureにする。

local.ssh.forward_agent = true

ちょっと長くなってきたので、続きは次回。

vagrantのnetworking: ポートフォワーディング

host machineへのアクセスへのオプションです。
まず、公式ドキュメントを見ましょう。
Vagrant Networking

Prot Forwarding:ポートフォワーディング
ポートフォワーディング:インターネットから特定のポート番号宛てに届いたパケットを、あらかじめ設定しておいたLAN側の機器に転送する機能

現状
localのvagrant rootディレクトリにファイルを置きます。

ブラウザでipをたたくと、jpegが反映されています。

port forwardingを追加

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.network :forwarded_port, guest:80, host: 4567
end

vagrant reload
http://127.0.0.1:4567/test.jpeg でたたく

上手くいってるっぽいです。
大体vagrantの基礎はこの辺で良いかな~

vagrantでprovisioning

provisioningとはリソースを提供できるように配置すること。
公式:Provisioning

あれ、若干初心者の域を超えてきてるか?全然意識してなかったが。。

まず、shell scriptを作ります。
bootstrap.shとします。

shellを書く

#!/usr/bin/env bash

apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
	rm -rf /var/www
	ln -fs /vagrant /var/www
fi

apt-get -> linuxでパッケージをインストール/アップデートする
-y -> yesを省略
-L -> ファイルがありシンボリックであれば真
-r -> ファイルがあり読み取り可能であれば真
-f -> ファイルがあり通常のファイルであれば真
-s -> ファイルがありサイズが0より大きければ真
ln -> link

vagrant fileでshellを読み込み
config.vm.provisionで shellを追記します。

  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"

>vagrant reload
>vagrant ssh
>wget -qO- 127.0.0.1

あれ、なんか上手くいってない。。ああああああああああああああああああああああああ
provisonを実行するには、vagrant provisionだ

>vagrant provision
>vagran ssh
vagrant@precise64:~$ wget -qO- 127.0.0.1


 
  Index of /
 
 

Index of /

[ICO]NameLast modifiedSizeDescription

[   ]Vagrantfile15-Dec-2018 23:53 3.1K 
[TXT]bootstrap.sh16-Dec-2018 00:06 152  
[   ]foo15-Dec-2018 13:40 0  

Apache/2.2.22 (Ubuntu) Server at 127.0.0.1 Port 80
vagrant@precise64:~$

きたーーーーーーーーーーーーーーーーーーーー

vagrantでSynced Folder(共有フォルダ)の設定

Synced Foldersの意味がわかりませんでしたが、どうやら、共有フォルダのようです。
例に習って公式ドキュメントを見てみましょう。
Synced Folders

By using synced folders, Vagrant will automatically sync your files to and from the guest machine.
ローカルのフォルダとvmで共有できるそうだ!

え、何だって?

共有って凄くない!?

By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.
ん?ローカルのvagrant upしたディレクトリと、home/vagrantが一緒?

vagrant@precise64:/home$ ls
vagrant
vagrant@precise64:/home$ cd vagrant
vagrant@precise64:~$ ls
postinstall.sh

postinstall.sh しかないよ。

vagrant@precise64:~$ ls /vagrant
Vagrantfile

topに戻ります。

vagrant@precise64:/$ ls
bin   etc         lib         media  proc  sbin     sys  vagrant
boot  home        lib64       mnt    root  selinux  tmp  var
dev   initrd.img  lost+found  opt    run   srv      usr  vmlinuz
vagrant@precise64:/$ cd vagrant
vagrant@precise64:/vagrant$ ls
Vagrantfile

ああああああああ、なるほど! vagrantフォルダと共有されてる!!!!!!!!!!!!!!

vagrant@precise64:/vagrant$ touch foo
vagrant@precise64:/vagrant$ ls
foo  Vagrantfile


これはすげー ビビった。