Lampros - Weird Bricks

VNC in PCBSD 10 (Joule) Jails (also intro to Warden)

11 December, 2013 | PC-BSD

Hi all,

Today I'm moving things forward a bit.

I love VirtualBox and as it's evident by my old posts I've been using it almost exclusively for all testing, but I got tired of the slow performance of guests.

I tried firing up the VT extensions but I realized my motherboard is one of the cheaper models and doesn't support them, even though the processor is quad core and supports them. So I went ahead and resized the Windows partition and installed PCBSD in dual boot - the only problem I run into was that everytime I would select the GRUB loader the installation would break and would force me to cancel.

As soon as I picked the BSD bootloader everything worked like magic.

So moving forward I started playing with Warden (the frontend to BSD Jails - read more about it here) I figured I'll do all my testing in Jails since it's kernel level virtualization and it's tons faster.

However, what about having a desktop ? The obvious answer is to use VNC, but I started running into weird errors when I was setting it up.

Here's what I did, hopefully this will save someone time.

Creating a new Jail with Warden and connecting to it

1. First start Warden and click on 'File'->'New Jail'

2. The 'New Jail Wizard' will come up - * enter a hostname, e.g. "lxde-vnc-test" * Use only an IPv4 IP address - make sure the one you use is not currently in use. In my case I used 192.168.2.7 * click 'Next'

3. When asked for the 'Jail Type' select 'Traditional Jail' and make sure that 'Install PKGNG and PC-BSD utilities' is ticked - on 'Jail Version' select 'Use system version (default) - click 'Next'

4. Set a root password and click 'Next'

5. In the 'Jail Options' leave everything unticked, we won't be using ports this time - at this point the jail will be created and any necessary dependencies will be downloaded. This takes about 5 minutes, depending on your system's performance and internet connection

6. Click on the blue "play" button to start your jail - the status will change to "running"

7. Now open a terminal window and become root - type sudo su - - you'll get a password prompt:

sudo su - Password:

8. Enter your password - now you'll be the root user:

[root@daemon] ~# 

9. Type jls to see the running jails - this is the output I got on my system:

jls JID IP Address Hostname Path 1 192.168.2.5 Jailbird /usr/jails/Jailbird 4 192.168.2.7 lxde-vnc-test /usr/jails/lxde-vnc-test

10. The way you "connect" to a jail is you either have the SSHd daemon set up, or start a shell inside the jail - we'll do the second one, by using the command:

jexec 4 csh

The above starts a C shell (csh) inside the jail! This is what I got:

[root@lxde-vnc-test] /#

Setting up VNC inside the Jail

1. So first of all install all the necessary packages - this is done, of course as the root user:

pkg install xorg curl vnc lxde-meta

The above took about 5 minutes 2. Now set a password for VNC with vncpasswd like this:

vncpasswd Password: Verify:

The above creates the directory ~/.vnc and places inside the file passwd 3. Now try to fire up the VNC server with the vnserver command:

vncserver: no free display number on lxde-vnc-test.

Oops what happened there? I searched for a bit on Google for the above error message and this seems to be a common problem with FreeBSD, VNC and Jails. A fix is suggested here . This requires you to modify the vncserver script and change some lines - I found a different way to work around this.

4. Create an environment variable called vnc and set it to 1

setenv vnc 1

5. Create another environment variable called DISPLAY and set it to :$vnc

setenv DISPLAY :$vnc

6. Now instead of using the vncserver script to launch VNC launch it directly with the Xvnc command, replacing the screen number with the correct variables and making it start in the background with adding & in the end - the resulting command is the following:

Xvnc :$vnc -desktop vnc-server:$vnc -PasswordFile ~/.vnc/passwd -depth 24 &

You'll get a bunch of output that will look like this:

Xvnc Free Edition 4.1.3 - built Nov 21 2013 
15:41:33 Copyright (C) 2002-2008 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Underlying X server release 40300000, The XFree86 Project, Inc
Wed Dec 11 12:58:42 2013
vncext: VNC extension running!
vncext: Listening for VNC connections on port 5901
vncext: created VNC server for screen 0
error opening security policy file /usr/local/lib/X11/xserver/SecurityPolicy
Could not init font path element /usr/local/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/local/lib/X11/fonts/CID/, removing from list!

Note that you will not instantly get a prompt - just press enter !

Want to make sure your server is running? Let's look at the processes with ps aux, like this:

ps auxw | grep Xvnc | grep -v grep

The output I got is:

root 43264 0.0 0.1 28632 10464 2 IJ 12:58PM 0:00.08 Xvnc :1 -desktop vnc-server:1 -PasswordFile /root/.vnc/passwd -depth 24

Now, check it - try to connect from your PCBSD host with VNC - make sure you have the ssvnc PCBSD PBI installed already - check that you have it with:

pbi info | grep ssvnc

The output in my case was:

ssvnc-1.0.29_01-amd64

If you don't have it install it with:

pbi install ssvnc

Once you've made sure you have it connect to your VNC server running in the Jail with ssvncviewer - the syntax for connecting to VNC screens looks like the following: (NOTE: do not run this as root!)

ssvncviewer IPADDRESS:VNCSCREEN

In my case the IP address of the Jail is: 192.168.2.7 The screen you ask? we defined this above with:

setenv vnc 1

So to connect we need:

ssvncviewer 192.168.2.7:1

You'll see some output like this and then get a password prompt for VNC - note that this is the VNC password:

ssvncviewer 192.168.2.7:1 

Proto: RFB 003.008

Connected to RFB server, using protocol version 3.8

SelectSecurityType:

sec-type[0] 2 (rfbSecTypeVncAuth)

Security-Type: 2 (rfbSecTypeVncAuth) Latency: 0.14 ms

Performing standard VNC authentication
VNC Password:

Once you enter the password you should get an empty screen with a grey background like this:

Folks more experienced with VNC can probably guess that this is because Xvnc on it's own does not load the xstartup script, this is something that the vncserver wrapper script takes care of. So how do we set up the window manager and desktop you may ask? It turns out it's almost easier than messing with the xstartup script.

Go back to the terminal window you were working on previously with the jail and type openbox-lxde & - this will start the Window Manager:

openbox-lxde &

You'll get some output like this, which you can ignore:

openbox-lxde & 
[2] 22534
[root@lxde-vnc-test] ~/.vnc# Obt-Message: XRandR extension is not present on the server

Just press enter to continue - if you have your VNC screen still up you'll see that nothing changed.

Now let's start the LXDE desktop with lxsession &

You'll get a bunch of output like this:

Obt-Message: XRandR extension is not present on the server 
Openbox-Message: A window manager is already running on screen 0
Xlib: extension "RANDR" missing on display ":1".
Xlib: extension "RANDR" missing on display ":1".
lxpanel: can't load netstat plugin
lxpanel: can't load cpu plugin

(lxpanel:50292): Gdk-WARNING **: shmget failed: error 78 (Function not implemented)

But most importantly you get this:

To summarize, this is all I did on a brand new Jail:

pkg install xorg curl vnc lxde-meta 
vncpasswd
setenv vnc 1
setenv DISPLAY :$vnc
Xvnc :$vnc -desktop vnc-server:$vnc -PasswordFile ~/.vnc/passwd -depth 24 &
openbox-lxde &
lxsession &