Wednesday, July 04, 2007

Seamless Virtualization on Feisty with all the extras...

Windows+Linux=Love For Ever?

THOSO who are impantient on what this guide does scroll to the botton where I put the gallery....

As you may have read I was recently playing around in Ubuntu with wubi.Last week I decided to more to a normal Ubuntu Install and try to explore what else would it allow me to do.One Issue not so well known but EXTREMELY powerfull is what we call Seamless Virtualization...

-Seamless What???

-Yes I am aware of how is sounds and trust me its not such an easy task but once you manage to pull it off we are talking for around 99% application support in your Linux Box which will suit you and leave any fanboy speachless(Trust me I tried it :P)

As far as more advanced users may be interested let me explain what we shall do.We shall Install an Xp windows installation on a Virtual File,We are gonna use RDP to remotely call apps from it,we are gonna patch the Feisty RPD client for multi application support and use a pearl script to launch them,and finally arrange the tap interface to support multi user functionality.

-Cool so where do i begin?

-The first thing to do like always is prepare your weapons

  • VirtualBox. The program that will emulate a windows Xp install.Same can be done with VMware,Qemu)
  • Windows Xp Installation Disk.
  • Dependencies to use with sudo apt-get install: bridge-utils uml-utilities autoconf automake automake1.9 libX11-dev build-essential openssl rdesktop(incuded in feisty)
  • Client Xp tools : Server Component and Shutdown.exe
  • Rdesktop Source with Multi Application Patch or a Compiled binary (untested)

-Got them all now what?

-Lets play with Virtual Box.

1:Virtual Box

  1. Go to Applications->System Tools->InnoTek VirtualBox
  2. Press New>Next and enter for name xp and OS type "Windows Xp" You can use any name but its better to keep it short
  3. Set Memory to as much as you like.I recommend 256 or 512 if you can spare it
  4. Proceed to creating new HardDrive>New>Dynamic Expanding Image>any size above 2GB
  5. Keep pressing next till you are done with basic settings
  6. Now open the new machine settings
    go to General Advanced and Select Bidirectional Shared Clipboard
  7. Go to Cd/DVD and Mount the drive which contains the XP Installation CD or the ISO of it.
  8. Go to Network and Select Attached to Host Interface,Cable Connected and Interface name tap0
  9. Go to Remote Display and just tick the box to enable VRDP Server
  10. Go to shared folders and insert any folder you want the XP to be able to read.I inserted both my partitions.MARK down the name when it creates them.
  11. If you have come so far press start and procced to installing Windows XP.Im not gonna get into details on that but its not rocket science either :)

-Ok it finished and im logged at Windows Xp now what?

-Lets Tweak them for our needs


2.Ubuntu Configuration


Open a terminal and type :sudo pico /etc/rc.local

Add this text inside the BEFORE the exit and after any other enties you may have.


tunctl -t tap0 -u GnomeUserName
chmod 0666 /dev/net/tun
/usr/sbin/brctl addbr br0
/sbin/ifconfig eth0 0.0.0.0 promisc
/usr/sbin/brctl addif br0 eth0
/sbin/dhclient br0
/usr/sbin/brctl addif br0 tap0
ifconfig tap0 VboxIp up
bash -c 'echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp'
route add -host LinuxIp dev tap0
arp -Ds eth0 LinuxIp pub


Where:
GnomeUserName:your user name logged in linux
Vbox ip:A FREE ip for the virtual machine
Linux Ip:Your Ubuntu Linux local network Ip

For multiply users you need to add those lines too


tunctl -t tap1 -u GnomeUserNAme1
brctl addif br0 tap1
ifconfig tap1 VboxIp1 up
echo 1 > /proc/sys/net/ipv4/conf/tap1/proxy_arp
route add -host LinuxIp dev tap1


Where
GnomeUserName1=Second User name
tap1=tab increases while we add users.3rd user would be tap2 and so on
Vbox ip1=Another ip to our network DIFFIRENT to the one we used in other users
yourip=the same for all ip of the Linux Machine.For a third user we do the same increasing the numers of tap and VboxIps

Reboot the Linux System now for them to activate or you may enter them manually one by one on a terminal.(good for troubleshooting).Once you are sure they are ok we procceed to:


