Monday, March 24, 2008

Sharing your X desktop via VNC

When getting set up to share my Linux X desktop, I found to my temporary confusion, that unlike vncserver on Windows, which of course shares your existing desktop, the vncserver program for X is designed to start a new instance of an X server (possibly even blind to the person on the machine) and share *that* rather sharing your existing desktop, which is probably what you usually need to do!

To share your existing X desktop via VNC requires another tool called x0vncserver.

As far as I know this is only available with vnc4 (realvnc) and not with tightvnc.

To share my desktop, the first thing I needed to do was to create a password file for the incoming user to authenticate against:


$ vncpasswd .vnc/passwd
Password:
Verify:


The .vnc directory didn't need to exist already, it creates it for you.


$ ll .vnc/
total 12
drwxr-xr-x 2 john john 4096 Mar 20 15:28 .
drwxr-xr-x 52 john john 4096 Mar 20 15:28 ..
-rw------- 1 john john 8 Mar 20 15:28 passwd


It only seems to use the first 8 characters, and then saves that as obfuscated binary data.

Once you have the password file you can launch x0vncserver against it:


$ x0vncserver PasswordFile=.vnc/passwd

Thu Mar 20 15:33:32 2008
main: XTest extension present - version 2.2
main: Listening on port 5900


and it is ready to accept incoming connections :o)

If the incoming user is using tightvnc or another client that does not support the vnc4 protocol extensions, then you need to tell it to run in vnc3.3 compatibility mode:


$ x0vncserver Protocol3.3 PasswordFile=.vnc/passwd


You can also get usage help from x0vncserver by running it with any args it doesn't understand:


$ x0vncserver .

Friday, March 07, 2008

suspend to disk on low battery...

I found out why my machine was shutting down at low battery and why I couldn't get it to suspend to disk instead...

Fixed now :o)

You need to look at these files:


/etc/powersave/battery


I changed these values:


BATTERY_WARNING="10"
BATTERY_LOW="5"
BATTERY_CRITICAL="0"


And in:


/etc/powersave/events


I now have these:


EVENT_BATTERY_LOW="notify"
EVENT_BATTERY_CRITICAL="notify john_suspend_to_disk"


NB: I put john in the name so it would stick out like a sore thumb when I do a diff if dpkg ever asks me about changed config files on an upgrade and I'll know it's my own modification, and so it didn't conflict with or get overwritten by a provided script.

I created my own script to handle this:


/usr/lib/powersave/scripts/john_suspend_to_disk


which just has:


#!/bin/sh
#
#
#

sleep 10

/usr/sbin/s2disk

#
# You could use:
# echo -n disk > /sys/power/state
#


And I installed uswsusp which provides /usr/sbin/s2disk

Oh... I also set up a shell function to protect it, because I found I accidentally scrolled back through my shell history and hit enter on s2disk a couple of times ;o)


# type s2disk
s2disk is a function


I put this in my .bashrc:


s2disk ()
{
echo -e "Confirm you want to suspend: \c";
read OK;
if [ "$OK" = "y" ]; then
/usr/sbin/s2disk;
fi
}


What I *would* also like to add is a notify when the battery reaches 100% so I know to unplug my charger - I understand it's much better for the longevity of your battery if you don't leave it plugged in on full charge all the time and instead allow it to do full flat-charged-flat power cycles. I have a couple of laptops with useless batteries due to them having been left plugged in and running 24x7 for months or years on end - my Linux boxes rarely get shut down.

In an ideal world I'd like some device that plugged in between the charger plug and the laptop which I could drive from the OS to physically break the power connection when the battery gets to 100% - and not to reconnect it again until it's back to 0% (yes, I find with my reasonably new battery I can actually keep running it quite a while after it reaches "0%" - obviously 0% isn't dead flat - it's an arbitrary level set to give you a safety margin and still work when your battery is getting a bit knackered due to age.)

Wednesday, March 05, 2008

Problems installing vmplayer on Debian

I downloaded VMware-player-2.0.2-59824.i386.rpm and converted it with alien.


# alien VMware-player-2.0.2-59824.i386.rpm --scripts


I had installed it before, then removed it to install vmware-server (because vmware-server complained that installing it caused file conflicts with vmplayer) and later removed vmware-server again and reinstalled vmplayer.

The bits left behind by vmware-server seem to break it...
The nice thing would be to find them and remove them, but I found a workaround.

When I first tried to install the player again I got error messages from some of the install scripts:


dpkg: error processing vmwareplayer_2.0.2-59825_i386.deb (--install):
subprocess pre-installation script returned error exit status 1
/var/lib/dpkg/tmp.ci/postrm: line 25: [: abort-install: integer expression expected
Errors were encountered while processing:
vmwareplayer_2.0.2-59825_i386.deb


So I backed up the deb file and built a copy of it with no scripts using:


# alien VMware-player-2.0.2-59824.i386.rpm


(and renamed that vmwareplayer_2.0.2-59825_i386.deb.no_scripts)

I was able to install it, but when I tried to run the player I found more hangovers of having had vmware-server installed:


$ vmplayer
Unable to load image-loading module: /build/mts/release/bora-59824/bora/build/release/ws/vmui/../libdir/libconf/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-png.so: /build/mts/release/bora-59824/bora/build/release/ws/vmui/../libdir/libconf/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-png.so: cannot open shared object file: No such file or directory


I made sure it was there:


$ locate libpixbufloader-png.so
/usr/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-png.so


Eventually I found the solution was to run:


# /usr/bin/vmware-config.pl


but... that failed:


# /usr/bin/vmware-config.pl
Making sure services for VMware Player are stopped.

sh: /etc/init.d/vmware: No such file or directory
sh: /etc/init.d/vmware: No such file or directory
Unable to stop services for VMware Player

Execution aborted.



OK, so fake it:

Make a copy of /etc/init.d/vmware containing:


#!/bin/bash

echo $1


then:


# chmod +x /etc/init.d/vmware


Now run the config again:


# /usr/bin/vmware-config.pl
Making sure services for VMware Player are stopped.

status
stop

Configuring fallback GTK+ 2.4 libraries.

In which directory do you want to install the theme icons?
[/usr/share/icons]
...


and go through the rest of the config.

After this (if you have your correct compiler etc installed, you should find that vmplayer will start happily)

Once that works you will find you can now go back and over-install the copy of vmwareplayer_2.0.2-59825_i386.deb that DOES have scripts without it erroring, so you get your correct startup scripts etc...

Once you've reinstalled it you will again need to run


# /usr/bin/vmware-config.pl


one more time otherwise trying to run vmplayer will give you:


$ vmplayer
vmware is installed, but it has not been (correctly) configured
for this system. To (re-)configure it, invoke the following command:
/usr/bin/vmware-config.pl.