Ubuntu Graphics Problems

I ran into this problem a while back on my server but it’s never really affected me as I dont generally use the console.

After running updates a good few months back, my system stopped giving me any output. It wouldn’t load to X or a console and even stopped showing the splash screen and the boot info.

The way I was getting around it was to just use an earlier Kernel version during boot. But tonight while doing some work this little bugger got me again.

After hours working through numerous problems I’ve just left unresolved this one finally needed to be solved. Previously I’d just SSH’d to the machine having no console, started the xlib_shm stuff and up popped the CCTV view and I’d just leave that running, but tonight even that wouldn’t work.

I found the following info while trawling the interweb for fixes:-
The problem seems to start after Kernel 2.6.38-8 (that’s the last one I can boot without problems)
It’s related to the ATI graphics card and drivers
*ERROR* Failed to register bit i2c VGA_DDC was showing up in the syslog

I found info in several bugs saying to add this ‘i2c_algo_bit.bit_test=0’ but didn’t actually say where.

So I opted to add ‘i2c_algo_bit.bit_test=0’ into the grub config for the lastest kernel, so my grub line now looks like ‘linux   /vmlinuz-2.6.38-15-generic root=/dev/mapper/VG-LV_Root ro   quiet splash i2c-algo-bit.bit_test=0 vt.handoff=7’

Rebooting kept my splashscreen, and presented me with my console once again. and now my xlib_shm was also working once again.

But as I’m very likely to forget after a bunch more remote updates, I thought it best to make it a little more permanent, so I edited /etc/default/grub and amended the OPTIONS line to read ‘GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash i2c-algo-bit.bit_test=0″‘
a quick run of update-grub and my entire config is updated.
This should survive future updates and keep me with a working console should I need it.

cp: cannot stat `/lib/libnss_*’: No such file or directory

Another Quick note as I keep running into this and every time go hunting for what I did to fix it last time.

When doing update/upgrades I run into the error cp: cannot stat `/lib/libnss_*’: No such file or directory when it’s running update-initramfs

This seems to be because of the dropbear hooks, that I use to decrypt a filesystem remotely.


Has all the info, but the basic steps for me are:-

nano -w /usr/share/initramfs-tools/hooks/dropbear

search for the line

cp /lib/libnss_* "${DESTDIR}/lib/"
Add x86_64-linux-gnu into the path making the line

cp /lib/x86_64-linux-gnu/libnss_* "${DESTDIR}/lib/"

UPDATE: This is valid for a 64bit system. For a 32bit system the path is more likely to be /lib/i386-linux-gnu/
This would make the line

cp /lib/i386-linux-gnu/libnss_* "${DESTDIR}/lib/"

Then run

update-initramfs -u

and no error.

Asterisk SIP One way Audio

ok, I know what your all thinking just from the title alone.
It’s SIP and One way Audio, it’s going to be a NAT and firewall issue. That was my immediate thought too, but it’s wrong.
To explain a little of the background will probably help.

I’ve been running Asterisk at home now for years, using a Digium 422. One line coming in, and a few Linksys SIP phones.
I’ve been happy with it running away for some time, adding in blacklist functions into the dial plan of incoming calls, blocking withheld numbers into entering their number and building up a list of numbers that are annoying me to reject. I’ve had a few people questioning when they’ve called about it. and even more from visitors whose witnessed the Tivo auto pausing if a call comes in as well as displaying who it is.

So after years of me singing it’s praises (as well as a linux server in general), it’s no-wonder that someone else wanted me to do a similar setup. Enter cousin 🙂

After weeks of searching on ebay, finally someone is selling a digium card. So bought it up quickly.

He’s had a Linux server running for a good few months, and I’ve got it all VPN’d together with my network.
So I installed the Digium card, installed asterisk, and went about configuring it using my config as the basis.
It all worked well, incoming and outgoing calls all fine using the card 2 phones connected and one line.
But obviously, now you’ve got a little you want more. So off he went looking at phones, I have to be fair he found a great deal of linksys phones, 4 of them with power for £40 when most are selling single units at over £20.

