WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to get a virtual remote desktop working.  (Read 9379 times)

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
How to get a virtual remote desktop working.
« on: May 22, 2009, 02:25:25 PM »
[updated May 23rd, 2009
 - Added information related to 'Refresh Screen' script changes
 - Changed the tcz-uninstall command line
 - Added Turn ON and Off Remote Desktop menu Button description]

It's Friday and time to wrap up another week working with Tinycore. I thought it might be useful to sum up my experience getting a remote desktop working that is the same as the local one. The same meaning the flwm background, wbar and menu are in sync. Applications can be installed at either the local or remote end and will be seen at the other end. I tried using both realvnc and tightvnc as the remote desktop server and ended up using tightvnc with the tightvncviewer on a windows machine. I use a secure vpn to my router for remote access to my home network so I don't need a ssl connection to the Xvnc server.

I should point out that my primary application for Tinycore is a webserver so I keep all applications that are not needed for the webserver in the tce/optional directory. I use only tcz applications since I am very limited in memory and install them only when needed. I created the following script to install/start, stop/uninstall and restart the remote desktop. I'm not a script writter so I don't claim that this script is flawless.

Anyway the start function replaces wbar.sh, flwm_restart and 'Refresh Screen' with changed versions, per some excellent advice from Robert and curaga, to accommodate a two display environment. The two displays being local (display=:0.0) and remote (display=:1.0). Without changes to these three files wbar updates and menu updates fall out of sync. Also the updates shutdown the local or remote wbar or flwm processes depending on circumstances. It gets quite confusing.

Next the start function installs the tightvnc application and then activates the Xvnc server. The Xvnc server needs the screen size and color depth set in the command line.

Once the Xvnc server is running the remote display needs to be configured. The conf function sets the background color and activates a wbar and flwm instantiation for the remote display (display=:1.0).

The stop function kills the Xvnc server process and transfers control to the tcz uninstall script. My intent here was to perform the uninstall of tightvnc but the tcz-uninstall script doesn't support this yet. [update- I changed the uninstall command to make use of Jason's latest tcz-uninstall.tcz version.] 
Code: [Select]
#!/bin/sh

 stop()
    {
    echo "Stopping tvnc..."
    sudo killall Xvnc 2>&1 > /dev/null &
    tcz-uninstall tightvnc 2>&1 > /dev/null &
    }

 start()
   {
   echo  "Starting tvnc..."
   sudo cp -f /mnt/sdc1/wbar.sh /usr/bin  2>&1 > /dev/null &
   sudo cp -f /mnt/sdc1/flwm_restart /usr/bin 2>&1 > /dev/null &
   sudo cp -f /mnt/sdc1/'Refresh Menu' /home/tc/.wmx 2>&1 > /dev/null &
   tce-load /mnt/sdc1/tce/optional/tightvnc.tcz &
   sleep 2
   Xvnc -geometry 1024x768 -depth 16 :1 2>&1 > /dev/null &
   sleep 3
   DISPLAY=:1.0 config
   }

 restart()
  {
  echo  "Restarting tvnc.."
  stop
  sleep 3
  start
  }

 config()
 {
  xsetroot -solid "#4f5f82"
  /usr/bin/wbar -bpress -config /usr/local/tce.wbar 2>&1 > /dev/null &
  /usr/bin/flwm 2>&1 > /dev/null &
 }

case "$1" in
  start) start;;
  stop) stop;;
  restart) restart;;

  *)
   echo "Usage: $0 {start|stop|restart}"
   esac
Here is the changed version of the wbar.sh script. It starts wbar from within the DISPLAY command for both the local and remote display. The remote display wbar is only started if /tmp/.X11-unix/X1 (X11 display 1)is present.
Code: [Select]
#!/bin/sh
cd "$HOME"
if [ $(awk '/icons:/{print $2}' "$HOME"/.desktop) == wbar ]; then
   WBARPID=$(pidof wbar)
   [ -n "$WBARPID" ] && killall wbar
   DISPLAY=:0.0 wbar -bpress -config /usr/local/tce.wbar > /dev/null &
   [ -e /tmp/.X11-unix/X1 ] && DISPLAY=:1.0 wbar -bpress -config /usr/local/tce.wbar > /dev/null &
