概要
CentOSにGUIデスクトップ環境みたいなやつ(GNOMEか…?)あったよね、あれどう表示するんだろとなったので調べて作っていました。
Vagrantfileにコードを書いておくだけでよいらしく、わりとすんなり表示されたのでメモ。
環境
Windows10 home
やったこと
vagrant init
適当なフォルダにVagrantfileをつくって
C:\>vagrant init 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.
vagrantfile内容設定
下記をコピーして貼り付けます。
Vagrant.configure("2") do |config| config.vm.box = "bento/centos-8.2" config.vm.box_version = "202006.16.0" config.vm.network "private_network", ip: "192.168.33.10" config.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "1024" end config.vm.provision "shell", inline: <<-SHELL sudo dnf -y group install "Server with GUI" sudo systemctl set-default graphical.target sudo systemctl get-default SHELL end
vagrant up
あとは起動する。これだけでいいらしい。
(シェルでGUIデスクトップのインストールしているのでちょっと時間がかかります、20分ぐらいかかった)
C:\>vagrant up
Vagrantfileに何が書いてあるか
Vagrantfileでは、ここで使うboxファイル(bento/centos-8.2)とIP(192.168.33.10)を指定して。
config.vm.box = "bento/centos-8.2" config.vm.box_version = "202006.16.0" config.vm.network "private_network", ip: "192.168.33.10"
ここでVitualBoxのGUI画面が表示されるようにして。
config.vm.provider "virtualbox" do |vb| vb.gui = true vb.memory = "1024" end
ここで初回起動時に実行するシェルコマンドを記入しています。
インストールだけなら「sudo dnf -y group install “Server with GUI”」があれば良い様子。
「sudo dnf systemctl set-default graphical.target」とかはマシンを起動するたびにGUIデスクトップを立ち上げる設定らしいです。
config.vm.provision "shell", inline: <<-SHELL sudo dnf -y group install "Server with GUI" sudo systemctl set-default graphical.target sudo systemctl get-default SHELL
上記が終わったあと仮想マシンをシャットダウン→起動します。
C:\>vagrant halt C:\>vagrant up
下記のようなGUIが立ち上がりvagrantを選択後、パスワードを入れるとログインできました。
おわり。