Home > Linux, windows > Cygwin Portable – (some) Linux power on a USB for Windows

Cygwin Portable – (some) Linux power on a USB for Windows

The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the POSIX system calls and environment these programs expect.

With these tools installed, it is possible to write Windows console or GUI applications that make use of significant parts of the POSIX API. As a result, it is possible to easily port many Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software (including the packages included with the Cygwin development tools themselves) as well as lots of BSD tools and packages (including OpenSSH). Even if the development tools are of little to no use to you, you may have interest in the many standard POSIX utilities provided with the package. They can be used from one of the provided Unix shells like bash, tcsh or zsh, as well as from the standard Windows command shell if you have to for some sad reason.

From Cygwin FAQ

If you google Cygwin Portable you will find several solutions:

The one that actually worked for me came from the SourceForge project called CygwinPortable. This version is designed to work with the software bundle PortableApps, but you could use it yourself outside the bundle (see bellow).

To install this software under the bundle just extract the zip file into your PortableAps folder, and on the gui launcher click on Options->Refresh App Icons. You will see two icons appear : one launches cygwin the other launches the setup.

I had some issues getting it to work as i wanted:

Subversion information

it seems the project mantainer packaged the software with svn files, you will need to remove all .svn folders from the exploded contents. I used SVN Cleaner for that.

Outdated setup.exe

The project seems to be unmaintained for some time now. Since that time a new version of cygwin came out which changed how setup.exe and setup.ini work. If you want to update or install new Cygwin packages you will need to download setup.exe from the cygwin page (see bellow for links) and replace the file cygwinsetup.exe in CygwinPortable\App\Cygwin\setup\ with the download one, i would advise you to replace it with a renamed version of the one download if you are using Portable Apps since the portable Apps link runs the original exe file. After doing this you can update and install new cygwin software without a hinch.

Cygwin is locked to the drive you updated it on

After i updated some packages on my cygwin my shell window changed into a normal cmd dos windows, which besides being ugly had the huge disadvantage of not allowing me to copy and paste with a single click. I set out to find a solution and it came in the form of rxvt. %Explain rxvt%. The problem was in my cygwin.bat file.

If you go into CygwinPortable\App\Cygwin you will find a file named cygwin.bat. This batch file is responsible for starting up cygwin. For some reason this file will be changed when you update your cygwin version and (after the setup) it will look something like bellow:

@echo off
F:
chdir F:\Software\Bin\PortableApps\CygwinPortable\App\Cygwin\bin
bash --login -i

the above just runs bash.exe from your cygwin bin dir. And worse it just locked your instalation of cygwin back to the current computer (see the two lines bellow @echo off).

In order to solve this all you have to do is open the cygwin portable zip file you downloaded and replace your cygwin.bat with the one provided in there. This will be able to determine the folder you are running CygwinPortable.exe from and open up your rxvt window.

For those of you wanting to use cygwin outside the PortableApps bundle all the above steps apply, but unfortunally there is some other work you need to do:

  1. All you need to work with cygwin is the folder “CygwinPortable\App\Cygwin” so pull that out
  2. To run cygwin you will need to execute the cygwin.bat file inside that folder. But this file is configured to be run by the CygwinPortable.exe file and not on its own. So to get it to run on is own you will need to change the first line of the script to
for /F %%A in ('cd') do set WD=%%A

Notice i only removed the last part of the line which was telling the batch file where the cygwin base folder was. Since with Portable Apps we run CygwinPortable.exe the base folder would be the file execution folder (\CygwinPortable\) plus “App\Cygwin”. But when running the batch file directly the base folder becomes the batch file execution folder. Ok this part was confusing, if you have any doubts let me know and i’ll revise this part

Enjoy your new powers.

External Links:

Advertisements
  1. xxsplit
    April 6, 2010 at 9:22 am

    Hi masterperas,

    Very nice reading since the portable Cygwin Project seems to have been dropped…
    I went through all the steps and it work except for one detail I haven’t managed to solve yet… Maybe you have an idea ?

    The new mount cmd seems to be behaving differently and will not accept the -b or -u options anymore. When cygwin.bat is lauched it fails on those…

    Removing the -b -u options leaves us with a cygwin.bat that looks like that:

    for /F %%A in (‘cd’) do set WD=%%A\App\Cygwin
    set path=%path%;%WD%\bin;%WD%\usr\X11R6\bin
    set SHELL=/bin/bash
    set DISPLAY=:0
    %WD%\bin\mount -f %WD%\ /
    %WD%\bin\mount -f %WD%\bin /usr/bin
    %WD%\bin\mount -f %WD%\lib /usr/lib
    %WD%\bin\run %WD%\bin\rxvt.exe -fn “-*-Courier-medium-r-*-13-*” -geometry 90×32+100+80 -sr -bg “white” -fg “black” -sl 8000 -termName xterm -e %WD%\bin\bash –login -i

    But here again I get an “Operation not permitted” error and rxvt doesn’t launch ?

    Any ideas ?

    Many thanks in advance…

    • masterperas
      April 6, 2010 at 12:23 pm

      I also have those errors but never minded them much since it doesn’t seem to cause errors inside the command line. From what i can tell -b indicates that all file I/O is in “binary mode”. but it seems that it now defaults to that.

      when i run mount inside rxvt i can see all my mount points even though i receive those errors :
      D:/CygwinPortable/App/Cygwin/bin on /usr/bin type ntfs (binary,auto)
      D:/CygwinPortable/App/Cygwin/lib on /usr/lib type ntfs (binary,auto)
      D:/CygwinPortable/App/Cygwin on / type ntfs (binary,auto)
      C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
      D: on /cygdrive/d type ntfs (binary,posix=0,user,noumount,auto)
      I: on /cygdrive/i type vfat (binary,posix=0,user,noumount,auto)
      Z: on /cygdrive/z type ntfs (binary,posix=0,user,noumount,auto)

      I don’t know why you decided to use the -f option since that one seems to tell mount to fake the mount and not execute it. just remove all option from it and try running the exe file.

      Also make sure you aren’t running the batch file directly. The batch file assumes the working directory is two folders up the folder structure, if you prefer running the batch file directly make sure to change this line:

      for /F %%A in (‘cd’) do set WD=%%A\App\Cygwin

      to

      for /F %%A in (‘cd’) do set WD=%%A

      but in that case you will need to execute cygwin directly from the app\cygwin folder. it’s best to just run the exe file

  2. October 19, 2011 at 3:40 am

    Thanks for the tutorial. I used what I learned from here and else where to take a normal cygwin installation and make it portable. Since the package built for Portable Apps is out of date and I don’t use PortableApps launcher thing I was more interested in just cygwin. Recent cygwin versions are almost portable right of the box. Here is what I did to get it totally portable: http://fadedbluesky.com/2011/portable-cygwin/

  1. August 3, 2010 at 6:54 pm
  2. April 13, 2011 at 7:47 am
  3. October 17, 2011 at 11:44 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: