mac vagrantでGLUTのGUIの立ち上げ方法

VagrantでGULTのGUIが立ち上がらない

#include <GL/glut.h>

void display(void){

}

int main(int argc, char *argv[]){
	glutInit(&argc, argv);
	glutCreateWindow(argv[0]);
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}

$ ./app
freeglut (./app): failed to open display ”

1.一旦ログアウトしてvagrantを止めます。

$ exit
$ vagrant halt

2. Vagrantfileにssh.forward_x11を追記します。

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.ssh.forward_x11 = true // 追加
end

https://www.vagrantup.com/docs/vagrantfile/ssh_settings.html
config.ssh.forward_x11 (boolean) – If true, X11 forwarding over SSH connections is enabled. Defaults to false.

X Window Systemとは、UNIX系OSで標準的に用いられるウィンドウシステム。

XQuartzをダウンロード
-> MacユーティリティでXQuartzを起動し、terminalから再度実行

$ ./app
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request: GLXBadContext
Major opcode of failed request: 149 (GLX)
Minor opcode of failed request: 6 (X_GLXIsDirect)
Serial number of failed request: 43
Current serial number in output stream: 42
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 149 (GLX)
Minor opcode of failed request: 24 (X_GLXCreateNewContext)
Value in failed request: 0x0
Serial number of failed request: 42
Current serial number in output stream: 43

$ sudo ldconfig -p | grep -i gl.so
libwayland-egl.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libwayland-egl.so.1
libwayland-egl.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libwayland-egl.so
libOpenGL.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libOpenGL.so.0
libOpenGL.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libOpenGL.so
libGL.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGL.so.1
libGL.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGL.so
libEGL.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libEGL.so.1
libEGL.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libEGL.so

あれ、何故だーーーーーーーーーー
色々検索していたところ、同じ解決方法を発見
https://unix.stackexchange.com/questions/429760/opengl-rendering-with-x11-forwarding

Try the following: 1) ensure you are running up-to-date Xquartz. 2) in a terminal, defaults write org.macosforge.xquartz.X11 enable_iglx -bool true 3) restart xquartz. This worked for me to get a simple java app running. I tried "glxgears" and it starts, but the gears don't turn. I presume they're supposed to

mac側のterminalでX11をenableにする。
$ defaults write org.macosforge.xquartz.X11 enable_iglx -bool true

再度XQuartzでsshログイン
$ ./app

立ち上がったーーーーーーーーーーーー

Virtual Boxのハードウェア構成の見方

ここでは、amazon linux2のハードウェア構成を確認します。

### Oracle Virtual box マネージャを起動
OS:Linux 2.6 / 3.x / 4.x 64-bit
システム メインメモリー:1024MB
アクセラレーション: VT-x/AMD-V、ネステッドページング 、PAE/NX, KVM 準仮想化
ディスプレイ: ビデオメモリー16MB、グラフィックコントローラ VBoxVGA
ストレージ: box-disk001.vmdk(25.00GB)
ネットワーク アダプタ: Intel PRO/1000MT Desktop(NAT)

### CPU
ヘッダの設定から、システム、ディスプレイ、ストレージ、オーディオ、ネットワーク、ポート、共有フォルダなど設定可能

1CPU, メインメモリ1GBだと、t2.microと同じくらいのスペック

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

vagrant boxesからamazon linux 2を入れて、環境構築をする
https://app.vagrantup.com/gbailey/boxes/amzn2

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

Vagrantfile

config.vm.network "private_network", ip: "192.168.33.10"

>vagrant up
>vagrant status
>vagrant ssh
$ exit

>vagrant halt

>vagrant status
default running (virtualbox)

なにいいいいいいいいいいいいいいいいいいいい?

Vagrantfile
config.vm.guest = :amazonを追加

config.vm.box = "gbailey/amzn2"
  config.vm.guest = :amazon

>vagrant halt
>vagrant status
default poweroff (virtualbox)

beautiful!

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}