Avoid Corrupting Cygwin Installations
Defective Cygwin Installation Program
Cygwin is commonly not able to update itself in all circumstances and messages to the effect that files are in use and just a simple reboot being necessary are incorrect and you merely end up with a corrupt and unusable cygwin installation.
Even when you think that you are just adding new packages to Cygwin it will often update to the latest version of any and all Cygwin modules and not just the ones which you think you are adding.
The problem occurs mostly when updating older cygwin installations and the main cygwin1.dll is updated. If you have ANY cygwin programs running then cygwin tries (and often fails) to install all the packages using the in-memory and out of date cygwin1.dll that you have and only installs the new cygwin1.dll after a reboot. Trying to install all the new packages with the old cygwin1.dll file results in failed installations.
There may be a way to force reinstallation but I dont know it and setup.exe offers only a per package reinstall option which doesnt seem to work.
Depending on the age of your cygwin installation, you may often get away with upgrading Cygwin but the chance of Cygwin installation being corrupted is quite high. If corruption occurs you will probably have to re-install cygwin from scratch so it is up to you to judge the cost/benefit.
To see what modules Cygwin is going to update
When running the Cygwin setup.exe, on the page where you select packages, click the View button until you see the view becomes "Partial" and this is a list (often very long due to lots of dependant utility packages.
The key package that you may want to avoid updating is "Cygwin: The Unix Emulation Engine" so you can click the version number in the New column until it become "Keep". Also be very careful about updating "bash: The GNU Bourne Again Shell" and never have any bash command prompts open on the server when you update (check Task manager)
Closing All Cygwin Processes that could possibly be upgraded
You need to ensure that all Cygwin programs AND SERVICES (eg sshd/rsync/mysql/exim etc) are closed as far as possible.
To see all cygwin services:
cygrunsrv -L
Example command to stop individual services:
net stop sshd
Closing all bash shell command windows
In particular it is important that no cygwin bash shell command window open because a bash upgrade often caused corruption.
Check in task manager for any "bash" processes.
Upgrading over a Cygwin SSH link
If possible use reverse connection VNC instead of cygwin ssh for the duration of the upgrade.
If View Partial shows that "Cygwin: Unix" is going to be updated
- Upgrade everything except "Cygwin: Unix" (use the Keep option explained above)
- Upgrade "Cygwin: Unix" by itself and reboot afterwards to change to the new version of the Cygwin1.dll
If you have no other option than to upgrade Cygwin while connected using Cygwin then the Cygwin sshd service can be stopped but your connection will remain open.
Make sure that your SSH client has no bash terminal window open as follows:
- If connecting with Tunnelier close any bash terminal windows and leave only Remote Desktop or WinVNC
- In connecting with Putty, use the option to not open a bash command shell.
sshd is often updated by the cygwin providers so it is quite likely that you will get a message about cannot upgrade an ssh file in use and requiring a reboot however this usually does not cause any major corruption
Steps
1. Disable and stop any Cygwin processes that you can
Disable any scheduled task that might call cygwin (kayako wget isnt cygwin is standalone win32 app)
net stop sshd
net stop exim
In Task manager sort processes alphabetically by name and show processes from all users
- Check no bash processes
- check no cygrunsrv processes (which are the parent of cygwin services)
- check for anything other cygwin related services stuff
2. Check that step 1 has succeeded and do normal upgrade if so
Try to rename (in windows NOT cygwin) the cygwin/bin/cygwin1.dll file to something else eg cygwin1.dll.temp. If successful rename it back again immediately.
If you CAN rename it then simply perform a normal Cygwin upgrade process and finish.
3. Special Cygwin installation if you cannot rename cygwin1.dll (Cygwin is running)
Do the usual cygwin setup.exe process but do View "partial" and if "cygwin: The UNIX emulation engine" is there and is not the ONLY module to be updated then click on the version number in the New column until it says "Keep". If asked to reboot the computer during this stage, choose No.
If you marked "cygwin: The UNIX emulation engine" as "Keep" in the previous step then redo the cygwin installation and this time, since "cygwin: The UNIX emulation engine" will be the only option, you will not upgrade it. You will be asked to reboot the computer. Do so.