Using Unix programs on a Windows PC

Last updated: Mon 2nd June 2003. Polished this document a little. Changed the startx.bat so that by default it now takes advantage of the Cygwin Xserver to run individual windows - i.e., it no longer needs to overlay its own desktop on top of the Windows one.

Fundamentals

Unix programs run on Unix systems. Windows programs run on Windows systems. Because the operating systems are different, you can't run a Unix program on a Windows machine (and vice versa). The operating systems contain different fundamental components. Right?

But what if you added fundamental Unix components to Windows?

Well, if you add enough Unix components, I'm glad to say that first paragraph above becomes a lie. You can run Windows programs on Linux, and Linux programs on Windows -- in several different ways, actually. If you add all the right fundamental extra pieces to your system, and use programs that have been built to use those pieces, you can run programs from one kind of machine on another. (Do a Google search for emulator and see how many matches you find!)

See Emulators below for a list of some useful ones I've tried. But for Windows, there's a nicer way than using emulators.

Background

The first step in this little recipe is to install Cygwin. (You do this by first downloading the small Setup.exe program and then running that.)

I've provided a new easy method if you've never installed Cygwin. The zip package of files below contains a batch file called cyginst.bat which you can double-click on to do everything. You will need to edit it slightly first to suit your requirements. If you run it, it will even tell you how to do that.

Cygwin is a huge set of packages if you choose to install every component (hundreds of megabytes -- many hours of download time on a 56K modem), but provides most of what anybody would need. It includes the PostgreSQL database, C and C++ compilers, Perl, an XFree86 server, TeX and Groff document processors, and much more.

You may need to go no further than the installation of Cygwin. You do that by simply clicking on the Install Now link on the Cygwin homepage to first download the setup.exe program, then you run that. It sees to the whole process, letting you pick and choose pieces, upgrade an existing Cygwin installation, etc. If you want to install on multiple PCs, choose Download from Internet instead of Install from Internet in the Setup program. That way the files will be installed on that local machine, and everyone on the network can install from there. That'll save a lot of download time!

When installing, setup will ask you whether you want DOS or Unix style line endings. Choose DOS! Cygwin will work quite happily with that choice, and it makes things much easier to work on the same file in both Cygwin and Windows at your whim.

When installing everything (about 600MB after the files have been uncompressed!), there is an easy way that only takes a few mouse clicks. Proceed through the setup as far as the screen that shows you the possible packages to install. Then click on the "View" button until just the package Categories are listed. To the right of the top-level category ("All"), you'll see an icon of two curved arrows, and next to that the word "Default". Click on either the icon, or the word "Default", until the word changes to "Install". You can easily click into the categories and turn off selected packages to trim it down.
(Note: on some machines, this step takes a couple of minutes, with nothing appearing to happen. If you click on the icon a lot, thinking that it's stopped, you'll only make things take longer still! So just click once and be patient.)

After installing Cygwin, you can open up a good command shell (not that embarrassingly deficient batch file processor that Microsoft gives you), and type famous Unix commands like ls, grep, cp, and so on whenever you need them. :-)

Better yet, Cygwin also includes the X window system, which is the graphical window environment available on all desktop Unix machines (even on Apple MacOS X machines). Increasingly many powerful Unix programs are being ported to run under Cygwin on a Windows machine. One of the best is arguably the GNU Image Manipulation Program, the GIMP

Further below I give some more detailed instructions on how to set up a graphical environment (namely, XFree86) etc. for Cygwin. But there is a shortcut if you just want to get going quickly. First, install Cygwin (See Step 1 below, for details). Then, download my file post-install.zip . (I'd suggest you put it in a directory by itself somewhere, to keep long term.) After downloading it (and after installing Cygwin), unzip it like this in a Cygwin window:

    unzip -a post-install.zip
    
(the "-a" converts Unix line endings to DOS line endings). Then run the post-install script:
    sh post-install.sh -fresh
    
You should read the post-install script to reassure yourself that it's not doing anything unpleasant. It basically just creates a place for users to put their data files (each user has their own private area), copies some extra config files, creates some extra desktop shortcuts, and sets up things for XFree86. The README.txt file contains a more detailed description.

More Ramblings...

As I said before, one of the things I really appreciate about Linux is that it's so secure that viruses aren't a problem. So you don't need to scan incoming email for them, you don't have to worry about opening emails that secretly mail off files or your address book to all and sundry, or crash your computer. Likewise, you don't have to worry about visiting web pages that disconnect you from your ISP and reconnect you to a toll-charged number, or which open up your files to outside access, or ...

For these reasons, and others, it's nice to run a Linux machine for connection to your ISP, fetching mail to the machine, and then allowing users on the local network to read their email from that machine. That's what we do at our home here.

You can read your email on the Linux machine directly, of course. There are hundreds of programs for doing that. Netscape Messenger is okay, but we prefer Postilion. More modern mail programs are those from the KDE (kmail) or Gnome or Ximian groups.

Using Samba, the free clone of the Microsoft "SMB" network protocol, you can easily make a Unix machine appear to be just another Windows machine on your network. You can make it the Windows domain master, and file server, if you wish -- I'm told that it's easier to do than setting up a real Windows machine for the purpose. It's also faster than Windows for providing Windows networking ( ref. )

You can even make it the print server, if you choose printers that are compatible with Linux. The pre-requisites are simply to have a normal, modern Linux installation, since it will come with Samba pre-installed.

Now, you can just use the Linux machine as the mail server, and let users connect to it in a pretty normal way (e.g. using the POP protocol), to read their email. But if you do that, you're back at square one, with all the normal chance for virus infection. (Unless you set up virus defangers on the Linux machine that strip viruses before delivery.)

What I describe next is an alternative way to do things like reading your email.

How to use Windows to read your email on Linux

(Or, how to run Unix X applications remotely, on Windows, for free!)

This describes how to configure your Windows system to read mail directly on your Linux machine and do other fancy stuff. Doing this, you lose the convenience of being able to click on innocuous attachments that actually run programs without your knowledge.

Which is the whole point!    :-)

