CentOS with GNOME desktop on Vagrant

I made a CentOS vagrant box which contains GNOME desktop environment, so I will show how to use and to make it.


How to use

[1] Create Vagrantfile

Create a Vargantfile as shown below:

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

Vagrant.configure(2) do |config|
  config.vm.box = "s-hironobu/centos72_x86_64_gnome_vncserver"
  config.vm.network "private_network", ip: ""
  config.vm.network :forwarded_port, guest: 5901, host: 5901

[2] Start vm box

Run vagrant up.

$ vagrant up

[3] Access VM via vnc client

If you use OSX, run the following command:

$ open vnc://localhost:5901

Password is vagrant.

If you use other OS, run your vnc-client.

Figure 1:

Figure 1:

How to make

[1] Download and start official CentOS vagrant box

Download centos box from vagrantbox.es and start it.

# vagrant up

Login the Guest OS as “root”, and install GNOME related packages.

# vagrant ssh
Last login: Mon Mar 14 05:24:32 2016 from
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ su -
Last login: Mon Mar 14 05:24:40 2016 from
[root@localhost ~]# 
[root@localhost ~]# yum upgrade
[root@localhost ~]# yum groupinstall "X Window System" "GNOME Desktop"
[root@localhost ~]# yum install tigervnc-server

[3] Change inittab

Put the following line into /etc/inittab file.


[4] Set up vncserver

Run vncpasswd command as “vagrant” user.

[root@localhost ~]# su - vagrant
Last login: Mon Mar 14 05:44:51 UTC 2016 from on pts/0
[vagrant@localhost ~]$ 
[vagrant@localhost ~]$ vncpasswd
[vagrant@localhost ~]$ exit

Run the following commands to create vncserver@:1.service file and replace from “<USER>” to “vagrant” in its file.

[root@localhost ~]# cd /etc/systemd/system
[root@localhost system]# ln -s /lib/systemd/system/vncserver@.service vncserver@:1.service
[root@localhost system]# sed -i -e 's/\<USER\>/vagrant/g' vncserver@:1.service

Run the following commands to set up vncserver.

[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl enable vncserver@:1
[root@localhost system]# systemctl restart vncserver@:1

[5] Set up firewall

Run the following commands.

[root@localhost system]# firewall-cmd --permanent --zone=public --add-service=vnc-server
[root@localhost system]# firewall-cmd --reload
[root@localhost system]# firewall-cmd --list-all

[6] Clean up

Run the following commands to make the box as small as possible.

[root@localhost system]# yum clean all
[root@localhost system]# dd if=/dev/zero of=/EMPTY bs=1M
[root@localhost system]# rm -f /EMPTY
[root@localhost system]# cat /dev/null > ~/.bash_history && history -c && exit

[7] Make package

Run the following command on your host OS.

$ vagrant package