So I spend another few hours running network cables to 4 different locations in the house, connect up the phones and go back to configuring asterisk and the phones. Fairly straight forward, run through testing phone to phone etc, all appeared fine.

The following day I had a lovely call saying that their now getting one way audio. Straight away I thought that’s NAT, but as all the phones and asterisk box are on the inside NAT shouldn’t come into it. Still I went back through the SIP config and adjusted lots of it to completely wipe out NAT (I use NAT in my config as I have some connections from SIP providers etc).
More testing, but still the same.
So I started running SIP and RTP traces, I’ve had to read through them bother before and can just about follow what’s going on, but I mainly just look for anything obvious out of place, like IP addresses that are external etc.
Still after going through them, it all looked good in the SIP debug, but the RTP was only showing one side audio on calls that were going in / out over the Line. Calls to other phones were fine.
So I registered one of the phones onto my system and placed a call, that worked fine.
So I come home and registered one of my phones to his system. Placed the call, and again one way audio.

I’m not convinced it’s a NAT problem as my phone would now be running over the VPN to his server and it’s the same server that terminates the VPN. I now started checking out the codecs, but testing using different ones just pointed to it not being codecs. If it couldn’t find common ground the call failed from the start.

It took a few days to get back to as I was onto other stuff, but check after check just showed that everything was fine. But still the one way audio on calls.

I looked again and there was a new version of asterisk released 10.1.3, where I was using 10.1.2 on his server. The 2 fixes in the change were around SIP. So I downloaded the new version, compiled it and installed. Made sure it was all running and then got home to make some test calls.

Still one way audio. So I’m now left with one option. My own server is running an older version of asterisk, I uninstalled his asterisk completely and then downloaded the source for, compiled and then installed.
Using the same config from the 10.1.3 install threw a few warnings on loading, but it still loaded. Got him to make a test call, he called my mobile and hey presto we can hear each other.

I wanted to update my own asterisk, but after encountering this issue and especially as it’s still present in the latest I think I’ll leave updating my system for a while.

Bottom line, dont just consider One way Audio a NAT problem, and if everything looks to be working correct consider downgrading if there’s no upgrade available.

Ubuntu Upstart

Well I posted yesterday about handing over the control of my webcams script and the Zoneminder viewer xlib_shm to a daemon manager, as it seemed the right way to go and I noticed earlier tonight that my 2nd machine has again crashed out on the xlib_shm.
First I did a search for the daemontools to get an idea of what it’s like, but alot of the postings were older. So then decided to do an ‘alternatives’ search which brought up a few results, only one of which mentioned upstart in ubuntu, hey presto! I’ve heard upstart before but never looked at it (at least I thought).
Did a bit of looking around and yep I remember reading that Ubuntu is moving away from the init.d scripts a while ago just never put it together with the word upstart.
Basically there’s new files in /etc/init/ which is what upstart looks at and their the configs for each service that’s starting on the machine. Funnily enough I remembered then where why I’d done some searching previously on /etc/init/ and it was for gdm.conf because the gdm kept launching even though I’d removed it with the update-rc.d -f gdm remove. I was trying to kill it off because it was grabbing the screen before xlib_shm could.
Anyway that’s a bit of a side track. Looking at some of the configs there and the FAQ it looks quiet powerful and will do exactly what I need.

