Ubuntu / Xubuntu 12.04 Desktop as Hyper-V Guest


This post is in the category: Guides

Posts here are mostly step-by-step guides on how to replicate something I have set up in the past. Read over my About page to see how I show commands/output and read the disclaimer.


Ubuntu 12.04 and Hyper-V have pretty good support for each other, but it’s not without a fair share of hiccups. I will go over all the steps required to install Xubuntu as a Hyper-V guest and configure remote access through VNC.

These instructions are intended for Hyper-V running on Windows 8 Pro.

Bonus Video

Base OS Install

Install Xubuntu 12.04 using whatever method you like, most likely using the Xubuntu 12.04 Desktop ISO.

Fixing the Blank Screen Issue

Boot up the machine with the Hyper-V viewer open. You will most likely see a blank screen until the login screen appears. Let’s fix that, because we will need to interact with the terminal without a GUI later.

Login to the VM’s desktop and fire up a terminal editor.

[user]$ sudo leafpad /etc/default/grub

Find the below lines, and make sure they are set accordingly. You may have to remove quiet splash from one of the lines.

GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

Next uncomment this line.

GRUB_TERMINAL=console

Save and close the text editor.

Now update the grub images.

[user]$ sudo update-grub

Finally reboot.

[user]$ sudo reboot

Now as the VM is booting up, you should see verbose boot messages before the login screen appears.

Disabling the GUI at Startup

It seems that Microsoft does not recommend using the Hyper-V viewer for day-to-day tasks with the guest machines. They recommend using RDP or some other form of remote access. In our case, we will use VNC.

First, we need to disable the GUI from launching by default.

Login into the VM guest and bring up a terminal.

[user]$ sudo leafpad /etc/init/lightdm.conf

Comment out these lines.

#start on ((filesystem
#           and runlevel [!06]
#           and started dbus
#           and plymouth-ready)
#          or runlevel PREVLEVEL=S)

Save and close the text editor.

[user]$ sudo reboot

Now if you are watching the VM boot, you will see verbose boot message resolve to a terminal login prompt instead of a GUI.

At this point, we have more commands to run, but it’s not important whether you run then through the Hyper-V manager or SSH using something like Putty.

Installing and Configuring the VNC Server

[user]$ sudo apt-get install vnc4server
[user]$ mkdir ~/.vnc
[user]$ touch ~/.vnc/xstartup
[user]$ chmod +x ~/.vnc/xstartup
[user]$ vim ~/.vnc/xstartup

Copy in the below content.

#!/bin/sh

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#xfce4-session &
startxfce4 &

Save and close the text editor.

Run the below command as the user you want to server the VNC server under, mostly likely the user account you created during the OS setup.

[user]$ vncserver :0

You will be prompted to set a password if this is the first time launching the server.

Now let’s try to connect from a VNC client. I recommend using RealVNC. When connecting, set the compression and encryption to your liking. I turn the compression to as low as possible as I use it only over the LAN.

Once you have the VNC client installed, try and connect to your VM using the IP address or hostname.

If you ever need to manually kill the server, do it with this:

[user]$ vncserver -kill :0

Configuring an Upstart Script

So now we have a working Hyper-V guest with remote access, but what happens when the VM reboots? The VNC server will not start automatically with our current configuration. This is our last setup.

Login to the VM through SSH or the Hyper-V manager.

[root]$ sudo vim /etc/init/vnc-server.conf

Add the below content, replacing andrew with your user name.

start on runlevel [2345]
stop on runlevel [016]

pre-start script
    su andrew -c 'vnc4server :0 -geometry 1920x1080'
end script

post-stop script
    su andrew -c 'vnc4server -kill :0'
end script

Notice that I also set the screen resolution here. Adjust that to your liking.

Fixing the Tab Key

For whatever strange reason, the Tab key may not work when connected through VNC. Run the below command from a graphical terminal as the affected user to fix that.

[user]$ xfconf-query -c xfce4-keyboard-shortcuts -p /xfwm4/custom/'<'Super'>'Tab -r

Conclusion

At this point, this VM should no longer require the Hyper-V viewer. Simply power on the VM, wait a minute for it to boot, and then connect to it through VNC.

This entry was posted in Guides and tagged , on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

Leave a Reply

Your email address will not be published. Required fields are marked *