fi
Here is what I changed in the flwm_restart script. It starts flwm from within the DISPLAY command for both the local and remote display. The remote display flwm is only started if /tmp/.X11-unix/X1 (X11 display 1)is present.
Code: [Select]
#!/bin/sh

restart() {
 killall flwm
 DISPLAY=:0.0 flwm &
 [ -e /tmp/.X11-unix/X1 ] && DISPLAY=:1.0 flwm &
 }

 WBARPID=$(pidof flwm)
 [ -n "$WBARPID" ] && restart

Here is what I changed in the 'Refresh Screen' tool script. It starts flwm from within the DISPLAY command for both the local and remote display. The remote display flwm  is only started if /tmp/.X11-unix/X1 (X11 display 1)is present.

Code: [Select]
#!/bin/sh
pkill flwm
DISPLAY=:0.0 flwm &
[ -e /tmp/.X11-unix/X1 ] && DISPLAY=:1.0 flwm &

Although I have attempted to have all command output sent to the null device the Xvnc server still sends information to the console as shown below. Other messages appear as well.
Code: [Select]
tc@box:/mnt/sdc1$ ./tvnc start
Starting tvnc...
/mnt/sdc1/tce/optional/tightvnc.tcz
22/05/09 15:13:00 Xvnc version TightVNC-1.3.9
22/05/09 15:13:00 Copyright (C) 2000-2007 TightVNC Group
22/05/09 15:13:00 Copyright (C) 1999 AT&T Laboratories Cambridge
22/05/09 15:13:00 All Rights Reserved.
22/05/09 15:13:00 See http://www.tightvnc.com/ for information on TightVNC
22/05/09 15:13:00 Desktop name 'x11' (box:1)
22/05/09 15:13:00 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
22/05/09 15:13:00 Listening for VNC connections on TCP port 5901
Font directory '/usr/lib/X11/fonts/Speedo/' not found - ignoring
Font directory '/usr/lib/X11/fonts/Type1/' not found - ignoring
Font directory '/usr/lib/X11/fonts/100dpi/' not found - ignoring
tc@box:/mnt/sdc1$ Xlib:  extension "Generic Event Extension" missing on display ":1.0".

tc@box:/mnt/sdc1$
22/05/09 15:13:16 Got connection from client 192.168.0.114
22/05/09 15:13:16 Using protocol version 3.8
22/05/09 15:13:16 Enabling TightVNC protocol extensions
22/05/09 15:13:16 Pixel format for client 192.168.0.114:
22/05/09 15:13:16   16 bpp, depth 16, little endian
22/05/09 15:13:16   true colour: max r 31 g 63 b 31, shift r 11 g 5 b 0
22/05/09 15:13:16   no translation needed
22/05/09 15:13:16 Using hextile encoding for client 192.168.0.114
22/05/09 15:13:16 rfbProcessClientNormalMessage: ignoring unknown encoding 8
22/05/09 15:13:16 Enabling X-style cursor updates for client 192.168.0.114
22/05/09 15:13:16 Enabling cursor position updates for client 192.168.0.114
22/05/09 15:13:16 Using image quality level 9 for client 192.168.0.114
22/05/09 15:13:16 Enabling LastRect protocol extension for client 192.168.0.114
22/05/09 15:13:16 rfbProcessClientNormalMessage: ignoring unknown encoding -223
I will do more testing but so far the local and remote desktops seem to be cooperating.

I created a turn On and Off remote desktop toggle menu button as a convenience. I created a file in the /home/tc/.wmx/Tools folder with the content shown below. Note the file name is changed by the script as a way to toggle the name in the menu.

Code: [Select]
#!/bin/sh

 start(){
  /mnt/sdc1/tvnc start 2>&1 > /dev/null &
  sleep 4
  mv /home/tc/.wmx/Tools/'TurnOn RemoteDeskTop'  /home/tc/.wmx/Tools/'TurnOff RemoteDeskTop'  2>&1 > /dev/null &
  /usr/bin/flwm_restart 2>&1 > /dev/null &
 }

 stop(){
  /mnt/sdc1/tvnc stop 2>&1 > /dev/null &
  sleep 4
  mv /home/tc/.wmx/Tools/'TurnOff RemoteDeskTop'  /home/tc/.wmx/Tools/'TurnOn RemoteDeskTop'  2>&1 > /dev/null &
  /usr/bin/flwm_restart 2>&1 > /dev/null &
     }

 PID=$(pidof Xvnc)
 [ -n "$PID" ] && stop || start