Here are the steps

  1. Browse the Cygwin site , in particular the Cygwin user guide.
  2. 	
  3. Install my extra stuff

    Download this file post-install.zip . Afterwards, unzip it like this:

    	    unzip -a post-install.zip 
    (the "-a" converts Unix line endings to DOS line endings), and then run cyginst.bat:
    	    cyginst.bat
    	    
    If you've already installed Cygwin, you could also start a Cygwin command window and do this, instead:
    	    sh post-install.sh -fresh
    	    
    You should read the post-install script to reassure yourself that it's not doing anything unpleasant. It basically just creates a place for users to put their data files (each user has their own private area), copies some extra config files, creates some extra desktop shortcuts, sets up things for XFree86.

    If you don't have "unzip", you'll have to install Cygwin manually, and then start a Cygwin window and use its unzip program.

  4. 	
  5. Install Cygwin, including the X Windows component.

    If you do this by running cyginst.bat, it will take care of everything for you. The notes below are still useful, especially since they tell you how to get cyginst.bat, and how to use Cygwin's setup.exe program to install it.

    When you install, choose "DOS" (not Unix) file conventions, and if more than one person will ever use the Windows machine, choose "Set up for everyone".

    This way it will work neatly with existing Windows files, and everyone can easily use it, but tailor things to their own liking.

    When you run Cygwin's setup program to install various packages, at one point you'll be presented with a list of packages. You have to click on the word "default" if you want to change the default behaviour. E.g. if you click on it so it changes to say "Install", it means the package will be installed.

    If you choose "Install" for the top category called "All", it will in fact install everything. You'll need a cable-modem to do that, however: a full install is around 600MB! You can get a friend with one to do it for you, and burn it off onto a CD. The only trick to remember is that they should choose "Download from Internet" instead of "Install from Internet". And you should choose "Install from local directory" when you take the CD home, not "Install from Internet".

  6. 	
  7. Configure ssh.

    ssh should be installed by default on Linux, and is included in Cygwin, too, unless you especially chose not to install it. I'm afraid setting up ssh on your Linux box is something I'm not going to explain in detail. For better instructions, visit the OpenSSH web site. But basically, all the users need to run ssh-keygen on each computer (Linux and Windows), to create keys for themselves. (The administrator should also create the host key on each computer.)

    This is especially easy using Cygwin, thanks to the Cygwin and OpenSSH people. hey provide a script called ssh-host-config that does all this for you. Plus, my stuff runs that command for you!

    On Linux, all the the public keys (*.pub files) created by ssh-keygen should be copied into the ssh directory on the other machines that want to be able to connect to them. The public host keys created by the administrator on one machine go in the system ssh directory on the other machine(s). For Linux, that's usually under /etc/ssh or /etc/ssh2.

    After you've done that (you may have to reboot, or run My Computer->Manage and check that Cygwin SSH daemon is running), you can securely login to your Windows machine from a Unix (or Cygwin) system! (As well as the reverse.)

    If you have problems with logging in with the slogin command, you can do a fair bit of diagnosis this way though:

    	slogin -v "your-remote-machine"
        
  8. 	
  9. That's basically it.

    Really! The rest of this stuff is just extra notes.

  10. 	
  11. Notes about X and Window Maker

    Nowadays Cygwin includes the excellent Window Maker window manager. X (also called Xwindows, X11, or XFree86), is how all Unix systems (except Mac OS X and Nextstep) present the user with a graphical desktop.

    The window manager then is layer on top of X, that provides all the window controls, like scroll bars etc. (The fact that Unix has many of these is the reason it has enormous flexibility in how graphical programs look and feel. Many people would say, too much flexibility!)

    See www.windowmaker.org for full info on Window Maker. Some reasons to like it are that it's very small, fast, easy to use, elegant to look at, and is very easy to configure (it has a graphical configuration program).

    I noticed that when setting the keyboard shortcuts for various commands (using the "Capture" button in the Window Maker preferences program, on the keyboard panel), on Windows 95 it always included a spurious "Mod2" modifier for the left "Alt" key on the keyboard. Just highlight and delete the "+Mod2" part of the captured string if you have the same problem. I also changed the default keyboard shortcut for cycling between applications from Mod1+Tab (i.e. Alt+Tab), to Ctrl+Mod1+Tab, so as not to conflict with Windows' own setting.

    You could also download the IceWM and BlackBox window managers, and any others that look to be to your taste.

    I strongly suggest that any extra component files you download, you put in C:\TEMP. It's easy to clean them up from there, and besides, the instructions below assume that you've done this. :-)

  12. 	
  13. About "Home" directories

    The post-install.sh script, when used with the "-fresh" option, will set up things so that each user has their own area. This defaults to your existing Cygwin /home area if you've already set one up under Cygwin. Otherwise if this is your first install, it will default to D:\home\your-username.

    If you already have a home area set up for each user on your Windows machine then use that instead of the default home area that Cygwin sets up, and don't use the "-fresh" option with post-install.sh. For example, if you use a directory called C:\personal to keep a separate directory for each user (e.g. C:\personal\bob, C:\personal\jane), then your C:\personal exactly matches Cygwin's /home directory. Cygwin will expect each user's home directory to be called /home/bob, /home/jane).

    So, from inside a Cywgin command window, type:

    	cd /
    	umount /home	# Just to be on the safe side.  Ok if it fails.
    	mv /home /home.cygwin.orig
    	mkdir /home
    	mount -t c:/personal /home
    	for USER in bob jane
    	do
    	    ls -a /home/$USER
    	    cp /home.cygwin.orig/$USER/* /home/$USER
    	    cp /home.cygwin.orig/$USER/.[a-zA-Z]* /home/$USER
    	done
        
    This changes each user's home directory to follow your machine's existing convention for home directories, and copies the default Cygwin files into their existing home directory.

  14. 	
  15. What is inside post-install.zip, anyway?

    This section has been drastically shortened. Previously, it was a long list of instructions about how to take what I have here and install it on your system. But since then I've written a shell script that basically does it all for you. Much simpler!

    So, this section now just mentions a few useful facts about the setup.

    	
  16. Installing other components.

    These days, the full Cygwin install is very complete, and unless you're keen you won't need to install anything else. If you do want to, though, ypou may find the tips below useful.

    Start up a Cywgin command shell window. (This is like a DOS or Windows command.com or cmd.exe window, but you type Unix commands in it, not DOS ones.)

    When you download one of these other components, the file you download will be named something like xxx.tar.gz -- this means it's actually a compressed bunch of files. (The .tar means it's a "tar" collection; the ".gz" means it's been compressed with gzip.)

    This command will list all the file contents:

    	tar tzf xxx.tar.gz
        
    This command will list the first few files:
    	tar tzf xxx.tar.gz | head 3
        
    If the file is named xxx.tar.bz2, it's an even more tightly compressed bunch of files (it's been compressed with "bzip2"). This command will list all the file contents:
    	tar tjf xxx.tar.gz
        
    (Note: "j" instead of "z" de-compression.)

    If the contents of these file bunches have names that start like:

    	usr/X11R6/bin/icewm.exe
        
    then it means that they contain the full path name for where they should be installed.

    They should be installed directly under the Cygwin "root" (because "usr" is a top-level directory that is supposed to exist directly under the root, "/").

    In that case, change to the root directory first before extracting all the files:

    	cd /
    	tar xzf /cygdrive/c/temp/xxx.tar.gz
    	# or:
    	tar xjf /cygdrive/c/temp/xxx.tar.bz2
        
    (Note that C:\TEMP is referred to as /cygdrive/c/temp in Cygwin. A shortcut that usually works is c:/temp, but this won't work for the "tar" command, for some reason.)

    If the file names don't start with "usr/..." then just work out where they should go by reading their accompanying instructions (look for a file called INSTALL or README or for a doc/ directory), or by inspecting the file names. Once you know they belong in, say, /usr/X11R6/bin, cd to that directory and extract them there. Or, you could just unpack them in C:/temp, and manually move individual files into the appropriate places. How you put the files in the right place doesn't matter.

  17. 	
  18. Whew! That's really it! Sit down and have a quiet cup of tea, and marvel at the huge amounts of time that a small army of programmers have built up, and are giving away for free, just because they feel like it. It makes my heart warm to think about it.

Emulators

The free Wine Windows environment.

The enhanced, commercial CodeWeavers version of Wine.

A heavy duty Windows emulator, Win4Lin from Netraverse.

Feedback

Feedback and suggestions for improvement to this are welcome. If you create some Windows NT-family desktop shortcuts for starting X, and let me have a copy, I'll put them up here too.

Back to Luke's home page