macにubuntuを入れよう

まずvagrant boxes
https://app.vagrantup.com/boxes/search

まず、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
`vagrantup.com` for more information on using Vagrant.

ポートフォワーディング

  # config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "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: https://help.ubuntu.com/

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: 10.0.2.15
Swap usage: 0%

Graph this data and manage this system at:
https://landscape.canonical.com/

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 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: 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 10.0.2.15/24 brd 10.0.2.255 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
10.0.2.15

あれ
mac:ubuntu mac$ vagrant ssh-config
Host default
HostName 127.0.0.1
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

ubuntuの中身を見ると、centosとファイル構成は似ているように見えます。後は使いながら少しずつ覚えていくしかないですね。とりあえず、pythonで開発する際はubuntuベースで使っていこうかと思います^^

vagrant-omnibus

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|
  config.vm.box = "<your_box_name_here>"
  config.vm.network :private_network, ip: "192.168.33.33"

  config.omnibus.chef_version = "11.4.0"

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

vagrant ssh-config

VagrantfileがあるディレクトリでOpenSSHの設定を行う。

>vagrant ssh-config
Host default
  HostName 127.0.0.1
  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

ん?なんじゃこりゃ。

取得できるファイルをssh.configに書き込み。
>vagrant ssh-config > ssh.config

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

まじこれ?
要するにvagrantにscp接続できたってこと?

うおおおおおおおおおおおお、全然追いつける気がしない。

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.