3.Client Windows Tweaking


  1. In order to make them communicate with the drives we need to open a windows command promt(yeah I know ironic isnt it?) and type in there net use x: \\vboxsvr\name.As you guessed the name is the one we marked before when setting shared folders.If you shared more than one folder then run the command for each one of them with a different letter z,y,x.This will create network drives with those letters..
  2. Place Server and Shutdown.zip at one of those shared folders at your Feisty machine so you can pick them up from the Windows Client.Extract and put them at c:\seamlessrdp\
  3. Go to Explorer>Tools>Folder Options>View>Adanced Settings>Hide File Extention For known File Types and DISABLE it
  4. Righ click on windows taskbar and UNLOCK it.Then if you have your gnome panel up leave it down else drag it up or wherever you want....This will come handy for having both GNOME and Windows Panel at the same screen
  5. Create 2 text documents in that folder and name then shutdown.bat which contains "shutdown.exe -u -f" and logoff.bat which contains "shutdown.exe -l -f".The seamlessrdp folder should now contain seamlessrdp.dll seamlessrdp.exe vchannel.dll shutdown.exe shutdown.bat logoff.nat
  6. Right Start and right click on MyComputer>Properties>Remote>Allow users to connect remotely to this computer CHECK It
  7. Start>Click on the User Icon on Top of the Menu>once you are the Icon Selection press Back>Create a password
  8. Start>Run>Type "control userpasswords2" and a window should pop Up>Uncheck “Users must enter a user name and password to use this computer”
  9. Start>Run>Type "mmc">File>Add remove Snap In>Add>Group Policy Object>Add>Finish>Close>Ok
  10. Keep MMC open and go to Local Computer Policy > Computer Configuration > Windows Settings and select Scripts (Startup/Shutdown) go to startup>Add New Script>c:\seamlessrdp\logoff.bat Save and close
  11. Make sure to UNmount all CDs/DVD on VBox and go to Virtual BoX meny to Click to Install Guest Additions.If there is no media mounted there should pop an installer and just keep pressing next till its dont
  12. Go to Control Panel>Netword Connections and you can either Note down the IP or set a fixed one (recomended if you using a router).To do so just click on properties on the network connection>Tcp/Ip settings>Set manually>And use a FREE IP of your network,the SAME subnet mask as your network and the ip of the default gateway(router or your pc).Enter the gateway ip in the DNS server tab if you fail to get internet in the XP.Press ok and exit.The Ip we Find here we shall call it VboxInternalIp and ITS IMPORTANT since all conections are made with that IP
  13. Open a notepad and paste this code into it.Then Save as Fixes.Reg and run it.

    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp]
    "ColorDepth"=dword:00000004
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
    "NoDesktop"=dword:00000001
    tap0


-Man that was a LOT!!!

-Thats true but the hard part is over now.Lets see how we connect if everything is ok.

Running Windows Applications Seemlesly

  1. First of all we need to load the xp machine on backround so type:"VBoxManage startvm "xp" -type vrdp".If you wish to add it on startup(NOT recommended in my opinion use the System->Preferences->Sessions.
  2. Since you wanna see some results before getting dirty again use that command
    rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\explorer.exe" VboxInternalIp:3389 -u "WinUserName" -p WindowsPassword
  3. Be patient.If the above command fails try switching the Ip from Windows to the Vmbox Ip you used on setting up the step 2.It will normally log to desktop with full Gui so you may know if there is something wrong with the setup.
  4. If explorer loads you will be presented with windows task bar.IF YOU HAVE gnome panel in the bottom I suggest to hide it(use the hide arrows)
  5. If you run explorer you may lauch as many apps you want at the same time.On the other side if you launch a notepad using this command you will notice you cannot run any other app.This is a limit of the current RDP
    rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\system32\notepad.exe" VboxInternalIp:3389 -u "WinUserNAme" -p WindowsPassword
  6. To fix the above issue we need to patch the RDP client OR use my Compiled binary(Skip that step if you use it and just copy it at step 7).Extract the Rdesktop Source and put the Multi Application Patch inside that folder.Not open a terminal navigate to the folder you extracted and type
    patch -p1 <20070420_rdesktop.patch
    ./bootstrap
    ./configure
    make
  7. If everything goes well you should find inside the folder a file named rdesktop.You need to copy it to /usr/bin and replace the original.One easy way is "alt+f2>gksudo nautilus" to go there to keep a copy of the original too.You may wanna try my compiled rdesktop but I cannot guarantee its success
  8. If it work type
    rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\system32\notepad.exe" VboxInternalIp:3389 -u "WinUserNAme" -p WindowsPassword
    and then
    rdesktop -l "calc"
    This should pop out calculator in a second window.COngratulations you have set up multi user rdesktop
  9. Now lets make a script to call an application easier no matter if its first or second on a machine:


    #!/usr/bin/perl



    my $bin = '/usr/local/bin/rdesktop';

    my $host = 'VboxInternalIP';

    my $socket = '/home/GnomeUsername/.rdesktop/seamless.socket';

    my $shell = 'C:\seamlessrdp\seamlessrdpshell.exe';

    my $username = 'WinUsername';

    my $password = 'Windows password';



    if (@ARGV != 1) {

    print "usage: rdesktop-wrapper \n";

    exit;

    }



    # if socket and master session exist,

    # launch command in slave mode

    $numprocs = `pgrep -c -U Gnomeusername -x rdesktop`;

    if (-e $socket and ($numprocs == 1)) {

    exec($bin, '-l', $ARGV[0]);

    # otherwise, start new master mode

    # only if no other sessions running

    } elsif ($numprocs == 0) {

    exec ($bin, '-A', '-s', $shell . " $ARGV[0]", $host, '-u', $username, '-p', $password);

    }
    Save as rdesktop.pl and with terminal in the folder you saved it type sudo chmod +x redsktop.pl
  10. If you use more than one users make diffirent rdesktop1.pl,rdesktop2.pl.When completed you may copy them over to /usr/bin folder as we did before
  11. Launching an application now is easier than even just type
    rdesktop.pl "c:/..../application.exe"
  12. You can now create a menu in Gnome Panel Considering Seamless Applications.We mainly need 1PowerOn Button,One Poweroff,One pointing to explorer.exe(which in my tests behaved better with the old way NOT the pl script one),and one for each application you want to install and run there
  13. In order to poweroff you may call the "c:/seamlessrpd/shutdown.bat" or force the poweroff
     VBoxManage controlvm "xp" poweroff
    if you Virtual Pc got another than xp name change it

Finito La Musica - Credits Special Thanks


Although its a hard word the result is more than rewarding.I would like to give full credits to all those who really came up with those stuff and made this possible.


Gallery


Both Start Menus as you see here:




Showing the Actual System Drives mapped as Netword Drives



Running Multiply Windows Apps