Windows in bed with Linux

"If you don't know where you want to go, we will make sure you get there."    — Microsoft slogan, as understood in Japanese.
On this page:


First, let me preface this by saying that when getting a new system, I always reformat it and do a clean install. The reason is that I don't want most of the stuff that's installed by default by the vendors: you don't know what it's for or what it does, and most apps nowadays have that annoying 'call home' property. Before doing this, boot the machine and copy \windows\system and \windows\system32 to a CD or a network drive so when doing the clean install you can point the missing drivers there.
Lossless reinstall
Two links on how to completely rebuild, repair, or refresh an existing XP installation without losing data, and without having to reinstall user software, reformat, or otherwise destructively alter the setup.
In very short, you can use the 'repair' option of the install CD, only on retail versions.
CD key change ?
Use sysprep, (found on the XP cd in tools/reskit/ or just search the cd for, extract sysprep.exe and run sysprep.exe -reseal. When the machine reboots you can enter the CD key from your legit copy of XP. Everything stays the same.
Another way to do the same: Reboot in safe mode; delete WPA.* (WPA.DBL, WPA.BAK) in C:\windows\system32; Reboot into normal mode, you will be warned that you need to activate; Click to activate, select by phone, select change key (bottom of form); Enter new legit key; You are returned to activation screen, click Activate online.

Where to get your freeware for Windows

Micro & soft

User interface, Windows system, Internals...

Network Utilities



Multimedia, CD...

Other Windows tips

Running Windows as limited user...

...should be customary, like in every other OS. Instead of this many badly written Windows apps need to be run as admin. Nonetheless it's better to try to keep things sane and clean (less virus/trojan risk) by running as simple user. Here are a few tricks:

How to restart Explorer.exe

In Task Manager (Ctrl+Shift+Esc), find process "Explorer.exe" and kill it. If it doesn't restart right away, go to [File][New Task] and run 'explorer'. Some task bar icons disappear when you do that, although the programs behind them are still running.

Go to [Start][Shutdown]. When the dialog appears, hold Ctrl+alt+shift and click Cancel. Explorer will cleanly unload all of its resources and shutdown. To start it back up, open Task Manager (Ctrl+shift+Esc) and go to [File][New Task] and run 'explorer'.

Linux soap

Linux or Windows ?
The answer is Yes !

Various Solutions:

Posix tools
There are several sets of compiled Unix command line tools for Windows. One is available from Microsoft on the Win2003/XP Resource Kit (or Win2k resource kit) and others like GnuWin32 or unxutils are free. They are natively compile, so the good thing is that they are fast. Drawback is that they are very limited in what they can do and don't chain very well.
Cygwin is a windows DLL that gives a high quantity of Linux tools under Windows. I use it 100 times every day. Even contains X-Windows. Those guys should get the Nobel peace prize. See my notes below.
It's already in cygwin, otherwise check the Windows Services for UNIX
Live Boot CDs
That's the best way to try linux totally risk free. Select a Live boot CD, download its ISO, burn it to a CD, leave it in the tray, reboot and you are using linux without touching your hard disk ! Shutdown, remove the disk again, reboot and you are back at home in Windows.
For instance I like the several variants of Knoppix. If you still think that Linux is a command line hard to install retro thing, Knoppix will be a jaw dropper. It's also great in case something went deeply wrong with you main PC. Note: trick for booting into a Live CD without quitting Windows: go into Hibernation mode, turn the computer back on with the Knoppix/Live CD inside, boot to Knoppix and play with it, reboot to come back to what you were doing in Windows.
Even more mind-shattering: With ClusterKnoppix or Quantian you turn your computer, your laptop, your parents' computers and whatever else you can hook up into a super Mosix cluster in 5 minutes flat. The only thing missing will be your girlfriend's Mac.
VMware, can run Linux under windows.
COlinux tools to get a Linux environment running at the same time than Windows. It's not an emulator but a driver that splits your computer in two, with two different OSes sharing resources at the same time. Pretty limited in its early stages but very interesting concept.

Cygwin tips and tricks

Cygwin installation notes

Do a default install. They run it again and add plenty more than the default setup. Almost every linux/posix/unix/whatever command is there. One of the few missing one is mkfifo and that's due to the OS. Keep the setup.exe file and run it regularly to update your configuration. Run /usr/sbin/makewhatis and updatedb --localpaths='/ /cygdrive/c' --prunepaths='/cygdrive/c/cygwin /cygdrive/c/RECYCLER' as the first thing after starting the first shell so you can have proper man pages and locate database.

What's currently installed?
Run cygcheck -s for various info.
A better shell
The CygWin shell is based on Windows cmd.exe shell and hence sucks big time. There are several solutions around that (setup sshd then login with putty, launch X and use xterm...) but they are complex and have heavy drawbacks. One of the simplest is to download and unzip PuttyCyg. Then make a link to the executable in your start menu by adding -cygterm - and launching it from the C:\cygwin\home\username directory. It gives you a much better shell. The only thing missing are tabs.
Perl, Python and Ruby are optional part of cygwin, install them, they can always come handy. And for Python get the "Buy at Amazon.comHow to think like a computer scientist: Learning with Python" book. Stay away from Perl if you can, its garbage syntax wasted one year of my life.
Make sure you get all the gnu compilers (gcc and similar) and their associated tools, this way you can compile additional programs.
is also an optional part that's pretty useful, if not as nice as other commercial X-window managers out there. You can get WindowMaker with the install and configure .xinitrc to start with startx. Or better, you can use the rootless manager. Start it with startxwin.bat or . and launch X apps from there. Yes, it's confusing as there seems to be plenty of ways to start X-Windows: XWin, X, few of them working directly without tinkering...
You can even get KDE to run on cygwin !
Network tools
wget (download manager), ssh, scp, the incredible rsync...
For instance if your company firewall won't let you check email on a remote pop server, just tunnel the transfer with ssh: ssh -vCL and change the POP3 config in your local email reader to use localhost instead of Obviously you need ssh access on the remote server, but that is usually the case if it's a Linux/Unix host.
Install the ImageMagick set of tools to script image manipulations (see above for bugs).
You can run shell scripts at defined times if you enable the cron subsystem. Read /cygdrive/c/cygwin/usr/share/doc/Cygwin/cron-4.1-5.README and also man 5 crontab. If you are new to it, it may not be obvious, but it's worth it. Update your cron file with crontab -l >/tmp/cron && nano -w /tmp/cron && crontab cron
You can run updatedb from a cron job with the following line 5 5 * * * nice updatedb --localpaths='/ /cygdrive/c /cygdrive/l/Large1 /cygdrive/m/Large2 /cygdrive/n/Large3'. Note that simply using updatedb should run by default on / but will not discover the mounted drives. Also you want to exclude hidden folders. You can then use locate with part of your filename. Note that many older versions of cygwin have a buggy updatedb unable to parse filenames with spaces.
Dealing with spaces in filenames: if you want to use locate in association with xargs, spaces will ruin the thing, for instance locate -i def.h | xargs grep -H keyword will fail in most cases. here's a very simple hack which took me a long time to find: locate -i def.h | tr "\n" "\0" | xargs -0 grep -H keyword.
A portable Cygwin ? Cygwin on USB key ?
Cygwin is an invaluable tool (and free too), but its installation is time consuming and even more so network consuming. What if you use various computers all the time, without administrative installation rights, for instance in Internet bars, friends houses or even the next cubicle ? I needed to use rsync to update my site from any location. Here's a way to do a minimal cygwin that runs directly off a USB key:
Make a MiniCygwin directory on your USB key. In it copy the following files which you'll find in C:\cygwin\bin: cygcrypt-0.dll, cygcrypto-0.9.7.dll, cygminires.dll, cygpopt-0.dll, cygwin1.dll, cygz.dll, rsync.exe and ssh.exe (note, the version numbers may change)
Then I just plug the USB key in, open a DOS window in that directory and rsync away (or change the path if operating from another directory). Just be careful that you are not in bash anymore so the syntax is a bastard mix of DOS and linux: rsync still uses forward slashes for instance. You may be able to copy other programs that you need (for instance awk, bash, cat, cp, cpp, find, gcc, gdb, grep, ld, ls, make, mv, rm, sed, sh, tar...), just verify the dll dependencies: if you get an error when you try to run them, add the DLL indicated in the error message.
Gallery2, PostGreSQL and Cygwin
See files /usr/share/doc/cygwin/cygserver.README, /usr/share/doc/Cygwin/postgresql-7.4.5.README and /usr/share/doc/postgresql-7.4.5/FAQ_MSWIN
[Win][Break], [Advanced][Environment variables][System variables][New], add CYGWIN=server
/usr/sbin/cygserver &
ipc-daemon2 &
initdb -D Somepath/pgsql -E UNICODE
If initdb fails with the message cp: cannot stat `/dev/null.exe': No such file or directory, inside initdb you need to replace the line cp /dev/null "$PGDATA"/postgresql.conf || exit_nicely with touch "$PGDATA"/postgresql.conf || exit_nicely
postmaster -D /usr/local/pgsql/data >"/cygdrive/c/Program Files/Apache Group/Apache2/logs/pg.log" 2>&1 &

Shell stuff

Launching a file from the bash shell
Do cygstart filename.txt will open the file in your editor of choice (Notetab Pro in my case)
You can do clipboard manipulation like this: getclip | ...commands... | putclip Those two commands are part of cygutils.
Icon run
To start a shell script from a [Start][Whatever] icon, create a shortcut in your start menu (or duplicate the Cygwin one) and in its [Properties][Target], type bash --login -i
Process list
ps -W to display Windows processes.
Unix commands in the task scheduler
For instance running daily c:\cygwin\bin\bash -c "updatedb --localpaths='/ /cygdrive/c' --prunepaths='/cygdrive/c/cygwin'" will update the locate database of files. When looking for a file, instead of using the slow Windows Search, just type locate -i filename and get instant results.
Or you can install crontab with some efforts
Directory separators \ and /
Use cygpath to convert between unix, windows and DOS style pathnames. Don't forget the quotes or the backslashes if you have spaces in the file names.
The Path
There should be a export PATH=$HOME/bin:$PATH in your .bash_profile, but what is the original Path set to ? To the value set in [Control Panel][System][Advanced][Environment Variable] which you can edit there to add c:\cygwin\bin so you can use cygwin also from a DOS window. Mine is set to C:\cygwin\bin;C:\Perl\bin\;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\VXIpnp\WINNT\BIN;C:\Program Files\Resource Pro Kit\;C:\Program Files\j2sdk1.4.1_01\bin
Drag folders from explorer
Some commands, like cd accept windows style pathnames, so you can drag and drop folders from Windows Explorer onto a bash shell to write the pathname on the command line. Otherwise you can use painful quote embeddings like command "$(cygpath "Pathname")"
Replace something with something else in all files below a directory (/etc in this example, very dangerous command like most perl one-liners)
perl -pne's/something/somethingelse/g' -i $(find /etc -type f)


Distributed compilation
Gentoo Forum has an article on distcc under cygwin
Code collaboration under Cygwin
CVS is an optional part of Cygwin but I couldn't get it to transfer binaries properly
SVN is very new (version 1.0 as of March 2004) but has more promise. Install from binary and get the TortoiseSVN shell addition.

And when I'm tired of Windows, what do I use ? Gentoo Linux which is a source-based distro for full use of all those dearly paid advanced hardware processor options.