I was going to jump straight in and make a new config for the webcams stuff, but then noticed you can have a service start on another, well that should be good I only want webcams starting if zoneminder is running so let’s check that config, oh no there isn’t one yet. After 2 mins of searching for a config some clever person has already made I’m going to call it a night and have a proper look tomorrow. but it got me thinking of moving more over to Upstart like my asterisk stuff that will also need and depend on dahdi.
You can also depend on having a filesystem and networking. I can see the filesystem being used for the zoneminder config and both being used for the webcams config. So I’m really looking forward to getting into this a bit too. There’s only a handful of occasions when asterisk has shutdown so not a huge problem, but when it has I did once get left with no phone line for 3 days cause I didn’t know it wasn’t running (obviously enjoying the peace and quiet too much). To solve this I have Nagios monitoring now and using event handlers to restart via the init.d script but handing over to Upstart really does seem the way forward. I’d still keep Nagios monitoring to ensure it’s running I can’t live without my nagios watching over everything.

Home Temperature Sensors

Not going to go into the technical stuff on this post, far too tired. but wanted to try posting up an image to see if I had to host elsewhere or if it just goes, and thought this would be a good try.

A few years back I decided I wanted to put some temperature sensors in the house as we just never seem to be able to get all the rooms at a decent temp at the same time. You can be boiling hot in the one and freezing in another. Not much has changed with that respect but I do have more of an idea of what’s going on day by day and longer term. It’s really quite interesting. As I posted yesterday about the Raspberry PI board, one of my many wishes was to somehow get an interface to take over control of the central heating. It should be pretty straight forward, the biggest downside I don’t want to be screamed at having no heating if the computer freezes so need to build in over-rides.
Anyways, that’s the grand plan but below is a simple image I knocked together a few years back that uses php to colour in each of the rooms and write the current temp

From inside my network you can click on each of the rooms to get some stats. and the little blue dot is the set point I’d programmed up for when I do sort out the controller.

Due to my bad coding at the time (first real time I’ve done php from scratch not just had to change someone elses code) and the fact that I keep everything (database is now at 860k entries) the detail page is quite slow to load. I should really rewrite it to store upto date stats elsewhere and then hourly just update that table with the totals. I may get around to it.
I did used to use MRTG to also connect into the database and pull the stats to have some nice graphs. This worked really well until I changed alot of my network kit that MRTG was polling, and I shut it down to give it a full clean up.

Anyway to get all this stuff going I use the OneWire Temp sensor DS18S20 I think it has a + on some of the chips I use but not all. I bought them online from a website with sheep in the title something like sheepwalk sheepcottage, can’t remember I’ll dig that out when I’m going through it a bit more. They were decent prices then maybe not now. but I received them very quick and they were helpful.

A thing to note that I’ll go into when I put the scripts up but this will prompt me, I do get alot of nulls coming back in the results. I know this is due to my mainly star configuration of the sensors and the fact that I dont provide power to the chips (bad idea when running a few). I did it because I was being lazy and using the 2 spare cables I had in the wire going to each of the alarm sensors for each room. It made sense at the time and it actually works really well as I didn’t have to run new cables and the temp sensor is hidden by the alarm sensor itself. Being close to the top of the ceiling I did expect it to skew the temp results (heat rises) but it actually seems to be pretty close when I compared them to an independent weather station sensor I used to see.

Oh and the green outside the house in the pic is also programmed to be changed. it’s green showing sensor fault (there isn’t one) I always planned to stick a sensor outside front and back and take an average reading for the colour. just havn’t got around to running a cable outside for that bit. So many things to do so much left unfinished 🙂

Zoneminder rotating Webcam images.

Note: I’ve made an entire new system running from a database that can accommodate multiple rotating outputs, because I liked seeing the webcams so much on my tv along with my own cctv. I leave this here as an idea script. btw, there was an update for 3 monitors based on the below that used this very script, but I’m going to jump straight to the database one as it’s much better.

I had the idea to include some public webcams onto my zoneminder monitor, I’m already running xlib_shm so was considering find a way within that code to pickup some jpegs and display them in one area. However this seemed overly complicated, it seemed a much simpler idea to create a new monitor in zoneminder that picks up from a local file and just add that monitor onto the xlib_shm line in the xinitrc file so it displays on bootup.

