Cygwin: Difference between revisions

From miki
Jump to navigation Jump to search
 
(31 intermediate revisions by the same user not shown)
Line 1: Line 1:
== References ==
== References ==
* Local Reference Cygwin documentation can be found at '''<tt>/usr/share/doc/cygwin-doc-1.4</tt>'''.
* Local Reference Cygwin documentation can be found at '''<tt>/usr/share/doc/cygwin-doc-1.4</tt>'''.
* [http://alumni.soe.ucsc.edu/~you/notes/cygwin-install.html Guide from some user]

'''Cygwinport''' project:
* http://sourceware.org/cygwinports/

;Alternatives to Cygwin
* [https://sourceforge.net/projects/msys2/ MSYS-2]


== Packages ==
== Packages ==
Line 7: Line 14:
* [http://www.cygwin.com/setup.html Cygwin package contributor guide]
* [http://www.cygwin.com/setup.html Cygwin package contributor guide]
* Interesting repositories:
* Interesting repositories:
*; ftp://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin/
** http://ftp.esat.net/mirrors/sources.redhat.com/pub/cygwin/<br/>My new default mirror
** ftp://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin<br/>usual repository I use, not official anymore as per setup.exe...
*:(usual repository I use)
*; ftp://sunsite.dk/projects/cygwinports
** ftp://sunsite.dk/projects/cygwinports<br/>Repository of Cygwin Ports, maintained by Yaakov Selkowitz (homepage: http://cygwinports.sunsite.dk/)
**:Website: http://sourceware.org/cygwinports/
*:Repository of Cygwin Ports, maintained by Yaakov Selkowitz (homepage: http://cygwinports.sunsite.dk/)

*:Website: http://sourceware.org/cygwinports/
=== Installing from CygwinPort ===
* Run
<source lang="bash">
cygstart -- /path/to/setup.exe -K http://cygwinports.org/ports.gpg
</source>
* Add <tt>ftp://ftp.cygwinports.org/pub/cygwinports</tt> as new Download Site (see [http://sourceware.org/cygwinports/] for mirrors).
* Select packages


=== Creating a local setup.ini ===
=== Creating a local setup.ini ===
Line 56: Line 70:


When done, simply install the package by running ''Cygwin'' <tt>setup.exe</tt>, asking to ''Install from Local Directory''. ''Cygwin'' will see the new file setup.ini, and proposes for install the packages listed inside.
When done, simply install the package by running ''Cygwin'' <tt>setup.exe</tt>, asking to ''Install from Local Directory''. ''Cygwin'' will see the new file setup.ini, and proposes for install the packages listed inside.

* Install packages from the command-line (see [http://sourceforge.net/mailarchive/forum.php?thread_name=loom.20110217T110819-205%40post.gmane.org&forum_name=cygwin-ports-general])


== Troubleshooting ==
== Troubleshooting ==
Line 77: Line 93:
$ export PATH=$PATH:/usr/local/lib/bin
$ export PATH=$PATH:/usr/local/lib/bin
$ /usr/local/sbin/authtest ausername
$ /usr/local/sbin/authtest ausername
</source>

=== Out of Memory ===
Typical Perl error:
<source lang="text">
Out of memory during "large" request for 268439552 bytes, total sbrk() is 311015424 bytes at /usr/lib/perl5/vendor_perl/5.10/Git.pm line 908, <GEN1> line 615.
</source>
Solution is to increase [[#Changing Cygwin's Maximum Memory|Cygwin's maximum memory]] (see below)

=== Rebaseall ===
'''rebaseall''' is needed in case Cygwin reports DLL address conflict when forking. Here the sequence to follow [http://cygwin.wikia.com/wiki/Rebaseall]:
# Make sure that '''all''' cygwin processes are closed (this includes cygwin processes, cygwin services, X server...)
# Run the minimal shell '''ash''' (e.g. via {{kb|win-R}}), and type:
<source lang=bash>
cd /bin
PATH=. rebaseall -v
exit
</source>

=== SSHD ===
'''{{Red|Beware!}}''' Whatever is said here, the offcial doc for sshd is located at <tt>/usr/share/doc/Cygwin/openssh.README</tt>. Read it or the wrath of the Cygwin's Gods will strike on you!

'''SSH keep asking for the password although public key is set / Wrong HOME directory'''
* ''sshd'' uses for HOME the value defined in <tt>/etc/passwd</tt>. If that variable is wrong, sshd will not find the keys to authenticate the session and will prompt instead for a password.
* This occurs typically for domain users with HOME set on some network server after running <code>mkpasswd -u $USER >>/etc/passwd</code>.
* Editing the HOME value in <tt>/etc/passwd</tt> shall fix the problem.

'''Network shares not visible when logging to Cygwin via SSH'''
* This is a known problem, see: [http://cygwin.com/faq/faq.using.html#faq.using.shares Cygwin FAQ], [http://cygwin.com/cygwin-ug-net/ntsec.html ntsec.html], [http://cygwin.com/ml/cygwin/2006-06/msg00862.html Corinna's tip].
* Some guides: [http://ist.uwaterloo.ca/~kscully/CygwinSSHD_W2K3.html Setup SSHD on W2K3], [http://pic.dhe.ibm.com/infocenter/wxdinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.ops.doc%2Finfo%2Fodoe_task%2Ftcimgr_sshwin.html Run SSHD as root], [http://inside.mines.edu/~gmurray/HowTo/sshNotes.html]
* One solution is to start sshd manually:
<source lang=bash>
net stop sshd
chown $USER /var/empty # to fix misleading error "/var/empty must be owned by 'root' and not group or world writeable"
/usr/sbin/sshd& # or -D to disable daemon mode
</source>
* Another solution is to start a [[screen]] session launched directly from a console, then detach, and attaching to that session when logging in via SSH.
:In a cygwin terminal:
screen
{{kb|C-a}}{{kb|d}} ''{{gray|# detach session}}''
:From another computer:
<source lang=bash>
ssh cygwinhost
screen -D -R
</source>
</source>


Line 131: Line 191:


=== Get a Bash shell owned by SYSTEM ===
=== Get a Bash shell owned by SYSTEM ===
;On Windows 7


We use '''PsExec''' from Sysinternals [https://docs.microsoft.com/en-us/sysinternals/downloads/psexec PsTools]:

* Launch a <code>cmd.exe</code> windows shell with ''Administrative'' privileges.
* Run
<source lang=winbatch>
psexec -i -s c:\cygwin64\Cygwin.bat
</source>
* This starts a new console with user SYSTEM:
<source lang=bash>
whoami
# SYSTEM
</source>

;Old trick
This is a trick I found to easily open a Bash windows as user ''SYSTEM''. First create a dummy service '''bashsystem''':
This is a trick I found to easily open a Bash windows as user ''SYSTEM''. First create a dummy service '''bashsystem''':


Line 142: Line 217:
$ net start bashsystem
$ net start bashsystem
</source>
</source>

=== File permissions ===
=== File permissions ===
* Use '''getfacl''' and '''setfacl''' to set NT file permissions and access conditions.
* Use '''getfacl''' and '''setfacl''' to set NT file permissions and access conditions.
Line 150: Line 226:


=== Install SSHD ===
=== Install SSHD ===
Reference: [http://www.noah.org/ssh/cygwin-sshd.html]
Reference:
* New reference for Windows 7: http://techtorials.me/cygwin/sshd-configuration/
* [http://www.noah.org/ssh/cygwin-sshd.html]


* Install the packages:
* Install the packages:
Line 159: Line 237:
ssh-host-config -y # Yes to all question
ssh-host-config -y # Yes to all question
</source>
</source>
* When queried for CYGWIN variable, answer <tt>tty ntsec</tt>
* When queried for ''CYGWIN environment variable'', answer
<s>tty ntsec</s> ''{{Gray|# For Cygwin 1.5.x}}''
ntsec ''{{Gray|# For Cygwin 1.7.x}}''
* Launch the service:
* Launch the service:
<source lang="bash">
<source lang="bash">
Line 165: Line 245:
</source>
</source>
* Optionally, open the SSH port (22) on the firewall
* Optionally, open the SSH port (22) on the firewall
* Create the /etc/passwd and /etc/group files:
<source lang=bash>
mkpasswd -d WBI -u beq06659 >> /etc/passwd
mkgroup -l -d >> /etc/group
</source>
* '''Important!''' &mdash; Edit the HOME setting in /etc/passwd to make sure it points to cygwin home directory. Or sshd will not find the pubkey to use when logging in (see [[#SSHD|Troubleshooting SSHD]])
* Increase ''sshd'' process priority to reduce connection time (not sure it helps though)
<source lang=bash>
cygrunsrv -R ssh
cygrunsrv -I sshd -p /usr/bin/nice.exe -a "-n -10 /usr/sbin/sshd -D" -f "CYGWIN sshd" -y tcpip -e 'CYGWIN="ntsec"'
</source>

'''Re-install sshd'''
<source lang=bash>
rm -rf /var/log/sshd* /etc/ssh_host* /etc/sshd_config /var/empty
net user cyg_server /delete
net user sshd /delete
vi /etc/passwd # virer cyg_server & sshd
ssh-host-config -y
ssh-user-config
cygrunsrv -S sshd
</source>

=== Changing Cygwin's Maximum Memory ===
It seems that by default, maximum memory for cygwin process are 384MB. One can change this value by modifying a windows registry key (see [http://cygwin.com/cygwin-ug-net/setup-maxmem.html] for details):
<source lang="bash">
# Set limit to 1024 (1GB)
regtool -i set /HKLM/Software/Cygwin/heap_chunk_in_mb 1024
regtool -v list /HKLM/Software/Cygwin
</source>


Use the following program (from DJ Delorie) to get the maximum valeu for that variable (returns '''1536MB''' on a Dell Latitude E6410 with 4GB RAM):
<source lang="c">
main()
{
unsigned int bit=0x40000000, sum=0;
char *x;
while (bit > 4096)
{
x = malloc(bit);
if (x)
sum += bit;
bit >>= 1;
}
printf("%08x bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);
return 0;
}
</source>

=== Install a package from the command-line ===
The official package administration tool is <tt>setup.exe</tt> (usually available at <tt>/setup.exe</tt>).

References:
* [http://cygwin.com/ml/cygwin/2006-10/msg00880.html Re: Installing packages from cygwin Command Line]
* [http://serverfault.com/questions/126093/how-do-i-install-a-cygwin-package-from-the-command-line How do I install a cygwin package from the command line?]

Command-line reference:
<source lang=text>
Command Line Options:
-A --disable-buggy-antivirus Disable known or suspected buggy anti
virus software packages during execution.
-C --categories Specify entire categories to install
-D --download Download from internet
-d --no-desktop Disable creation of desktop shortcut
-h --help print help
-K --pubkey URL of extra public key file (gpg format)
-L --local-install Install from local directory
-l --local-package-dir Local package directory
-n --no-shortcuts Disable creation of desktop and start menu
shortcuts
-N --no-startmenu Disable creation of start menu shortcut
-O --only-site Ignore all sites except for -s
-P --packages Specify packages to install
-p --proxy HTTP/FTP proxy (host:port)
-q --quiet-mode Unattended setup mode
-r --no-replaceonreboot Disable replacing in-use files on next
reboot.
-R --root Root installation directory
-S --sexpr-pubkey Extra public key in s-expr format
-s --site Download site
-U --keep-untrusted-keys Use untrusted keys and retain all
-u --untrusted-keys Use untrusted keys from last-extrakeys
-X --no-verify Don't verify setup.ini signatures
</source>

For instance, to install package ''screen'':
<source lang=bash>
/setup.exe -q -n -N -d -R c:/cygwin -s http://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin -l D:/temp/cygwin -P screen
</source>

See http://cygwin.com/mirrors.lst for a list of mirrors.

To use a proxy, use option <code>-p</code>:
<source lang=bash>
/setup.exe -q -n -N -d -R c:/cygwin -s http://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin -p myproxy.com:8080 -l D:/temp/cygwin -P screen
</source>

Other solutions:
* '''[http://code.google.com/p/apt-cyg/ apt-cyg]'''<br/>apt-cyg is a command-line installer for Cygwin which cooperates with Cygwin Setup and uses the same repository. The syntax is similar to apt-get.<br/>(not an official cygwin package)

=== Install cron ===
Due to the way Windows manage security credentials, installing <code>cron</code> is not straightforward, in particular when cron jobs must access network share.

Here we install <code>cron</code> as SYSTEM, and store the user password obfuscated in the registry. This assumes that access to this PC is restricted.

* Install {{deb|cron}} package.
* In an cygwin shell launched '''As Administrator''':
<source lang="bash">
passwd -R # Store user password in registry
cron-config # - Yes - Install cron as service
# - No - Do NOT run as user
# - Yes - Use passwd -R
</source>

;Install a {{file|/etc/cron.d/}} job:
Cygwin cron supports cron.d jobs if the following conditions are satisfied:
* The cron job must define variable <code>HOME</code>, and be started as user <code>SYSTEM</code>:
<source lang="bash">
HOME=/
SHELL=/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin

* * * * * SYSTEM date > /var/log/crondtest.log
</source>
* The cron job must be owned by <code>SYSTEM:SYSTEM</code>:
<source lang="bash">
chown SYSTEM:SYSTEM /etc/cron.d/*
</source>
* See <code>/usr/bin/cronevents</code> in case of problems.

;troubleshoot:
* Look at {{file|/var/log/cron}}
* Look for cron in Windows events using <code>/usr/bin/cronevents</code>.


== Development ==
== Development ==
=== References ===
* [http://www.cygwin.com/ml/cygwin-apps/2006-05/msg00017.html cygport]
* [http://www.nongnu.org/cygbuild/manual/index.html#using_preremove_sh_and_postinstall_sh_for_upgrading__etc_files Using preremove.sh and postinstall.sh for upgrading /etc files]
* [http://www.nongnu.org/cygbuild/manual/index.html Cygbuild manual]
* [http://cygwin.com/setup.html Cygwin Package Contributor's Guide]


=== Building from source in Cygwin ===
=== Building from source in Cygwin ===
Building a package from source in Cygwin is unfortunately not an easy task. The steps are:
Building a package from source in Cygwin is unfortunately not an easy task. The steps are:
Line 208: Line 430:


For more information, see cygport source package, <code>man cygport</code>, and [http://www.cygwin.com/ml/cygwin-apps/2006-05/msg00017.html].
For more information, see cygport source package, <code>man cygport</code>, and [http://www.cygwin.com/ml/cygwin-apps/2006-05/msg00017.html].

=== [http://sourceware.org/cygwinports/ Cygwinports] ===
* Run setup as follows:
<source lang=bash>
cygstart -- /path/to/setup.exe -K http://cygwinports.org/ports.gpg
</source>
* Add <tt>ftp://ftp.cygwinports.org/pub/cygwinports</tt> as new repository. Make sure that cygwinports and the regular mirror are '''both''' selected.
* If setup complains about the following error message, try launching setup with flag <code>-X</code> (which disable signature verification)
<source lang=text>
Mirror Error: Setup.ini signature for ftp://sunsite.dk/projects/cygwinports//setup.bz2.sig from ftp://sunsite.dk/projects/cygwinports/ failed to verify.
Possible corrupt mirror? Setup.ini rejected.
</source>


=== Solving dependencies issues with <tt>cygcheck</tt> ===
=== Solving dependencies issues with <tt>cygcheck</tt> ===
Line 242: Line 476:
</source>
</source>


=== Building Vim from source in Cygwin ===
== Building Source Packages ==
=== Vim ===


'''Download the source package'''
'''Download the source package'''
Line 259: Line 494:
'''Install the dependencies'''
'''Install the dependencies'''


Building a package requires that some extra development libraries be installed as well. These libraries are only needed for the build, and can be removed afterwards. To find which libraries to install, simply look at the file <tt>gvim-7.3.003-1.cygwin.patch</tt>. The important remarks is of course the one in bold:
To find which libraries to install, look at the file <tt>gvim-7.3.003-1.cygwin.patch</tt>. The important remark is of course the one in bold:
Runtime requirements:
Runtime requirements:
alternatives
alternatives
Line 286: Line 521:
sed-4.2.1-1
sed-4.2.1-1


So to build the package, we must not only install the packages listed under "Build requirements", but also the '''devel''' version of runtime libraries. Note that not all runtime libraries have a development library.
So to build the package, we must not only install the packages listed under "Build requirements", but also the '''devel''' version of runtime libraries (those marked in blue). Note that not all runtime libraries have a development library.


'''Build the package'''
'''Build the package'''


The standard procedure:
To build the package:
<ol>

<li>Build the package with <tt>cygport</tt>:</li>
<source lang="bash">
<source lang="bash">
cd /usr/src
cd /usr/src
cygport gvim-7.3.001-1.cygport all
cygport gvim-7.3.001-1.cygport all
</source>
</source>
<li>This will create a source and binary package. Unpack the binary package:</li>
<source lang="bash">
tar -xvjf vim-7.3.003-1.tar.bz2 -C / # Unpack to root dir /
# Note: there can be several packages. E.g. for gvim 7.3.447 from cygwinports:
tar -xvjf vim-7.3.447-1.tar.bz2 -C /
tar -xvjf gvim-7.3.447-1.tar.bz2 -C /
tar -xvjf vim-common-7.3.447-1.tar.bz2 -C /
</source>
<li>Run <tt>setup.exe</tt> so that to execute the pending <tt>postinstall.sh</tt> script.
</ol>


'''Changing build options'''
To change the configure settings, for instance to compile vim with ruby feature (<tt>+ruby</tt>), we need to add the option <tt>--enable-rubyinterp</tt>. The easiest is to edit the file <tt>gvim-7.3.003-1.cygport</tt>:

<ul>
<li>Check configure help:</li>
<source lang=bash>
./configure --help
</source>
<li>Check the configure file (<tt>build/src/auto/configure</tt>)</li>
<li>To enable '''ruby interpreter''' (feature '''+ruby''', configure properties '''--enable-rubyinterp'''), the easiest is to adapt the <tt>cygport</tt> file:</li>
<source lang="diff">
<source lang="diff">
--- a/gvim-7.3.003-1.cygport 2011-07-27 14:35:31.765625000 +0200
--- a/gvim-7.3.003-1.cygport 2011-07-27 14:35:31.765625000 +0200
Line 310: Line 564:
CONF_OPT_COMPBY="\"--with-compiledby=Cygwin/X <cygwin-xfree@cygwin.com>\""
CONF_OPT_COMPBY="\"--with-compiledby=Cygwin/X <cygwin-xfree@cygwin.com>\""
}
}
</source>
</ul>

'''Check the build'''

We can check which features are active in Vim, plus the compilation command used, with the vim command <code>:version</code>, or in a shell:
<source lang="bash">
vim --version
</source>
</source>


== Miscellaneous Tips ==
== Miscellaneous Tips ==
<ul>
* Interesting post [http://www.cygwin.com/ml/cygwin/2003-06/msg00897.html about the 'su' command], explaining why there is no 'su' in Cygwin, and how 'ssh' overcomes this.
** Other relevant [http://www.cygwin.com/ml/cygwin/2001-03/msg00337.html post].
<li>Interesting post [http://www.cygwin.com/ml/cygwin/2003-06/msg00897.html about the 'su' command], explaining why there is no 'su' in Cygwin, and how 'ssh' overcomes this.</li>
* Other relevant [http://www.cygwin.com/ml/cygwin/2001-03/msg00337.html post].
* Use '''rxvt''' as terminal emulator instead of standard console window.

* The <tt>+</tt> that appears next to file permission in '''ls''' output means that there are other permissions for the file (use '''getfacl''' on the file to see them)
<li> Use '''rxvt''' as terminal emulator instead of standard console window.</li>

<li> The <tt>+</tt> that appears next to file permission in '''ls''' output means that there are other permissions for the file (use '''getfacl''' on the file to see them)</li>
<div style="padding-left:2em;"><pre>
<div style="padding-left:2em;"><pre>
-rwxr-x---+ 1 beq06659 Users 2555 Oct 10 23:32 inetd.conf* #More permissions set (getfacl inetd.conf to see them)
-rwxr-x---+ 1 beq06659 Users 2555 Oct 10 23:32 inetd.conf* #More permissions set (getfacl inetd.conf to see them)
Line 322: Line 587:
</pre>
</pre>
</div>
</div>

* '''Clipboard''' integration
<li> '''Clipboard''' integration</li>
** To enable ''clipboard'' usage in Cygwin X Server, use option <tt>--clipboard</tt> with command <tt>xwin</tt>.
* To enable ''clipboard'' usage in Cygwin X Server, use option <tt>--clipboard</tt> with command <tt>xwin</tt>.
** Device <tt>/dev/clipboard</tt> can be used for command-line manipulation of the clipboard (note that <tt>/dev/clipboard</tt> is not listed in <tt>/dev</tt> directory). The commands <tt>getclip</tt> and <tt>putclip</tt> can be used for the same purpose (package [http://cygwin.com/packages/cygutils/ cygutils]):
* Device <tt>/dev/clipboard</tt> can be used for command-line manipulation of the clipboard (note that <tt>/dev/clipboard</tt> is not listed in <tt>/dev</tt> directory). The commands <tt>getclip</tt> and <tt>putclip</tt> can be used for the same purpose (package [http://cygwin.com/packages/cygutils/ cygutils]):
<div style="padding-left:3em;"><source lang="bash">
<div style="padding-left:3em;"><source lang="bash">
$ cat myfile >/dev/clipboard # To copy some text to the clipboard
$ cat myfile >/dev/clipboard # To copy some text to the clipboard
Line 331: Line 597:
$ getclip # ... same effect
$ getclip # ... same effect
</source></div>
</source></div>

* Change the prefix used by cygwin to mount windows partitions (default is <tt>/cygdrive</tt>):
<li> '''Change /cygdrive prefix''' &mdash; Either in Bash:</li>
{{pl2|<source lang="bash">
<source lang="bash">
# Change cygdrive prefix to / (default is /cygdrive)
mount --change-cygdrive-prefix /win
mount --change-cygdrive-prefix /win
</source>}}
</source>
or edit <tt>/etc/fstab</tt>:
<source lang="bash">
# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0
none / cygdrive binary,posix=0 0 0
</source>
</ul>


== Cygwin Useful commands ==
== Cygwin Useful commands ==
Line 409: Line 687:
rxvt*scrollBar_right: true
rxvt*scrollBar_right: true
</source>
</source>

To copy/paste in rxvt, either {{kb|Shift-Left click}} or {{kb|Shift-Ins}}.


== [http://x.cygwin.com/ Cygwin/X] ==
== [http://x.cygwin.com/ Cygwin/X] ==

Latest revision as of 17:29, 21 May 2019

References

  • Local Reference Cygwin documentation can be found at /usr/share/doc/cygwin-doc-1.4.
  • Guide from some user

Cygwinport project:

Alternatives to Cygwin

Packages

Installing from CygwinPort

  • Run
cygstart -- /path/to/setup.exe -K http://cygwinports.org/ports.gpg

Creating a local setup.ini

Packages in Cygwin can be installed from repositories. The content of these repositories is described in a file setup.ini. Each package in the repository is made of one or more .bz2 files (the actual package) and a file setup.hint (spec) describing the content of the package. The setup.ini file of the repository is actually a compilation of all setup.hint files in the repository along with additional information. Cygwin apparently does not want to install a package from a single .hint file (or at least have not found how to do so). In that case you need to generate the setup.ini file. Here's an example how this can be done.

Example is based on package recode v3.6.1.

  • Download the package above, and create following directory structure within Cygwin Local Package Directory (where setup.ini location is already shown).
.
|-- http%3a%2f%2fftp....
|   ...
`-- local
    |-- release
    |   `-- recode
    |       |-- recode-3.6-1-src.tar.bz2
    |       |-- recode-3.6-1.tar.bz2
    |       |-- recode-devel
    |       |   |-- recode-devel-3.6-1.tar.bz2
    |       |   `-- setup.hint
    |       `-- setup.hint
    `-- setup.ini
  • Create the file ./local/setup.ini with the following content:
# File manually generated on 20081105.
# setup-timestamp and setup-version are completely fake...
setup-timestamp: 1214338445
setup-version: 2.573.2.2

@ recode
sdesc: "GNU recode utility"
ldesc: "The program recognizes or produces approx. 150 character sets and can convert almost any character set to almost  any other."
category: text
requires: cygwin libintl3
version: 3.6-1
install: release/recode/recode-3.6-1.tar.bz2 838836 c185a17d8e1eb964611d26cbfe9b0e05
source: release/recode/recode-3.6-1-src.tar.bz2 1731299 83b0f5940aa5d2a82355586b6d977bab
  • (in gray) First the header
  • (in black) Then entry giving the package name
  • (in red) Then a copy-paste from setup.hint file.
  • (in green) Then the version (derived from package name)
  • (in blue) And finally two entries for binary and source package, giving for each: location of .bz2 file, the file size in bytes, the md5 checksum (as given by md5sum).

When done, simply install the package by running Cygwin setup.exe, asking to Install from Local Directory. Cygwin will see the new file setup.ini, and proposes for install the packages listed inside.

  • Install packages from the command-line (see [2])

Troubleshooting

Cygwin

  • Look for multiple copies of the cygwin DLL cygwin1.dll. Removes all copies that are not in the cygwin install directory (usually c:\cygwin).
  • List of interfering software:
    • NoMachine NX Client - installs a custom version of the Cygwin DLL which can cause multiple interferences:
      • Cygwin crashes when multiple instances are launched.
      • Running cygwin commands (like ls) in a NT command shell when another instance of cygwin is running creates application error (Memory cannot be "read").
      • setup.exe fails because it runs several instances of bash.
    • SysInternals' Process Monitor
      • All back-quoted commands or $() commands in scripts fail until Windows is restarted

Missing DLL using strace

strace can be used to check whether an application needs a .DLL but cannot find it. This error is not reported by default on cygwin, so an application may just leave without any message, giving the impression that it simply does nothing. strace on the other hand will report about the missing .DLL. To solve the problem, install the .DLL somewhere in your PATH, or edit the PATH to include the .DLL location.

Example ([3]):

$ strace /usr/local/sbin/authtest                   # This will open a dialog box to complain about DLL.
$ export PATH=$PATH:/usr/local/lib/bin
$ /usr/local/sbin/authtest ausername

Out of Memory

Typical Perl error:

Out of memory during "large" request for 268439552 bytes, total sbrk() is 311015424 bytes at /usr/lib/perl5/vendor_perl/5.10/Git.pm line 908, <GEN1> line 615.

Solution is to increase Cygwin's maximum memory (see below)

Rebaseall

rebaseall is needed in case Cygwin reports DLL address conflict when forking. Here the sequence to follow [4]:

  1. Make sure that all cygwin processes are closed (this includes cygwin processes, cygwin services, X server...)
  2. Run the minimal shell ash (e.g. via win-R), and type:
cd /bin
PATH=. rebaseall -v
exit

SSHD

Beware! Whatever is said here, the offcial doc for sshd is located at /usr/share/doc/Cygwin/openssh.README. Read it or the wrath of the Cygwin's Gods will strike on you!

SSH keep asking for the password although public key is set / Wrong HOME directory

  • sshd uses for HOME the value defined in /etc/passwd. If that variable is wrong, sshd will not find the keys to authenticate the session and will prompt instead for a password.
  • This occurs typically for domain users with HOME set on some network server after running mkpasswd -u $USER >>/etc/passwd.
  • Editing the HOME value in /etc/passwd shall fix the problem.

Network shares not visible when logging to Cygwin via SSH

net stop sshd
chown $USER /var/empty       # to fix misleading error "/var/empty must be owned by 'root' and not group or world writeable"
/usr/sbin/sshd&              # or -D to disable daemon mode
  • Another solution is to start a screen session launched directly from a console, then detach, and attaching to that session when logging in via SSH.
In a cygwin terminal:
 screen
 C-ad                 # detach session
From another computer:
ssh cygwinhost
screen -D -R

Administration

Adding Users

Create the user in Windows User Management first, then use command mkpasswd to add it to Cygwin environment.

$ net user <username> <password> /add /yes
$ net localgroup <an_local_group> <username> /add
$ mkpasswd -l -u <username> >> /etc/passwd

Installing a Service

Reference: Cygwin inetutils-1.5 OLD-README

Use cygrunsrv to install a Cygwin process as a service in Windows. Some examples:

$ cygrunsrv -I inetd -d "CYGWIN inetd" -p /usr/sbin/inetd -a -D
$ cygrunsrv --install imapd --desc "Courier IMAP daemon" --disp "CYGWIN imapd" \
  --path /usr/local/sbin/imapd-service.sh --termsig QUIT --type auto --shutdown

By default this will install the service to run under account SYSTEM (LocalSystem), who is the user that has all the required permission up to Windows XP. For Windows 2003 Server or Windows Vista, see below.

Start/Stop the service

Manually starting and stopping is possible via

$ net start <service>
$ net stop <service>

Creating a Privileged User in Windows 2003, Windows Vista

Beginning with Windows 2003 Server and Windows Vista, the SYSTEM user is lacking the "Create a token object" right, which is required to change the user without providing the password. On these systems you have to create an admin user account with special additional user rights. You can use the Cygwin tool editrights or the local/domain security policy mmc snap in to set these rights:

Create a token object
Act as part of the operating system
Replace process level token
Increase quotas
Logon as a service

Get a Bash shell owned by another user

For instance, to open a Bash window as user localuser (you'll need to type in the user's password)

$ runas /user:localuser c:\cygwin\Cygwin.bat

Another method is to apply the same trick used to log as user SYSTEM (see below). This trick is even better since it doesn't require the user password, and hence would enable privilege escalation. However Windows security system prevents a process running as a user without providing the user password to connect to network shares.

Get a Bash shell owned by SYSTEM

On Windows 7

We use PsExec from Sysinternals PsTools:

  • Launch a cmd.exe windows shell with Administrative privileges.
  • Run
psexec -i -s c:\cygwin64\Cygwin.bat
  • This starts a new console with user SYSTEM:
whoami
# SYSTEM
Old trick

This is a trick I found to easily open a Bash windows as user SYSTEM. First create a dummy service bashsystem:

$ cygrunsrv --install bashsystem --desc "Bash SYSTEM" --disp "CYGWIN bashsystem" --path /Cygwin.bat --type manual --interactive

Next, to open a Bash shell as user SYSTEM:

$ net start bashsystem

File permissions

  • Use getfacl and setfacl to set NT file permissions and access conditions.
  • To copy ACL from one file to another
% getfacl srcfile | setfacl -f - dstfile

Install SSHD

Reference:

  • Install the packages:
cygrunsrv
openssh
  • Launch ssh host config:
ssh-host-config -y       # Yes to all question
  • When queried for CYGWIN environment variable, answer
tty ntsec                # For Cygwin 1.5.x
ntsec                    # For Cygwin 1.7.x
  • Launch the service:
cygrunsrv -S sshd        # or 'net run sshd'
  • Optionally, open the SSH port (22) on the firewall
  • Create the /etc/passwd and /etc/group files:
mkpasswd -d WBI -u beq06659 >> /etc/passwd
mkgroup -l -d >> /etc/group
  • Important! — Edit the HOME setting in /etc/passwd to make sure it points to cygwin home directory. Or sshd will not find the pubkey to use when logging in (see Troubleshooting SSHD)
  • Increase sshd process priority to reduce connection time (not sure it helps though)
cygrunsrv -R ssh
cygrunsrv -I sshd -p /usr/bin/nice.exe -a "-n -10 /usr/sbin/sshd -D" -f "CYGWIN sshd" -y tcpip -e 'CYGWIN="ntsec"'

Re-install sshd

rm -rf /var/log/sshd* /etc/ssh_host* /etc/sshd_config /var/empty
net user cyg_server /delete
net user sshd /delete
vi /etc/passwd # virer cyg_server & sshd
ssh-host-config -y
ssh-user-config
cygrunsrv -S sshd

Changing Cygwin's Maximum Memory

It seems that by default, maximum memory for cygwin process are 384MB. One can change this value by modifying a windows registry key (see [7] for details):

# Set limit to 1024 (1GB)
regtool -i set /HKLM/Software/Cygwin/heap_chunk_in_mb 1024
regtool -v list /HKLM/Software/Cygwin


Use the following program (from DJ Delorie) to get the maximum valeu for that variable (returns 1536MB on a Dell Latitude E6410 with 4GB RAM):

main()
{
  unsigned int bit=0x40000000, sum=0;
  char *x;
  
  while (bit > 4096) 
  {
    x = malloc(bit);
    if (x)
    sum += bit;
    bit >>= 1;
  }
  printf("%08x bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);
  return 0;
}

Install a package from the command-line

The official package administration tool is setup.exe (usually available at /setup.exe).

References:

Command-line reference:

Command Line Options:
 -A --disable-buggy-antivirus           Disable known or suspected buggy anti
 					virus software packages during execution.
 -C --categories                        Specify entire categories to install
 -D --download                          Download from internet
 -d --no-desktop                        Disable creation of desktop shortcut
 -h --help                              print help
 -K --pubkey                            URL of extra public key file (gpg format)
 -L --local-install                     Install from local directory
 -l --local-package-dir                 Local package directory
 -n --no-shortcuts                      Disable creation of desktop and start menu
 					shortcuts
 -N --no-startmenu                      Disable creation of start menu shortcut
 -O --only-site                         Ignore all sites except for -s
 -P --packages                          Specify packages to install
 -p --proxy                             HTTP/FTP proxy (host:port)
 -q --quiet-mode                        Unattended setup mode
 -r --no-replaceonreboot                Disable replacing in-use files on next
 					reboot.
 -R --root                              Root installation directory
 -S --sexpr-pubkey                      Extra public key in s-expr format
 -s --site                              Download site
 -U --keep-untrusted-keys               Use untrusted keys and retain all
 -u --untrusted-keys                    Use untrusted keys from last-extrakeys
 -X --no-verify                         Don't verify setup.ini signatures

For instance, to install package screen:

/setup.exe -q -n -N -d -R c:/cygwin -s http://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin -l D:/temp/cygwin -P screen

See http://cygwin.com/mirrors.lst for a list of mirrors.

To use a proxy, use option -p:

/setup.exe -q -n -N -d -R c:/cygwin -s http://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin -p myproxy.com:8080 -l D:/temp/cygwin -P screen

Other solutions:

  • apt-cyg
    apt-cyg is a command-line installer for Cygwin which cooperates with Cygwin Setup and uses the same repository. The syntax is similar to apt-get.
    (not an official cygwin package)

Install cron

Due to the way Windows manage security credentials, installing cron is not straightforward, in particular when cron jobs must access network share.

Here we install cron as SYSTEM, and store the user password obfuscated in the registry. This assumes that access to this PC is restricted.

  • Install cron package.
  • In an cygwin shell launched As Administrator:
passwd -R                # Store user password in registry
cron-config              # - Yes - Install cron as service
                         # - No  - Do NOT run as user
                         # - Yes - Use passwd -R
Install a /etc/cron.d/ job

Cygwin cron supports cron.d jobs if the following conditions are satisfied:

  • The cron job must define variable HOME, and be started as user SYSTEM:
HOME=/
SHELL=/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin

* * * * *     SYSTEM    date > /var/log/crondtest.log
  • The cron job must be owned by SYSTEM:SYSTEM:
chown SYSTEM:SYSTEM /etc/cron.d/*
  • See /usr/bin/cronevents in case of problems.
troubleshoot
  • Look at /var/log/cron
  • Look for cron in Windows events using /usr/bin/cronevents.

Development

References


Building from source in Cygwin

Building a package from source in Cygwin is unfortunately not an easy task. The steps are:

  1. Download the source package
    The source package can be downloaded with setup.exe. The archive is found in directory /usr/src.
  2. Find the dependencies
    Building a package requires that some extra development libraries be installed as well. These libraries are only needed for the build, and can be removed afterwards. The problem is that these libraries are not automatically installed when downloading the source package with setup.exe
  3. Find which chain of commands to use


The main problem I encountered is the total lack of documentation in the source package. The same applies regarding any administration task in Cygwin (like how to install a package manually, etc). Obviously the usual way of ./configure; make && make install could work, but Cygwin often applies specific patches to packages. Also most packages have lots of configuration options. Clearly there must be some automated way to build the packages from the source.

The hint comes from the file with extension .cygport in the source package. See #cygport below.

Cygport

cygport is meant to simplify the building process of packages on cygwin. To build a package from source (assuming we have downloaded the source package with setup.exe), we simply issue the command:

cd /usr/src
cygport gvim-7.3.001-1.cygport almostall            # or 'all', will delete working directory

Cygport will:

  • Unpack the source archive
  • Apply upstream patches
  • Apply cygwin patches
  • Configure the package with a predefined set of option
  • Compile
  • Install (in local dir)
  • Create a source package and a binary package

All this is done in some local directory in /usr/src, where original sources are kept separate from the patched sources, build is not done in the source directory, etc. The structure of that local directory is:

/usr/src/gbim-7.3.003-1
build/                            # Directory where build is done. Check build/src/auto for configure log
config/                          
dist/                             # Packages ready for distribution
inst/                             # Content of Binary package
log/                              # Compile, install log
origsrc/                          # Original, unpatched sources 
patch/                            # patches
spkg/                             # Content of source package
src/                              # Source, patched
temp
CYGWIN-PATCHES

For more information, see cygport source package, man cygport, and [8].

Cygwinports

  • Run setup as follows:
cygstart -- /path/to/setup.exe -K http://cygwinports.org/ports.gpg
  • Add ftp://ftp.cygwinports.org/pub/cygwinports as new repository. Make sure that cygwinports and the regular mirror are both selected.
  • If setup complains about the following error message, try launching setup with flag -X (which disable signature verification)
Mirror Error: Setup.ini signature for ftp://sunsite.dk/projects/cygwinports//setup.bz2.sig from ftp://sunsite.dk/projects/cygwinports/ failed to verify.
Possible corrupt mirror? Setup.ini rejected.

Solving dependencies issues with cygcheck

Most build failure are due to unsatisfy dependencies, i.e. the package to build depends on some (development) libraries that are not installed or not found. Here some hints to solve that issue:

Look at compilation warnings / errors

This is probably the most obvious place to look at first. Compiler will give valuable hints about missing files (note that usually the compile log is saved in a file for later reference)

Look at Configure log

Look into the configure log file (config.log), and look for abnormal results (like X headers not found, etc). Then look in the configure file to see what is the corresponding test. This might give an interesting hint about which file is missing. For instance, in the case of vim, the configure script would compile a small program like the following to conclude about the presence of X headers:

#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
int
main ()
{
    ;
    return 0;
}

If the compilation fails, configure concludes that X headers are not available.

Find which package to install with cygcheck

Knowing the missing file, we can query the cygwin database for which packages provide that file. This is done with cygcheck:

cygcheck -p X11/Intrinsic.h
# Found 3 matches for X11/Intrinsic.h
# libXt-devel/libXt-devel-1.0.7-1 X.Org X Toolkit library (development)
# libXt-devel/libXt-devel-1.0.8-1 X.Org X Toolkit library (development)
# xorg-x11-devel/xorg-x11-devel-6.8.99.901-1      Obsolete package

Building Source Packages

Vim

Download the source package

  • Launch setup.exe, and check the source box (S) of gvim package.
    The package is downloaded in /usr/src. In our case we have:
  • 7.3.001 # These are 3 upstream patches to apply on vim-7.3.tar.bz2 7.3.002 7.3.003 gvim-7.3.003-1.cygport # The cygport script to build the package gvim-7.3.003-1.cygwin.patch # Cygwin patch to apply on vim-7.3.tar.bz2 (patched gvim-completion # Some additional file that will be copied upon install gvim.desktop-r2 vim-7.3.tar.bz2 # Original upstream package

Install the dependencies

To find which libraries to install, look at the file gvim-7.3.003-1.cygwin.patch. The important remark is of course the one in bold:

Runtime requirements:
  alternatives
  cygwin-1.7.5-1                   
  libgdk_pixbuf2.0_0-2.20.1-1    ← + devel package!
  libglib2.0_0-2.24.1-1          ← + devel package!
  libgtk2.0_0-2.20.1-1           ← + devel package!
  libICE6-1.0.6-1                ← + devel package!
  libiconv2-1.13.1-1
  libintl8-0.17-11
  libncursesw10-5.7-18           ← + devel package!
  libpango1.0_0-1.28.1-2         ← + devel package!
  libSM6-1.1.1-2                 ← + devel package!
  libX11_6-1.3.5-1               ← + devel package!
  libXt6-1.0.8-1                 ← + devel package!
  vim-7.3.x

Build requirements:
+(besides corresponding devel packages)'
  binutils-2.20.51-2
  cygport-0.9.89-1
  gawk-3.1.7-1
  gcc4-core-4.5.0-1
  make-3.81-2
  pkg-config-0.23b-10
  sed-4.2.1-1

So to build the package, we must not only install the packages listed under "Build requirements", but also the devel version of runtime libraries (those marked in blue). Note that not all runtime libraries have a development library.

Build the package

The standard procedure:

  1. Build the package with cygport:
  2. cd /usr/src
    cygport gvim-7.3.001-1.cygport all
    
  3. This will create a source and binary package. Unpack the binary package:
  4. tar -xvjf vim-7.3.003-1.tar.bz2 -C /     # Unpack to root dir /
    # Note: there can be several packages. E.g. for gvim 7.3.447 from cygwinports:
    tar -xvjf vim-7.3.447-1.tar.bz2 -C /
    tar -xvjf gvim-7.3.447-1.tar.bz2 -C /
    tar -xvjf vim-common-7.3.447-1.tar.bz2 -C /
    
  5. Run setup.exe so that to execute the pending postinstall.sh script.

Changing build options

  • Check configure help:
  • ./configure --help
    
  • Check the configure file (build/src/auto/configure)
  • To enable ruby interpreter (feature +ruby, configure properties --enable-rubyinterp), the easiest is to adapt the cygport file:
  • --- a/gvim-7.3.003-1.cygport    2011-07-27 14:35:31.765625000 +0200
    +++ b/gvim-7.3.003-1.cygport    2011-07-27 16:51:34.390625000 +0200
    @@ -25,7 +25,7 @@
     		CC="${CC} ${CFLAGS} -fno-strength-reduce -I/usr/include/ncursesw" \
     		LDFLAGS="${LDFLAGS} -L/usr/lib/ncursesw" \
     		CONF_ARGS="--prefix=/usr --with-vim-name=gvim --with-view-name=gview --with-global-runtime=/usr/share/vim" \
    -		CONF_OPT_FEAT="--with-features=huge" \
    +		CONF_OPT_FEAT="--with-features=huge --enable-rubyinterp" \
     		CONF_OPT_GUI="--enable-gui=gtk2 --disable-gtktest" \
     		CONF_OPT_COMPBY="\"--with-compiledby=Cygwin/X <cygwin-xfree@cygwin.com>\""
     }
    

Check the build

We can check which features are active in Vim, plus the compilation command used, with the vim command :version, or in a shell:

vim --version

Miscellaneous Tips

  • Interesting post about the 'su' command, explaining why there is no 'su' in Cygwin, and how 'ssh' overcomes this.
    • Other relevant post.
  • Use rxvt as terminal emulator instead of standard console window.
  • The + that appears next to file permission in ls output means that there are other permissions for the file (use getfacl on the file to see them)
  • -rwxr-x---+ 1 beq06659 Users 2555 Oct 10 23:32 inetd.conf*       #More permissions set (getfacl inetd.conf to see them)
    -rwxr-x---  1 beq06659 Users  706 Nov  8 01:27 initscript*
    
  • Clipboard integration
    • To enable clipboard usage in Cygwin X Server, use option --clipboard with command xwin.
    • Device /dev/clipboard can be used for command-line manipulation of the clipboard (note that /dev/clipboard is not listed in /dev directory). The commands getclip and putclip can be used for the same purpose (package cygutils):
    $ cat myfile >/dev/clipboard                         # To copy some text to the clipboard
    $ cat myfile | putclip                               # ... same effect
    $ cat /dev/clipboard                                 # To print the content of the clipboard
    $ getclip                                            # ... same effect
    
  • Change /cygdrive prefix — Either in Bash:
  • # Change cygdrive prefix to / (default is /cygdrive)
    mount --change-cygdrive-prefix /win
    

    or edit /etc/fstab:

    # For a description of the file format, see the Users Guide
    # http://cygwin.com/cygwin-ug-net/using.html#mount-table
    
    # This is default anyway:
    # none /cygdrive cygdrive binary,posix=0,user 0 0
    none / cygdrive binary,posix=0 0 0
    

Cygwin Useful commands

id

Use command id to print user identity

getclip

Read from the Windows clipboard and write it to standard output (same as cat /dev/clipboard)

getfacl

Display file and directory access control lists (ACLs).

putclip

Read standard input and write into windows clipboard (same as cat >/dev/clipboard)

regtool

  • regtool is the command-line equivalent of Regedit. It can be used to manipulate the content of the Windows registry. Some examples:
% regtool set -b '\prefix\KEY\VALUE' [data ...]   # REG_BINARY
% regtool set -e '\prefix\KEY\VALUE' [data ...]   # REG_EXPAND_SZ
% regtool set -i '\prefix\KEY\VALUE' [data ...]   # REG_DWORD
% regtool set -d '\prefix\KEY\VALUE' [data ...]   # REG_DWORD
% regtool set -m '\prefix\KEY\VALUE' [data ...]   # REG_MULTI_SZ
% regtool set -s '\prefix\KEY\VALUE' [data ...]   # REG_SZ
% regtool unset -q '\prefix\KEY\VALUE'            # -q quiet (no error output)
with prefix being HKCU, HKEY_CURRENT_USER, ... (see man regtool or regtool --help for more)
  • Check whether a KEY exists:
# in Bash...
% if ( regtool check -q '\HKEY_LOCAL_MACHINE\KEY' ); then echo Found; else echo Not Found; fi
# in CMD.EXE...
> regtool check -q '\HKEY_CURRENT_USER\KEY'
> if errorlevel 1 echo Not Found!
  • Check whether a VALUE exists:
# in Bash...
# ... we use list -l to limit output to KEYs!
% if ( regtool list -l -q '\prefix\KEY' | grep -q "^VALUE$" ); then echo Found; else echo Not Found; fi
% if ( regtool get -q '\prefix\KEY\VALUE' >/dev/null ); then echo Found; else echo Not Found; fi
# in CMD.EXE...
# ... we use list -l to limit output to KEYs!
> regtool list -l -q '\prefix\KEY' | find /i "VALUE" >\nul
> if errorlevel 1 echo Not Found!
> regtool get -q '\prefix\KEY\VALUE' >\nul
> if errorlevel 1 echo Not Found!
  • Beware of the use of back-slashes:
% regtool set -b '\HKEY_CURRENT_USER\Key\Value' [data ...]   # OK! works both for Cygwin and CMD.EXE
% regtool set -b '\\HKEY_CURRENT_USER\Key\Value' [data ...]  # NOK! Only works for CMD.EXE
% regtool set -b '\\HKEY_CURRENT_USER\\Key\Value' [data ...] # NOK! Only works for CMD.EXE

Cygwin Applications

rxvt

rxvt is a colour vt102 terminal emulator intended as an xterm replacement. It can be launched without starting any X Window System.

To install, simply add package rxvt.

To configure the default shell used by rxvt, define the following user variable as windows environment variable:

USER=/bin/bash

Appearance is controlled in file ~/.Xdefaults

rxvt*geometry:          160x50
rxvt*loginShell:        true
rxvt*font:              Lucida Console-12
rxvt*saveLines:         3000
rxvt*scrollBar_right:   true

To copy/paste in rxvt, either Shift-Left click or Shift-Ins.

Cygwin/X

Install:

  • Run setup.exe
  • Install the packages: xorg-server, xinit, xorg-docs, X-start-menu-icons, some font packages

Setup keyboard layout:

  • From the command-line, run the command:
startxwin.exe -- -xkblayout be
  • From Start Menu shortcut, edit the shortcut target (need to add quotes!):
C:\cygwin\bin\run.exe /usr/bin/bash.exe -l -c "/usr/bin/startxwin.exe -- -xkblayout be"