« Last Edit: May 23, 2009, 07:36:26 AM by bigpcman »
big pc man

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7344
  • Founder Emeritus
Re: How to get a virtual remote desktop working.
« Reply #1 on: May 22, 2009, 06:05:20 PM »
Very interesting. Thanks for sharing.
10+ Years Contributing to Linux Open Source Projects.

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to get a virtual remote desktop working.
« Reply #2 on: May 23, 2009, 04:41:02 AM »
After a little more testing I found an obvious problem. The "Refresh Menu" tool script was also "pkilling" off all instantiations of flwm. So I had to change that file as well:

#!/bin/sh
pkill flwm
DISPLAY=:0.0 flwm &
[ -e /tmp/.X11-unix/X1 ] && DISPLAY=:1.0 flwm &

I will update my original post.
big pc man

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to get a virtual remote desktop working.
« Reply #3 on: May 23, 2009, 07:21:25 AM »
I created a TurnOn and TurnOff RemoteDeskTop toggle menu button to manage the remote desktop script described in my original post. I'll update the original post.

Code: [Select]
#!/bin/sh

 start(){
  /mnt/sdc1/tvnc start 2>&1 > /dev/null &
  sleep 4
  mv /home/tc/.wmx/Tools/'TurnOn RemoteDeskTop'  /home/tc/.wmx/Tools/'TurnOff RemoteDeskTop'  2>&1 > /dev/null &
  /usr/bin/flwm_restart 2>&1 > /dev/null &
 }

 stop(){
  /mnt/sdc1/tvnc stop 2>&1 > /dev/null &
  sleep 4
  mv /home/tc/.wmx/Tools/'TurnOff RemoteDeskTop'  /home/tc/.wmx/Tools/'TurnOn RemoteDeskTop'  2>&1 > /dev/null &
  /usr/bin/flwm_restart 2>&1 > /dev/null &
     }

 PID=$(pidof Xvnc)
 [ -n "$PID" ] && stop || start

edit: The menu button script when activated by the menu creates console output as shown below. How can I prevent this?

Code: [Select]
tc@box:~/.wmx/Tools$  PID=$(pidof Xvnc)
tc@box:~/.wmx/Tools$  [ -n "$PID" ] && stop || start
[2] - Done                       mv -i /home/tc/.wmx/Tools/"TurnOn RemoteDeskTop" /home/tc/.wmx/Tools/                                                      RemoteDeskTop" 2>&1 1>/dev/null

edit 2: I have not been able to repeat this behavior. The output showed up on my remote ssh terminal. I restarted the ssh session and now there is no output to either the local or remote ssh console. Very strange.
« Last Edit: May 23, 2009, 08:36:51 AM by bigpcman »
big pc man

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to get a virtual remote desktop working.
« Reply #4 on: June 07, 2009, 09:01:19 PM »
08/10/2009 - Update Edit: As of tc 2.2 the background color on the remote display was no longer being set by xsetroot. I had to add the -display :1 option to the command as shown below in the "start()" part of the tvnc script.
----------------------------------------------------------------------------------------------------------------------------
This is an update to my previous posts on this subject. Now that the final 2.0 tc has gone back to jwm as the default window manager I did too. However, that caused some problems in my remote desktop connection manager.

Previously I had to change flwm_restart and wbar.sh to accommodate a local and remote monitor. With tc2.0 I had to change wbar.sh and jwm_restart since the jwm window manager is being used. See the changes below. Please keep in mind I don't claim what I am posting to be flawless.

Code: [Select]
original /usr/bin/jwm_restart
#!/bin/sh
pidof jwm >/dev/null && jwm -restart
Code: [Select]
Modified  /usr/jwm_restart
#!/bin/sh

restart() {
  jwm -restart &
  [ -e /tmp/.X11-unix/X1 ] && DISPLAY=:1.0 /usr/bin/jwm &
   }

pidof jwm >/dev/null  &&  DISPLAY=:0.0 restart