So the steps.
1) create a new directory /var/cache/zoneminder/webcams
2) create a text doc to hold the url’s /var/cache/zoneminder/webcams/urls.txt for example “http://www.ceredigion.gov.uk/english/visiting/aber_webcam/img/994.jpg” without “
3) create a text doc ~/webcams.sh with the following :
echo Directory : $DIR
echo Pull Interval : $PULLINTERVAL
echo Rotate Interval : $ROTATEINTERVAL
cd $DIR
for i in `cat $DIR/urls.txt`
   wget -q $i -O $FILENO.jpg
convert $CURRENTIMAGE.jpg -resize 640x480! rotate.jpg
if [ "$CURRENTIMAGE" -eq "$FILENO" ]; then
PGREPXLIB=`pgrep xlib_shm`
 if [ -z $PGREPXLIB ]; then
   startx &
while true; do
DATE=`date +%s`
   if [ "$DATE" -gt "$NEXTPULL" ]; then
   if [ "$DATE" -gt "$NEXTROTATE" ]; then
   if [ "$DATE" -gt "$NEXTXLIBCHECK" ]; then
sleep 2
4) chmod +x ~/webcams.sh
5) Now add a new monitor to Zoneminder pulling from a local file /var/cache/zoneminder/webcams/rotate.jpg with dimensions 640×480.
6) After testing that this script runs while I’m connected via putty, I add the following to /etc/init.d/zoneminder under the startx & ‘/root/webcams.sh &’. That way when the computer starts up and everything is displayed the webcams script is also started and away it rotates.
7) Add the following to /etc/init.d/zoneminder under the stop section where I added kill -9 xlib_shm ‘killall -9 webcams.sh’. Now the script is stopped if zoneminder is stopped.
One thing to note is that restarting zoneminder via the interface is not the same as running /etc/init.d/zoneminder restart. So the script and does not get reset when restarting via the interface.

Zoneminder XLIB_SHM

Ok it’s been a good while since my last post, and it’s not that I haven’t been doing anything, just not writing about it. Which just creates problems when I need to remember how what I did and how.

I needed something to get my monitors back on my similar to my windows setup. That used to rotate around the cameras and would bring to the front specific cameras when motion was detected.

After a bit of searching I found xlib_shm http://www.zoneminder.com/wiki/index.php/Xlib_shm
Although it says it only works with 1.22.3, I’m currently running 1.24.2 on Ubuntu 11.04.

So after installing it and trying to run via the command line “./xlib_shm -m 11 -m 12 -m 3 -m 13 -m 14 -c 2 -k 0x7a6d0000” it complained about not being able to open the display. of course I’m running it from a terminal on the server itself, but gdm is already lauched and I’d alt+ctrl+f1’d out of it. So I stopped gdm with “/etc/init.d/gdm stop” and tried again, hey presto it runs.

So now how do I get this to run on boot?

One option is to have gdm auto login and then auto run xlib_shm. I had a few problems with this approach, First the login counter, it takes a few seconds to auto login and kick in xlib_shm and it’s just a bit untidy. Second xlib_shm launches in a window doesn’t look very pretty and I’d prefer full screen. Third was the mouse pointer happily sat smack in the middle of the screen, not a huge problem for a 4 split, but single screen or 9 and it’s in the way of the main detail on the picture.

So kill that idea, I want it straight in no hassle as quick as it can. So the best thing I could come up with was stop gdm launching and make a new script to startup xlib_shm. unfortunately this approach seemed to hit it’s own problems. killing gdm wasn’t as easy as it should have been because of changes in the way it’s now started in Ubuntu 11.04, and adding xlib_shm into the init.d was proving unreliable sometimes it beat gdm and grabbed the screen othertimes it didn’t.

So I had to find another way, and my answer was to try and figure out how X was started.

