Linux DevCenter    
 Published on Linux DevCenter (
 See this if you're having trouble printing code examples

Using Samba, 2nd Edition

Windows Compatibility for the Linux Desktop

by David Collier-Brown, coauthor of Using Samba, 2nd Edition

In any business switching to Linux, there's at least one person who's stuck. These people need to use files from some Windows-only program, and usually have to do so by dual booting to and from Windows. Dual booting is very slow when all you really want to do is cut and paste a few screenfuls of data. Worse, because it is so slow, there is a real temptation to remain in Windows and use programs such as Outlook and Exchange, this year's favorite virus targets.

There is a better alternative: run just the necessary Windows programs under Linux. This solves the same problem we saw when DOS started to replace CP/M. There was always something that only the older operating systems' programs did, so you ran the older programs with an emulator.

What You Get

When you're done, you will have the ability to run Windows programs on your Sun Java Desktop or other Linux system. If someone mails you a Microsoft Project file, double-clicking will launch the program to edit it, even though MS Project runs only on Windows.

Yes, you can run MS Project on the Linux desktop. Our approach will let you use the Linux command win to run the Windows application just as if it were a normal Unix command, passing it a slightly modified Unix command line. Project will then appear in a normal X window on the desktop under control of your window manager.

MS Project running on the Gnome desktop
Figure 1. MS Project running on the Gnome desktop

Netscape can run the win project_file command when you double-click a file in mail or on the Web. You can run the same command from the Gnome applications menu by double-clicking an icon or an MS Project file, or directly from the command line.

With this, I can have my "must-have" programs: MS Project and Visio.

Choosing a Product

There are several emulators we could use, so our first task is to find one suitable for our purposes. In this particular case, I wanted a program that was usable on two existing machines: my JDS system at home, and the departmental loaner, a three-year-old laptop.

Learning Lab TigerLinux/Unix System Administration Certification -- Would you like to polish your system administration skills online and receive credit from the University of Illinois? Learn how to administer Linux/Unix systems and gain real experience with a root access account. The four-course series covers the Unix file system, networking, Unix services, and scripting. It's all at the O'Reilly Learning Lab.

The first good candidate was CodeWeavers' Crossover, which the Java Desktop uses to run Windows web-browser plugins. However, CodeWeavers doesn't offer support for Project. If it had, Crossover would have been a good choice: it's fast, resource-light, and inexpensive at $54.95 per person.

Related to Crossover is WINE, a free software project supported by the CodeWeavers team. Regrettably, it doesn't support Project, either. Nor do the two other well-known free projects, BOCHS and Plex86.

Next was EMC's VMware, a powerful virtual machine capable of running Windows NT, 2000, and XP; Linux; and Novell NetWare. The Samba team uses it to run multiple different Windows versions to test their SMB file server. Its only disadvantages are its preference for NT over Windows 9x, its cost ($299), and the need for a powerful PC.

Because the commonly needed programs all run under Windows 95 through 2000, the next good candidate is NeTraverse's Win4Lin. Win4Lin doesn't run NT and XP programs, so it's not as general-purpose as VMware. On the other hand, it is less expensive at $89.99 a seat, integrates particularly well with Unix, and doesn't require a powerful machine to run. I've had good results with it since I first tried it on Red Hat 7, so Win4Lin is a good choice for running Project on the Sun Java Desktop.

All of these products run locally, so they are suitable for portables and individual desktop PCs. If we were trying to provide backwards compatibility to a whole department of Unix machines, we'd also consider NeTraverse Win4Lin Terminal Server and EMC VmWare ESX server, both of which replace the Windows Citrix product.

Windows 98 will give you the fewest bugs and best performance. I used Windows 95, as it is quite fast and capable of running all the programs that I wanted, but it did have the disadvantages that installing it required a boot diskette and that it doesn't support USB.

Installing Win4Lin

Before you start, you'll need a licensed copy of Windows to use as your guest operating system, a copy of the Win4Lin installer, and possibly a Windows boot diskette.

From Windows, create a boot diskette, and check that you have the license key for your copy of Windows. Then download the Win4Lin installer. You will need to run win4lin-install as root, so a good place to save it is the /root directory.

There are three steps to installing Win4Lin: installing the virtual machine module into the Linux kernel, loading a basic DOS under it, and finally installing a complete licensed Windows in the account of the user who will use it.

If you are installing Win4Lin on a pre-release version of the Sun Java Desktop, there is an extra step. You'll need to preinstall a specific kernel that supports Win4Lin and is compatible with SJD.

Installing Matching Kernel Versions

At the time of writing, SuSE version 8.1 has just come out. I used kernel k_deflt-2.4.21-151.i586.rpm. Download the kernel to /root and install it. The command for this is:

# rpm -Uhv --nodeps --force k_deflt-2.4.21-151.i586.rpm

When the commands complete, reboot and continue.

Running the Installer

The initial step is to run the installer, /root/win4lin-install, as root. The installer will open a window with a handy "What stage am I at?" display in the upper left and start looking for the proper modules to download, as shown in Figure 2.

the installer screen
Figure 2. The installer screen

After downloading and installing the kernel modules, the installer will ask you to reboot to load the Win4Lin kernel module. This is the only reboot you'll need, unlike a normal Windows installation. Linux will default to loading the Win4Lin kernel, but you can still load the previous one in case of difficulty.

After logging back in again as root, run /usr/bin/win4lin-install. Note that this is not the installer we downloaded to /root. Instead, it's a different installer that the first installer placed in /usr/bin. You'll then come to the one place where you might strike trouble.

The Boot Floppy

As these boot disks are subject to the Windows license requirements, once you find the one you need, you should retain only the one that corresponds to your licensed copy of Windows.

Unless your Windows CD is bootable and your CD-ROM drive supports booting, Win4Lin will ask you to insert a DOS boot diskette.

If you don't have a Windows recovery floppy, or, like me, made one that didn't boot, see for a replacement. This can take a few tries: I thought I was installing Win95b, but actually had a Win95a CD. After multiple attempts, I finally succeeded with a Win95a floppy.

Once you've found or recreated your boot floppy, complete the installation. This will load a minimal DOS and the Windows installer.

Installing Windows

After this step, exit the root account and log in as the user who will run Windows. Now you'll need your proof of ownership. If you have a non-upgrade version of Windows you need a Certificate of Authenticity. For an upgrade you need the certificate or CD from the Windows you initially installed. One of these will contain the license key Windows will ask for.

As the licensed user instead of root, run /usr/bin/win4lin-install and the installation program will recommence.

Don't start with VNET! The Windows networking system is problem-prone and isn't protected by the built-in Linux firewall. If you start with Winsock and change your mind, you can add VNET later.

The first question the installer asks is whether to use the default WinSock networking or add VNET. The latter is necessary for the Network Neighborhood feature of Windows. If you select WinSock, you'll still have access to TCP/IP, so web browsing, telnet and FTP will all still work.

Once you've made this selection, the last Win4Lin screen will appear. A Windows virtual machine will boot in a separate window.

Almost immediately, the Windows installer will request a license. Select OK and type in your key, following the instructions on your particular screen. This step will vary somewhat, depending on the Windows version and whether you have an initial or an upgrade CD.

Once the Windows installation completes and you've set the time zone, Windows will reboot. However, unlike the interminable boot of Windows on physical hardware, no sooner does the installer window close than a DOS window opens and Windows starts to reload.

You're now in a quite normal-looking Windows session, but under Linux, with the Gnome icons visible on the far left. (See Figure 3.) These icons include the Win4Lin Desktop icon that will start this Windows session from now on.

Windows session with Explorer
Figure 3. A Windows session, with Windows Explorer running

Bear in mind one thing from this point onward: always exit Windows via the Start -> Shut Down menu, not the exit button on the upper right of the X window system frame. As a guest operating system, Windows needs to shut itself down.

Configuring Drives in Windows

We need to change one thing at this point. Win4Lin has created a mydata directory in the user's home directory and pointed Window's D: drive to it. Like the Sun Java Desktop's Documents directory, it exists to supplant the My Documents directory on Windows' C: drive.

We only need one personal documents directory, so we need to remove the C:/My Documents directory that Windows created from ~/win, and the similar ~mydata directory that Win4Lin created, and then point the D: drive to the SJD Documents directory.

Windows will eventually wedge right after you or one of your users fails to install something. Before this happens, create a tar file of the user's win directory and put it with your other backups to use to restore Windows alone.

Run the Win4Lin setup program, /usr/bin/winsetup. Select Personal Session Configuration: win, then the Drives and Filesystems tab. Select the D: drive, press the Properties button and enter $HOME/Documents in the Directory field. Next, click OK, then Save, and finally Exit. When you start Windows again, you'll see the new drive letter and its contents listed as Documents.

Because you've separated programs and data, you can now back them up separately.

With a tar backup of $HOME/win, you can always return Windows to a known working state by unpacking the tar file in the $HOME/win directory. Restoring this file is a less destructive version for the "reinstall Windows" step that application help desks will tell your users to take. Because it only overwrites the basic OS, most of the other files the user has added won't be threatened.

Running Windows Programs with Unix Commands

We now have the ability to start DOS or Windows and to run programs as if we'd dual booted. However, this is not what we were trying to achieve. Instead, we should make the Windows programs run like Linux programs by selecting them from the Gnome menu or by double-clicking their data files.

Because can run both DOS and Windows under Win4Lin from the command line, it is possible to write scripts and integrate Windows programs into Gnome and Netscape just like Linux programs.

The command to run a Windows program from Linux is win. Pass it the name of the program to run and any options. For example, win c:/windows/startm~1/programs/window~1 will start Windows Explorer.

Getting Paths to Work

There are two problems with paths, both of which can interfere with running Windows programs this way. The first is that running programs from Windows can involve directories with spaces in their names. The second is that Windows wants to use drive letters in place of full pathnames.

Windows has several popular directories with spaces in them, including the Microsoft Office directory, where Project and Visio reside. If you specify one of these paths in a Unix shell script without the right quoting in place, the script will fail. This could prevent us writing a script to run Project from Linux.

The solution for this problem is to find the DOS name that corresponds to the directory you want to use. DOS does not allow spaces in names, so you can use DOS directory names in win commands. The DOS dir command will show you both the long (Windows) and short (DOS) forms of a directory name, allowing us to construct a path that will be interpreted properly in Unix.

Consider the problem of writing a script to start Microsoft Project. Project resides at C:\Program Files\Microsoft Office\Wimproj.exe, which dir identifies as C:\PROGRA~1\MICROS~2\WINPROJ. This allows us the write a project script containing the following:


If we used the command project Documents/gantt.mpp, win would find the Project binary, but wouldn't be able to interpret the path to the data file.

The path to the file to be opened doesn't have the blanks problem. Instead, it is a Unix path without a DOS drive letter, which Windows won't be able to find. The solution to this is to have a drive letter corresponding to the root, and use a full path in the script. Our script now becomes something like this:

	case "$1" in
		"'" echo "'";;
		/' echo "$1";;
		' echo `pwd`/$1
win "C:/PROGRA~1/MICROS~2/OFFICE/WINPROJ" R:`fullpath $p` "$@"

With this script in /bin/project, create an R: drive and map it to root. Run /usr/bin/winsetup once more. Select Personal Session Configuration: win, and then the Drives and Filesystems tab. Hit the Add button and enter the path /. Then click OK.

For any program that runs under DOS, we can use the same approach to write a script to run it with the same structure, except for substituting dos for win as the command name.

At this point we can write scripts to run Project, Visio, or any other DOS or Windows program from the command line.

Integrating the Programs with Gnome and Netscape

The next step is to tell Gnome and Netscape how to find the win, dos, project, and visio scripts, associate them with the file types for Project and Visio, and add the commands to the menus. Gnome and KDE predominantly use configuration files with names like win4lin.desktop to make programs available to the GUI, while mail and web programs like Netscape use mime.types and mailcap files to do the same thing. We'll work with these three file types.

Adding Win4Lin to the Shortcut Menus

Win4Lin already comes with a two files to allow its icon to appear on a Gnome desktop, an icon and a .desktop file. The first thing we'll do is set it up under Gnome. Assume for the moment that I want it in the quick-start area of the main menu, as well as in its usual place two layers down in Accessories -> Office -> Win4Lin, as shown in Figure 5.

Gnome Menus after adding Win4Lin
Figure 5. Gnome Menus after adding Win4Lin

The Win4Lin installer placed a Win4Lin.desktop file in $HOME/.gnome-desktop, so as to make a Win4Lin icon appear on the user's Gnome desktop. This does not put it in the menus for this or any other user, so we'll first move the desktop file to a safe directory and then change it to make it appear where we want in the menus. If the user doesn't want the Win4Lin icon on the desktop, she can then delete it without accidentally making it disappear from the menus.

Copy the file to the /usr/share/applications directory, then put a symlink in its place in $HOME/.gnome-desktop:

# cd /home/davecb/gnome-desktop
# mv 'Win4Lin Desktop.desktop' \
# ln -s /usr/share/applications/Win4Lin_Desktop.desktop \
	'./Win4Lin Desktop.desktop'

At this point, edit it with a text editor to add the Categories line:

[Desktop Entry]
name[en_US.ISO8859-1]=NeTraverse Win4Lin Desktop

This indicates it is found in the Applications-> Office menu, as well as the quick-start area of the main menu, as shown above.

The two X-Sun categories are peculiar to the Sun Java Desktop. The X-Sun-Supported flag indicates that the program should appear in the menus, whereas the X-Sun-Quick-Start category indicates that it should also appear in the quick-start entries at the top of the main menu. Without the X-Sun-Quick-Start indicator, it would appear in Application -> Office only.

The first two categories in the list indicate its position in the menus, under the Applications main menu, in the Office sub-menu.

The menu names used by the SJD differ slightly from the names used in the Category line. The menu/submenu names in the left column of the table below correspond to the Category= names in the right column.

Menu NameCategory Name
Java ApplicationsX-Sun-Java
System ToolsSystem

We also need to move the icon from $HOME/.merge/Win4Lin.xpm to the global icon directory, /usr/X11R6/share/icons/png/hicolor/48x48/apps, and then update the Win4Lin.desktop file to say Icon=win4lin.xpm. Gnome will find the icon by name, if it's in the default place.

Non-JDS Gnome and KDE Desktops

Non-JDS Gnome desktops use exactly the same system of Category= values to place applications in menus.

To appear in the Applications menu, the categories must include Application. Under that menu, the commands appear in sub-menus if they contain Application and one of following additional category names.

Applications Sub-Menu NameCategory Names
AccessoriesUtility but not System
OfficeSpreadsheet || Office || WordProcessor || ProjectManagement || Calendar
SystemSettings but not System
Othernot Settings

These category names shown here come from the .vfolder-info files in /usr/share/gnome/vfolders or /etc/gnome/gnome-vfs-2.0/vfolders.

KDE uses an entirely different system. Instead of placing Category= lines in the desktop files, the files themselves appear in a directory hierarchy that corresponds to the menus. For example, if netscape.desktop were in /usr/share/applications/internet, it would appear in the Applications -> Internet menu.

Integrating Visio and Project

The same techniques works to add your Windows programs to the Gnome menus. We'll start with Visio.

Install the program as usual under Windows. Before you remove the CD, locate the icon you wish to use with the program. Running find on the CD identified a Windows VisioCD.ICO file in the /media/cdrom/Support directory. Copy the icon to a Linux file system and convert it to a Unix icon with:

$ winicontoppm VisioCD.ICO | pnmtopng > /tmp/visio.png

Copy visio.png to /usr/X11R6/share/icons/png/hicolor/48x48/apps, the default location for Gnome icons.

Next, find the executable. Running find on ~/win found ./Program Files/Visio/Visio32.exe and dir identified the path as \PROGRA~1\VISIO\VISIO32. At this point, we can copy the project script to create a visio script.

Then, create a desktop file in /usr/share/applications/visio.desktop, containing:

[Desktop Entry]

A new entry, Visio, will now appear in the JDS menus under Graphics. It's runnable.

Project requires a similar project.desktop file:

[Desktop Entry]
Name=Microsoft Project
# Icon=

Visio and Project File Types

In the visio and project.desktop files above, a line identifies the MIME type of the program. This is an unambiguous name for the file type used by the program. Both Gnome and Netscape use the MIME type to find out what program to run if you double-click a file of this type.

Gnome stores its registry files covering all MIME types that it will recognize in /usr/share/mime-info. We'll create win4lin.keys and win4lin.mime files as follows.

win4Lin.keys contains:

description=Microsoft Project File
description=Microsoft Visio file

win4Lin.mime contains:

ext: mpp mpc mpt mpx mpw
ext: vsd vss

A similar applications registry for files lives in /usr/share/application-registry. We'll create a Win4Lin.applications file there, containing:

name=MS Project



To integrate MS Project with Netscape, you need to provide the same information in a different set of files. Add the following lines to /etc/mailcap:

type=application/ desc="Microsoft Project File"
type="application/vnd.visio desc="Microsoft Visio File"

and the following lines to /etc/mailcap:

application/	/bin/project %s
application/vnd.visio:	/bin/visio %s

The /etc/mailcap file corresponds to the /usr/share/application-registry/Win4Lin.applications file, while the mime.types file corresponds to the /usr/share/mime-info/win4lin.keys and win4lin.mime files.

After adding these to the system mime.type and mailcap files, Netscape will recognize a Project file when you double-click it either in email or on the Web. It will launch /bin/project to edit the file.

Remote Access to Win4Lin and Windows

If you have another non-x86 machine, you can run Windows programs on Linux and display the window on your other machine, to the considerable startlement of your colleagues. See Figure 6.

running Visio from a SPARC
Figure 6. Running Visio from a SPARC

With a Linux machine named Calvin and a Solaris machine named Hobbes, the command on Hobbes is:

xhost +calvin: ssh calvin "DISPLAY=hobbes:0.0 /bin/project $@"

At this point we're done. Whenever we need to run those last remaining Windows programs, we can do so without leaving Unix and without the interminable waits of dual booting.

If we need to provide this same kind of capability to a whole department, we can look at the Win4Lin terminal server, which Sun and Siceroo recently used in a large deployment of Sun Rays for the Netherlands school system.


David Collier-Brown is a consulting systems integrator, currently working for the performance and engineering group at Sun Opcom in Toronto.

Return to the

Copyright © 2009 O'Reilly Media, Inc.