Code: [Select]
original  /usr/bin/wbar.sh
#!/bin/sh
cd "$HOME"
if [ $(cat /etc/sysconfig/icons) == wbar ]; then
   WBARPID=$(pidof wbar)
   [ -n "$WBARPID" ] && killall wbar
   wbar -bpress -config /usr/local/tce.wbar > /dev/null &
fi

Code: [Select]
Modified  /usr/bin/wbar.sh
#!/bin/sh
cd "$HOME"
if [ $(cat /etc/sysconfig/icons) == wbar ]; then
   WBARPID=$(pidof wbar)
   [ -n "$WBARPID" ] && killall wbar
   DISPLAY=:0.0 wbar -bpress -config /usr/local/tce.wbar > /dev/null &
   [ -e /tmp/.X11-unix/X1 ] && DISPLAY=:1.0 wbar -bpress -config /usr/local/tce.wbar > /dev/null &
fi

I also cleaned up the remote desktop connection manger script a bit. The script handles the install/start and the stop/uninstall of tightvnc as I have described in previous posts. See below.

Code: [Select]
#!/bin/sh
# bigpcman June 7, 2009
# Remote Desktop Xvnc Server install/start and stop/uninstall
# Download tightvnc.tcz to tce/optional
# My usb persistent storage = /mnt/sdc1
# The script manages a wbar button that toggles between on/off images
# The on/off images are initialized by the bootlocal.sh script
# Modified versions of wbar.sh and jwm_restart are required to activate remote monitor.

 stop()
    {
    echo "Stopping tvnc..."
    sudo killall Xvnc 2>&1 > /dev/null &
    sleep 2
    sudo cp -f /mnt/sdc1/mywbar/tvnc-wbar-off.png /mnt/sdc1/mywbar/tvnc-wbar-active.png 2>&1 > /dev/null &
    tcz-uninstall tightvnc --force --purge 2>&1 > /dev/null &
    }

 start()
   {
   echo  "Starting tvnc..."
   sudo cp -a /mnt/sdc1/wbar.sh /usr/bin  2>&1 > /dev/null &
   sudo cp -a /mnt/sdc1/jwm_restart /usr/bin 2>&1 > /dev/null &
   sleep 2
   tce-load /mnt/sdc1/tce/optional/tightvnc.tcz
   sudo cp -a  /mnt/sdc1/mywbar/tvnc-wbar-on.png /mnt/sdc1/mywbar/tvnc-wbar-active.png 2>&1 > /dev/null &
   Xvnc -geometry 1024x768 -depth 16 :1  2>&1 > /dev/null &
   sleep 3
   xsetroot -display :1 -solid "#4f5f82"
   /usr/bin/jwm_restart
   sleep 2
   /usr/bin/wbar.sh
   }

 restart()
  {
  echo  "Restarting tvnc.."
  stop
  sleep 3
  start
  }

case "$1" in
  stop) stop;;
  restart) restart;;
  start)  PID=$(pidof Xvnc)
             [ -n "$PID" ] && echo "Xvnc already started" || start;;

  *)
   echo "Usage: $0 {start|stop|restart}"
   esac
« Last Edit: August 10, 2009, 08:02:39 AM by bigpcman »
big pc man

Offline gwalther

  • Jr. Member
  • **
  • Posts: 93
Re: How to get a virtual remote desktop working.
« Reply #5 on: March 27, 2010, 07:15:56 PM »
After spending many hours trying to get the...tightvnc extension to work, I found this post.
After studying your scripts and trying my own versions based on yours, I now have ..tightvnc working.

Thanks so much,bigpcman,  for taking the time to share your scripts.

I think the instructions posted with the tightvnc extension should be changed by adding a "&" after both
Xvnc :1
DISPLAY=:1.0

it would really help us newbies  get off the ground

Offline stunix

  • Newbie
  • *
  • Posts: 10
    • stunix.com
Re: How to get a virtual remote desktop working.
« Reply #6 on: February 18, 2011, 11:04:35 AM »
wow now Im confused.  so in a nutshell, how can I simply get Xvnc running at boot with wbar and flwm?

<edit>

ok, after a little fiddle i have a down and dirty way. 

1, apply the tightvnc from the repo
2, edit ~/.xsession and on a newline after "waitforX" add :-
           Xvnc -geometry 1024x768 -depth 24 :1 &