I ended up editing ‘/etc/X11/xinit/xinitrc’
commenting out the ‘/etc/X11/Xsession’ line and adding ‘exec /usr/sbin/xlib_shm -m 11 -m 12 -m 3 -m 13 -m 14 -m 15 -m 18 -m 19 -m 20 -c 3 -k 0x7a6d0000’ to the bottom.
now starting X with “startx” fires up xlib_shm full screen with a 9 split.
Problem hit though with the screen turning itself off.
Found out that setting a couple of dpms options then starting x would solve this so added the following into the xinitrc file after the exec line

xset s off &
xset -dpms &

Now to get this starting with the boot. Solution edit the ‘/etc/init.d/zoneminder’
Within the start section add ‘startx &’ and in the stop section add ‘killall -9 xlib_shm’.
Now on each reboot X starts up with xlib_shm and the screen doesn’t shutoff at all.

I’ve no doubt theres bits in here that I’ve missed, I got this all running months ago. When I did the same similar on a 2nd system, it was pretty straight forward and similar but I did hit another issue.
For some reason xlib_shm would occasionally crash out and return to the command prompt. However between this change and installing that I’d setup scripts to pull a few webcams and display them on a zoneminder monitor rotating the image. As that script fires a rotate every 10 seconds, my answer to the crashing was to add a check into this script to see if xlib_shm was running and if not to startx &.

So that’s the brief outline of me getting xlib_shm to work with Zoneminder 1.24.2 on Ubuntu 11.04.

One thing to note, restarting zoneminder via the interface is not the same as running /etc/init.d/zoneminder restart. Because of this via the interface does not restart xlib_shm. This causes problem (mainly when I was testing) because the zoneminder feeds would shutdown and xlib_shm would then crash. I got used to only restarting via the commendline, but the script mentioned above would counter this problem should xlib_shm crash now.

ZoneMinder Browser Streaming

Got Zoneminder installed and running again. alot of fine tuning to be done, but so far so good.
Here’s the current setup:-
Ubuntu 11.04
Anykeeper 2016 Card
Zoneminder 1.24.2
6 Cameras connected
only 1 of the anykeeper cards in atm.

The anykeeper card isn’t exactly stable, 2 of the images are light flickering not a clue why they’ve been stable with this card before under windows and another card so guessing it’s down to the mix of card and config. I can live with it though as it doesn’t setoff the motion you can just see it pulsing when on live view.

Think I’ll be ordering another card though that is known to work with zoneminder, having something nice and stable would be nice.

One thing that has been bugging me though is the streaming options. When using Chrome I’ve had to manually select Yes on the Can_Stream to kick in the live view as the auto just sits there.
However I found this http://www.zoneminder.com/forums/viewtopic.php?t=15429
Incase it gets removed I’ll copy the instruction below

In file include/functions.php, change the following which is at around line 823 (May vary from installation to installation): 

    elseif (ereg( ‘Opera ([0-9].[0-9]{1,2})’,$_SERVER[‘HTTP_USER_AGENT’],$logVersion))


    elseif (ereg( ‘Opera/([0-9].[0-9]{1,2})’,$_SERVER[‘HTTP_USER_AGENT’],$logVersion))

In around line 876 (May vary from installation to installation), change:

function canStreamNative()
   return( ZM_CAN_STREAM == “yes” || ( ZM_CAN_STREAM == “auto” && (isNetscape() || isKonqueror()) ) );


function canStreamNative()
   return( ZM_CAN_STREAM == “yes” || ( ZM_CAN_STREAM == “auto” && (isNetscape() || isKonqueror() || isOpera() || isSafari()) ) );

In around line 840 (May vary from installation to installation), find this:

function isNetscape()
    getBrowser( $browser, $version );

    return( $browser == “mozilla” );

Add this below it or above it:

