The GNOME people work on improving their DE constantly. We were always curious about their development of GNOME Boxes as it sounds promising to have a frontend for a QEMU instance or even use Boxes for creating that instance. Unfortunately, using Boxes as a replacement for creating a VM in KVM/QEMU via CLI does not work properly yet.
What are we going to do?
- We are going to create a server on a physical machine for hosting virtual machines.
- We then install another Ubuntu server on the virtual machine.
- We will access the VM by using an SSH tunnel for connecting to the VNC server on that machine.
- By doing so, we will make use of GNOME Boxes for accessing the console of the VM.
Let’s assume our IP-address is 10.0.0.10 on the dedicated VM Host. In this demo, we are working inside an DHCP and DNS network, so the master server can easily handle the DNS records and host names. We simply fire up our server configuration, add the host name vmprovider for our dedicated VM machine and set the IP 10.0.0.10. Thus we can access our server via SSH more comfortably and/or are not bound to using IP addresses in the browser. This is helpful when you e.g. work on a Wordpress setup for instance. Wordpress doesn’t like changing IP addresses.
Why are we going to do this?
There are many reasons for deploying virtual machines on a server. Working on a local machine sometimes just doesn’t cut it, especially when you’re short on RAM or when cooperating with your fellow colleagues on a project.
Also, solutions like VMWare Player or Virtualbox are nice, but they also eat up your resources quickly. Yes, they’re hungry.
Using LXC is quite cool, but what if you don’t want to risk anything and find it to be a hassle to set up the LXC stuff, doing the config and so on? Cloning an LXC container is simple, but still you have to configure the networking and so on.
- Do you also find it terribly annoying when the VM instance captures your mouse pointer? GNOME Boxes doesn’t do that.
- Do you hate configuring the video settings for not messing up the scaling of your VM window? Simply resize your box.
Good Guy GNOME
What do we need?
Ubuntu 14.04 Server ISO
For the sake of simplicity we are renaming the file to just ‘ubuntu1404.iso’. My suggestion is to do that on your local machine for saving time.
20 GB HD space
1 free CPU
1 GB RAM
reasonable hostname and user names
- vmprovider for our host machine
Desktop with a GNOME DE >=3.10
What we’re not going to cover here
bridging your NICs
There are various tutorials across the web. It’s not too difficult to do, so we just take it for granted to work with virbr0 and its IP 192.168.122.1.
the perfect KVM/QEMU configuration
This post is about making use of GNOME Boxes via VNC, not about KVM’s huuuge options library.
the perfect network configuration
Why would we handle the network configuration inside a VM hosting machine while we could easily do that on a machine which’s purpose is to provide our users with a great environment? Nope.
Install the VM Host
Start the installation process on your dedicated machine, furiously. Instead, press the ESC button on the language selection screen first, then hit F4 and select ‘Minimal Installation’. Why? Because we want to create a lean and slick server installation. Apart from that, the minimal Installation downloads lots of necessary packages from the web so you save your time for doing a dist-upgrade after you’ve completed the installation procedure.
Partition your hard drives simply with the guided LVM setup and apply the reasonable user and host name, continue the install process. When reaching the tasksel screen, select the Basic Ubuntu server, the SSH server and the VM provider packages. Finish the installation process and reboot your VM host. We now SSH onto our machine and use the terminal rather than the VM’s console.
You’ll need some additional packages for making your life more comfortable. We don’t want to use QEMU, but we will use virsh as it provides us with a selection of simple options.
sudo apt-get install virtinst libvirt-bin
From our local machine we are copying the Ubuntu image to the /home folder of our vmuser on the VM host machine by using scp:
scp ~/Downloads/ubuntu1404.iso [email protected]:/home/vmuser/ubuntu1404.iso
Of course, you could easily browse the vmprovider’s file system by accessing it via Nautilus, so we could go with “connect to server”
and filling in our credentials.
On the VM Hoster edit the qemu config file for making the output of the VM’s VNC server accessible to VNC clients:
sudo nano /etc/libvirt/qemu.conf
Find the line vnc_listen and uncomment it:
vnc_listen = "0.0.0.0"
By doing so, any client from anywhere can access your VM’s console output, so we strongly suggest you have set up your access rules properly on a master server which handles DNS, DHCP and stuff. (refer to the section ‘What we’re not going to cover here’)
You don’t have to create a virtual file system prior to the installation process, we are going to do that while installing the VM Guest.
Finally start the installation!
SSH onto the vmprovider and fire up virsh in all of its glory:
virt-install —connect qemu:///system -n ubuntu2 -r 1024 —vcpus=1 —arch=x86_64 -c ~/ubuntu1404.img —network=network:default,mac=00:AA:BB:CC:DD:00 —accelerate —vnclisten=0.0.0.0 —disk=/var/lib/libvirt/images/ubuntu2,size=20 —force
|ubuntu2||…||is the name of your environment, call it according to your needs|
|—vnclisten=0.0.0.0||…||is not necessary here as already defined in the qemu.conf file|
|/var/lib/../ubuntu2||…||is the name of your virtual disk, make sure to keep same name like above|
|—force||…||means that you force the installation into this folder and file|
It can become quite cumbersome to restart installation procedures when receving errors, because you have to delete the environments, remove the MAC addresses and so forth.
virsh destroy ubuntu2
virsh undefine ubuntu2
standard procedure to memorize
Step One start the instance
Step Two SSH tunnel
Step Three start GNOME Boxes
No. It won’t work out if you don’t follow the order of launching the instance and then starting Boxes.
Wait for the install process to begin and then create a tunnel from your local machine to the vmprovider by launching a terminal and typing:
ssh [email protected] -L5900:127.0.0.1:5900
Now you can launch Boxes and create a new box. Well, you could have created the box beforehand but why hurry? You don’t have to specify a port in Boxes since you already have specified the correct port in your tunnel plus you enter the standard port for the VNC protocol by: vnc://127.0.0.1
Your box is ready now. Double click it to access the console and continue the installation. Did you read the section above about not furiously hitting the Enter button? Yes, we like that option, so we’ll do it again and select ‘Minimal Virtual Installation’ now. By doing so, Ubuntu does not install all the kernel modules and drivers which do not come in use in a virtual setup. How cool is that? We love it.
Once you’re done with the installation, your box will become dark. Let it rest for a while until you’re sure the installation process has completed properly. Sometimes it ‘freezes’, but you can easily stop the process by applying the shortcut given in the terminal window.
Close your box for now. Then go to your terminal (not the tunneling one!) and list all your installed machines:
virsh —connect qemu:///system list —all
Now is the time for starting up the machine again:
virsh —connect qemu:///system start ubuntu2
Again, make sure having started the instance before starting your GNOME Box. It won’t connect and your Tunnel Terminal will give you an error output. Voilá, there we go. We now can do what we want to do. Create a Rails application by installing RVM, running GitLab or whatever you like. Testing and wrecking.
Once you’ve had enough, you can shut down your instance by
sudo init 0
in your VM Guest session or on your VM Host
virsh —connect qemu:///system shutdown ubuntu2
Done with playing, now close that tunnel!
Alright, there you go. On your local machine grep for the processes involved with VNC:
ps aux | grep 5900
Then kill them!
kill 1680 #the PID given above
OK, OK. A more reasonable way? Close the Tunnel Terminal by hitting
CTRL + D
Questions and different stuff
Obviously, you can find different configuration options and might be wondering why we do it that way. First of all – why not?
> Why do you place the virtual disk inside /var/…?
Out of a habit. Usually I have my /var directory on a separate partition so that I can easily mount it during a server upgrade process without the need for repartitioning and other hassles which simply consume my time. (refer to the section ‘What we’re not going to cover here’)
> What if I want to run several virtual machines on my vmprovider?
Just make sure not to run out of CPUs and RAM. Simply alter your install command and apply this little neat option to it:
Of course you have to change the ports in your tunnels and of GNOME Boxes accordingly:
> I have grepped for 5900 and there are still processes running!
No need to worry. These show up on changing ports and do no harm.
> I am not absolutely sure if my tunnel is closed?
Fire at will!
pkill -x ssh
Still questions? Comments?
Did we make any mistake? Do you find it stupid to fuzz around with QEMU? Tell us why! Suggestions and improvements? Hit the ‘comment’ button or leave a reply on Google+!