Making Cygwin portable

One of the very packages I always install when I have to work with Windows is Cygwin. Being able to use my beloved GNU tools really makes things easier. Often I don’t have the option to install it. I grieved a little bit about the fact that some problems could be solved with just 2 commands that were — of course — missing from Windows’ horrendous command prompt. So I snooped around and built the following batch that’ll start a full-blown Cygwin session from i.e. portable harddisk:

@echo off set PATH=%CD%bin;%CD%sbin;%CD%usrsbin;%PATH set HOME=%CD%homePortable mount -bfu %CD%/ / mount -bfu %CD%bin /usr/bin mount -bfu %CD%lib /usr/lib cd %HOME% bash ----login -i

Easy, huh? All you have to do to make it work is renaming your /home/Username to /home/Portable (or simply adjust the setting in the batch). Pretty neat stuff.

Published by

tsukasa

The fool's herald.

3 thoughts on “Making Cygwin portable”

  1. it doesnt run.
    some errors i found. but monut option -b unknown

    here my test: please help

    @echo off
    echo Mein Dir: %CD%

    rem d:
    rem chdir %CD%\bin

    set PATH=%CD%\bin;%CD%\usr\sbin;%PATH
    set HOME=%CD%\home\homePortable

    mount -bfu %CD% /
    rem mount -bfu %CD%/bin /usr/bin
    rem mount -bfu %CD%/lib /usr/lib

    echo %HOME%

    cd %HOME%

    bash —-login -i

    pause

  2. Heya Wolfgang,

    I’m unable to test this thorougly but removing the “mount” lines altogether should do the trick. I didn’t read through the changelog but it doesn’t seem like the manual mount is necessary anymore (note: the original post was written in 2008, a lot has happened…).

    Please note that
    set PATH=%CD%\bin;%CD%\usr\sbin;%PATH
    should be
    set PATH=%CD%\bin;%CD%\usr\sbin;%PATH%

    From a few quick tests, the rest still works. If you run into problems, feel free to comment back.

    As for how I tested:
    – “Froze” my computer configuration with Try&Decide.
    – Downloaded the setup.exe from cygwin.com
    – Ran the default install to a portable harddisk.
    – Created the batch file, ran into the same mount error as you, REM’d the mount lines… success?
    – To make sure the changes would really work, I restarted the machine (thus eliminating all possible registry edits) and ran the batch again – still worked.
    – The test command chain I ran was something simple like “ls | grep pr”, so there might be problems in more complex applications.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.