function isOpera() {
    getBrowser( $browser, $version );
    return( $browser == “opera” );
function isSafari() {
    getBrowser( $browser, $version );
    return( $browser == “safari” );

 Next I have to get the PTZ up and running. Will post up my solution to that one as so far I’ve had no joy.

OpenVPN Connection Sever 2 Server Ubuntu

I’ve got a few VPN links in place using OpenVPN and thought it’s about time I documented how incase something goes wrong in the future.

First was the install:-

apt-get install openvpn

Once installed:-

cd /etc/openvpn

Then Generate a key using:-

openvpn --genkey --secret static.key

Create the config file using:-

nano -w server2.conf
remote server2.example.co.uk
port 8008
dev tun203
proto udp
ping 15
secret /etc/openvpn/static.key
chroot /var/empty
user nobody
group nogroup
log vpn.log
verb 0

Things that need changing are the server address and the local and remote IP addresses. Also check the chroot, user and group exist.
Next copy the static.key from server1 to server2. Then create a server1.conf in /etc/openvpn/

nano -w server1.conf
remote server1.example.co.uk
port 8008
dev tun203
proto udp
ping 15
secret /etc/openvpn/static.key
chroot /var/empty
user nobody
group nogroup
log vpn.log
verb 0

Notice how the IP configuration on this server is reversed. These IP addresses are just used by the tunnel and do not have to be within your normal network range. However for routing to multiple network segments it seemed easier to keep these addresses within the network range for me so it’s easier to trace where the fault lies if something goes wrong.
Last thing to check is that ip_forwarding is also enabled

cat /proc/sys/net/ipv4/ip_forward

Once the connections are established, it’s probably worth having some routing info pushed to each server. For simple routing you can uncomment the option in the configs above. For more advanced routing it’s worth installing Quagga.

I’ll need to update this with better details on what the configs do. But that’ll get it running in a simple setup.

Ubuntu 10.10 and Chrome Missing Plugins

Re-installed my laptop about a week ago with Ubuntu 10.10. Finally killed off the Windows partition that wasn’t working properly anyway. So took the opportunity to install a fresh Ubuntu 10.10 with disk encryption. Everything seemed to be working fine. that is except Chrome.
I couldn’t access my CCTV system using chrome like I used to. If you access it from Windows IE you get a nice little request whether to load the mpeg viewer or access jpeg stills. But never had that prompt in Chrome after auth it just loads up an image viewer that’s opens up a single camera view.

But now I’m just stuck with ‘Missing Plugin’ in a nice grey box. I’ve already loaded up Flash, Quicktime, VLC, and a few other plugins and video playback works. but the CCTV just didn’t! It was bugging me, but I’d just kinda left it. Tonight though I ended up installing ZoneMinder for someone, and after a few permissions problems finally got the camera up and running, but it was doing a simple jpeg image refresh every 5 secs. I remembered from a few years ago downloading cambozola(?).jar so went looking and found it. Installed it and tried again, boom ‘Missing Plugin’.

After some searching I found that there’s an option in Zoneminder to change Options > Images > CAN_STREAM it’s normally set on Auto. but if you change it to Yes, it makes the ‘Missing Plugin’ in Chrome go away.

But this isn’t a solution to me as my own CCTV is old software that almost certainly doesn’t have an option in anyway similar. So onto more searching for jpeg streaming chrome and ubuntu. By chance I stumbled onto a java site and oh look ‘Missing Plugin’ again.

Of course it is, I haven’t installed Java yet, DOH!

A quick search of the Ubuntu software and I installed the OpenJDK Java 6 Runtime. Restarted Chrome and it’s still not working. Uninstalled OpenJDK and then went off doing a manual install of Java and creating a symbolic link of the necessary files into the Chrome directory alongside the Flash and Quicktime plugins. But it still doesn’t work.

So back to the drawing board. Removed all the manual stuff and back to installing OpenJDK Java 6 Runtime via the Ubuntu Software. Then I also installed iced6tea-plugin. Yahoo it works. I now have access to my CCTV again using Chrome on Ubuntu.

So Bottom Line:-
If your getting ‘Missing Plugin’ messages in Chrome, make sure you have Java installed.
Ubuntu Software >
OpenJDK Java 6 Runtime