3, at the bottom of the same file add :-
           DISPLAY=:1 "$DESKTOP" &
           DISPLAY=:1 setbackground fill /opt/backgrounds/"$BACKGROUND" &
4 as root, edit /usr/bin/wbar.sh and comment the two lines in the middle containing WBARPID (by putting a # at the beginning of the line)
then add this file to /opt/.filetool.lst for persistance.
5  your vncserver will now start on boot, use your vncviewer on linux or ultr@vnc on doze and point it to 192.168.0.?:1 or the ip of your tc no password needed.

this sort of thing may make some people scream but ittl work if your in a hurry.

</edit>
« Last Edit: February 18, 2011, 05:44:48 PM by stunix »

Offline oldgit485

  • Newbie
  • *
  • Posts: 18
Re: How to get a virtual remote desktop working.
« Reply #7 on: October 10, 2011, 01:36:03 PM »
Hi stunix,
I am trying to put TC4.01 on a Toshiba Magnia SG30 very similar to Lees SG20.I have followed Lees lead and installed the hdd in my laptop and it works fine,ie I can VNC to it from my windows machine using tightvnc. having followed your information in the previous post,I  get a 1024x768x24 grey screen but by right clicking I get the options,click on control panel then wallpaper and then "done" and it works well.When I transfer the hdd to the magnia and use the same commands it fails to connect, I think vnc is not starting,however if I ssh to the magnia using putty and type Xvnc :1 it appears to start vnc and i get a few lines on the screen.If I then try vnc again I get the grainy grey screen  (at 640x480x8)but right clicking does not give the system options. I am not too familiar with the CLI yet so would like the back up of a gui for now.I have installed xampp and it all appears good whilst in the laptop.My feeling is that the edits in .xsession are not being passed to the Display ?
Thanks in anticipation
oldgit

Offline Lee

  • Hero Member
  • *****
  • Posts: 565
    • My Core wiki user page
Re: How to get a virtual remote desktop working.
« Reply #8 on: October 10, 2011, 05:41:08 PM »
You guys are making me want to try the whole vnc thing, especially on the Magnia.  Stunix, your step-by-step procedure looks easy enough I can't wait to try it... but I'll have to - too tired tonight.

Its probably not industrial strength security, but on my local desktops I have xtrlock start first thing when X comes up.  I suppose that would give -some- protection on an exposed vnc (if it would work at all).  Of course the non graphical machines use noautologin.

32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm
PPR, data persistence through filetool.sh
USB Flash drive, one partition, ext2, grub4dos

Offline netnomad

  • Hero Member
  • *****
  • Posts: 737
Re: How to get a virtual remote desktop working.
« Reply #9 on: October 10, 2011, 10:06:14 PM »
hi friends,

security must not be luxury.
your well-written solution can be tunneled in a ssh-protected communicaton.
you are able to write so well-tuned code and scripts, please use your ability for security, too.

vnc through through ssh can be pretty easy:
mini-howto, very basic, quick and dirty:

host1: ssh -L 5900:localhost:5900 host2
host2: xvnc
host1: vncviewer localhost:0
« Last Edit: October 10, 2011, 10:07:47 PM by netnomad »

Offline oldgit485

  • Newbie
  • *
  • Posts: 18
Re: How to get a virtual remote desktop working.
« Reply #10 on: October 18, 2011, 09:57:31 AM »
Hi Netnomad,
Thanks for your warnings I have removed all the changes made to the files and followed your  explanation,however all I can achieve is the grainy grey screen.The machine is a headless server with no graphics card,I am led to believe that Tightvnc creates a virtual desktop without needing a graphics card.I cannot fathom out the "display= "part of this.Could you enlighten me further please,I just need the Desktop until I am more familiar with the CLI.I had been using Xvesa and thought that might be the problem but having converted both host and client TC 4.02 to frame buffer there is no improvement.I have the "text" boot option and when I enter startx I get failed in startx wait, it may be that I am not starting a screen manager but I am now very confused.
With the file edits suggested in the earlier post it would work occaisionaly but not very often.I am using Tightvnc on both client (laptop) and server(Toshiba Magnia SG30)

Offline jorgea

  • Newbie
  • *
  • Posts: 1
Re: How to get a virtual remote desktop working.
« Reply #11 on: May 24, 2012, 11:39:46 AM »
Great stuff. Thanks for sharing here