43

Start of any Cygwin application takes more than a minute on Windows 8.1 x64. It doesn't matter, either I'm starting mintty from shortcut or cygwin.bat or ls.exe or bash.exe from bin folder. Each of them will be slow.

After Bash or mintty is started they are working fairly quick:

$ time for i in {1..10} ; do bash -c "echo Hello" ; done
Hello
...
Hello

real    0m1.273s
user    0m0.060s
sys     0m1.181s

Steps, which I've tried:

  • Reinstalled and tried both Cygwin and Cygwin64 a few times (version 2.864)
  • Started them as Administrator
  • Tried to run them in Windows 7 compatibility mode
  • Disabled "Automatically detect settings" for LAN as in this reply
  • Added 127.0.0.1 localhost cygdrive wpad to hosts as in same reply
  • Set antivirus to disabled state
  • Checked that Bash completion is not installed (no /etc/bash_completion.d folder)
  • Disabled all removable drives in Device Manager (only system SSD and data HDD left)
  • Tried to run with empty etc/profile.d folder
  • Tried to run with empty etc/bash.bashrc file

How else can I find root cause?

P.S. - I have two different systems, laptop and desktop both with Windows 8.1 64 bit. This issue it 100% reproducible on both.

Also, if I start Bash a few seconds after login it starts immediately.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anton
  • 10,890
  • 8
  • 45
  • 54
  • When network adapted is disabled, cygwin start in a moment. So, it tries to connect to some network resource. – Anton Feb 09 '15 at 13:44
  • Network monitor shows massive network activity for cygwin applications. They accessing some machines from my network to LDAP ports via TCP and LDAPMessage. – Anton Feb 09 '15 at 14:11
  • I have same problem. I tried both Solution 1 and Solution 2 below, and neither resolved the problem. BTW, when I run "mkpasswd", I get an extremely long list in my organization. – Hugues Feb 11 '15 at 17:28
  • @Hugues most probably you forgot `-c` flag for mkpasswd. In the end, you must get only one line to be saved to `passwd` file. Same for `mkgroup`. – Anton Feb 12 '15 at 13:29
  • I did include the `-c` flag when attempting solution 1; both `/etc/passwd` and `/etc/group` are single-line files. I was just reporting the fact that the cause of the slowness might be due to the fact that my organization has a long user list (`mkpasswd | wc -l` reports >50K lines) – Hugues Feb 13 '15 at 21:50
  • @Huhues I'm also working in giant company ;) Sorry, didn't got what you've meant in your first comment. – Anton Feb 15 '15 at 12:31
  • In my case my DC was announcing 2 IP addresses. One of them was not reachable from that computer. It was trying to reach port 135/tcp half of the times. – LatinSuD May 09 '16 at 18:39
  • Possibly related: *[Cygwin from Windows is very slow/ laggy](https://superuser.com/questions/877051)* – Peter Mortensen Oct 31 '18 at 14:52

4 Answers4

81

Eventually I found what causes this issue, but I'm still not sure why. Cygwin works for other people in same environment very well.

Cause: On the start of every Cygwin application it tries to get credentials as it is described in etc/nsswitch.conf file. For some reason, it takes a lots of time for my account as it contacts with several Active Directory domain controllers via LDAP.

Solution 1: You can save the current user and group in etc/passwd and etc/group files and set Cygwin to check them before Active Directory.

  1. Start mintty.exe and wait till it opens
  2. Run mkpasswd -c and save its output to etc/passwd file (you will have to create it, output should be one line)
  3. Run mkgroup -c and save its output to etc/group file (you will have to create it, output should be one line)
  4. Open etc/nsswitch.conf and write

nsswitch.conf contents:

passwd: files # db
group:  files # db

Now your Cygwin should start immediately.

Solution 2: There is special CygServer application, shipped with Cygwin, which can be started as an NT service or as a simple process (just run usr/sbin/cygserver.exe). It caches credentials and propagates them to every next Cygwin process while cygserver is running.

Add it to startup or start it before your Cygwin session and you're good — cygserver startup will take time, but every next Cygwin process will start immediately.

Is it your case? I want to share my investigation steps, so you could check, if your case is same to mine.

  • Install MS Network Monitor as it is able to show traffic from a specific process. Run it as administrator.
  • Create New capture tab and click Start (you don't have to add any filters or anything).
  • Start mintty and you will see its connections in netmon: netmon-screenshot
  • You will see list of mintty connections in the tree view on the left and TCP and LDAP frames on the right after selecting on of those connections.
  • Additionally, you can get name of those remote machines by IP address. Run nbtstat -a 8.8.8.8 in command line (replace 8.8.8.8 by one of IP addresses from netmon).

Going deeper: I'm still playing with etc/nsswitch.conf file to get local credentials or maybe cached ones so it will run faster without cygserver. But no luck yet.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anton
  • 10,890
  • 8
  • 45
  • 54
  • 3
    The release notes for the latest version of Cygwin highlight this change. See https://cygwin.com/ml/cygwin-announce/2015-02/msg00009.html – roaima Feb 11 '15 at 16:36
  • Hi, I found this thread and wanted to say that I'm also having similar issues that are driving me crazy. Before I post a question, I wanted to get some ideas on whether I'm running into the same issue. Basically, I'm running W7 joined to my company domain. After a recent cygwin update I'm having really long startup times for cygwin terminals, they're taking around 1 to 2 minutes to come up!! This is really frustrating. I'll start reading the thread suggested in the previous comment. – Jose Cifuentes Feb 16 '15 at 15:45
  • 2
    @JoseCifuentes I recommend you to try out **solution 2** (which is simply start `usr/sbin/cygserver.exe`, wait till it loaded and run any other cygwin application in parallel). If it helps - use solution 1, as it takes longer go trough but cures the problem for sure. – Anton Feb 16 '15 at 18:07
  • Thank you! I tried solution 1 and it didn't work (not sure what I did wrong), but solution 2 did work for me. It does take about 2 to 3 seconds for the actual prompt to appear (guess it's running some scripts, etc...) but I can live with that. – Jose Cifuentes Feb 16 '15 at 20:06
  • 1
    Shouldn't solution 1 be _passwd: files # db_ (don't query SAM/AD) as suggested in the other answer? At least for me merely creating local files but leaving db active in nsswitch.conf does not fix the problem. – Michael Koch Feb 23 '15 at 14:31
  • @Tensberg it should work if you have `files` before `db`, as cygwin depends on their order and it works for me. But for the sake of verification you can comment/remove `db` entirely, yes. – Anton Feb 23 '15 at 22:08
  • Folks, I've been using Solution #2 for a while. Thanks so much for that. In case someone else hits the same problem, I've seen cases where the cygwin terminals won't start and show this message: _/sbin/nologin: No such file or directory_ .The solution is to restart cygserver. Right click cmd.exe icon, Run As Administrator, and run these two commands: `sc stop cygserver` `sc start cygserver` – Jose Cifuentes Mar 02 '15 at 16:20
  • solution number 1 worked like a charm also on mingw shipped with git, thank you very much! (yes it seems to be linked to PC being part of domain) – Jakub Dec 16 '16 at 09:44
25

Here's what worked for me.

  1. Launch Cygwin terminal and then run the following two strings.

    mkpasswd -c > /etc/passwd
    mkgroup -c > /etc/group
    
  2. Edit your "/etc/nsswitch.conf" file to contain the following two lines.

    passwd:   files # db
    group:    files # db
    
  3. Relaunch Cygwin.

Cygwin opens quickly.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Whifix
  • 259
  • 2
  • 2
7

If you are on a network with a large AD directory mkpasswd will take a lot of time (several days in my case). So consider using:

mkpasswd -c -l > /etc/passwd
mkgroup -c -l > /etc/group

 -l,--local [machine]    Print local user accounts of \"machine\",
                         from local machine if no machine specified.
                         Automatically adding machine prefix for local
                         machine depends on settings in /etc/nsswitch.conf.
marius
  • 71
  • 3
2

Adding 'C:\cygwin64\bin' to the path worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131