Tuesday, April 28, 2009

Seamlessly integrate XP into Linux with SeamlessRDP

Today users have many choices for combining Linux and Windows on the same machine. You can go with a traditional dual-boot system in which the operating systems reside on different disk partitions but share a common partition for files, or you can use an emulator such as Wine, which lets you install Windows applications right in your Linux system. Virtualization programs, such as those from VMware, bring you closer to the more ideal solution of using both systems at once, but one is always the host and one is always the guest, shown inside a window. But by combining VMware Server with some free software, you can run Windows XP along with Linux, not inside a console window, but completely integrated into the Linux environment.

To make this work, you need three tools installed on your system. Though not open source, VMware Server is free as in beer; it requires a license number that you get from the same page where you download the program. (Of course you also need a copy of Windows XP to run under VMware Server.) rdesktop is a Remote Desktop Protocol client bundled with virtually every Linux distro, and Cendio's SeamlessRDP is a GPL-licensed utility that lets you integrate rdesktop with Windows XP.

With this solution, you're connecting to a virtual machine in the background, but you don't see a window frame or the Windows desktop. All you see is the Windows XP menu bar along with your regular KDE or GNOME menu bar, creating the illusion that both operating systems are working at the same time side by side. In Figure 1. below, notice the KDE menu bar on the top and the Windows XP menu bar on the bottom of the screen. You can launch applications from both.

To start, install Windows XP in VMware with the usual options, and make sure to set the network connection option to Network Address Translation (NAT). This simplifies the connection from the host machine. After you complete the Windows installation, log in and set a password for an account you've created that you'll call from Linux. You must allow remote connections to this Windows virtual machine, which you can do by going to Start -> Control Panel -> System (you may have to switch to the classic view). Once the system icon opens, go to the Remote tab and check "Allow users to connect remotely to this computer."

Now install VMware Tools for your Windows XP virtual machine. You must know which IP address the VMware DHCP server assigned to the virtual machine; to find it, open up a DOS console and type ipconfig.

Click to enlarge Next, install SeamlessRDP from within your Windows virtual machine. Open Internet Explorer and download the SeamlessRDP zip file. Create a directory under C: (C:\seamless) and extract the archive's content there. Unzip the three files into the directory; you'll use seamlessrdpshell.exe later.

Now you can log off the Windows session, but don't turn off the virtual machine. Once you have Windows displaying the Welcome screen, you can close the VMware Server console, leaving the Windows XP virtual machine session is alive in the background. A simple ps -ef | grep vmware proves it's still there.

Now it's time to use rdesktop. First, try to open a simple application, such as Notepad. Start a terminal session under Linux, and run this command from your xterm:

rdesktop -A -s "c:\seamless\seamlessrdpshell.exe notepad" 192.168.217.129 -u admin -p secret

Of course, change the IP address, username, and password to match your settings. If everything is OK, you should see the Notepad application pop up on your Linux system.

The -A option enables the SeamlessRDP mode that creates an X11 window for each application you launch. This option requires you to set a shell (-s) that launches the application indicated in the rdesktop command. Notice that you're using the directory you created and the SeamlessRDP application, c:\seamless\seamlessrdpshell.exe. The argument to this command is the Windows program that you wish to run. You need the full path if the program isn't in the regular path variable.

The -u and -p switches are optional. If you don't use them, the application will launch a Windows login screen asking for credentials.

Note that when you close Notepad or any other Windows-launched application, the rdesktop connection is still on. You must log out, because until you do, rdesktop won't be able to start other applications. Since you don't have a desktop and a Start menu from which to log off, you must go to the Windows XP virtual machine and press Ctrl-Alt-Del, then log off, or restart the virtual machine.

Once you know how to launch a Windows application from rdesktop with the SeamlessRDP option, try it with explorer.exe itself. This application creates a full desktop environment so users can interact mainly through the menu bar. If you run it "as is," it will pop up the full Windows XP desktop (including the wallpaper, icons, and shortcuts on the desktop).

If that's too intrusive for you, you can hack the Windows registry to get rid of the desktop and keep only the menu bar. Once you're in Windows XP again, launch the Registry editor by going to Start -> Run and typing regedit. Search for HKEY_CURRENT_USER -> Software -> Microsoft -> Windows -> CurrentVersion -> Policies -> Explorer. Once there, right-click on the right panel and select New -> DWORD Value. Name it NoDesktop, then click on it and change the data value to 1. Close the Registry editor and restart Windows.

When you turn off your Linux system, any virtual machine that is running in the background will obviously be lost, so you must start the VMware virtual machine and close the server console every time you want to connect to Windows this way. Before running the rdesktop command, consider moving your menu bar from the bottom of the screen to the top, because the Windows bar will sit there.

Now run the rdesktop command like this:

rdesktop -A -s 'c:\seamless\seamlessrdpshell.exe c:\windows\explorer.exe' 192.168.217.129 -u admin -p secret

VoilĂ ! After a few seconds, you should have the Windows XP menu bar at the bottom of the screen, and you should be able to launch any application you have installed. You've created the illusion that both operating systems are working on the same machine at the same time. Very cool.

This trick doesn't work with just VMware virtual machines. It also works with Windows clients on your network and other virtual machine software. Simply install SeamlessRDP and configure Windows XP properly so that rdesktop can connect to it.

No comments: