Portable MinGW and MSYS

Sometimes I have to use Windows (for example in my university) and each time it turns out to be sort of a pain in the ass. Standard terminal window is not resizable, text editor is only able to handle DOS linebreaks, even grep is not present on some systems (on the others it is still not that functional) and the whole system is full of things that are opposite to obvious and seem very strange to me.

I decided to create a USB flash drive with a handy terminal, convenient text editor, compiler and popular Unix utilities. MinGW and MSYS seemed a good choice, but it needed some workarounds to be done to make my installation portable.

Installation

I was following the official installation instructions in a virtual machine.

First of all, download mingw-get-setup.exe and run it.

Portable MinGW and MSYS (image 1)

Then, select your USB drive’s root as installation target.

Portable MinGW and MSYS (image 2)

This is what you will have on your flash drive after downloading the installer.

Portable MinGW and MSYS (image 3)

Select your desired options in the installer and apply. I only selected msys-base and mingw32-base (probably, you can leave it out if you don’t need a complier). And this is what you will have on your flash drive after.

Portable MinGW and MSYS (image 4)

To finish the installation, run msys/1.0/msys.bat, type postinstall/pi.sh and answer it’s questions.

Portable MinGW and MSYS (image 5)

You can later add and remove packages with mingw-get. I wanted to have terminal emulator and a text editor, so I also installed msys-mintty and msys-vim.

Portable MinGW and MSYS (image 6)

Making it portable

I wrote this batch script launch.bat on my flash drive that modifies /etc/fstab to use correct Windows drive letter assigned to this flash drive and then launch mintty. It also clears the PATH, so only MinGW and MSYS binaries are in the path, so utilities like ping will not be accessible unless installed with mingw-get.

This does the trick. Now I can use my portable system almost on any Windows computer.

Adding pseudo package manager

Official MinGW documentation recommends installing software with /mingw prefix which adds some extra mess to the system. So I would create a directory /mingw/addons and install each package to /mingw/addons/$pkgname. Each package will install binaries, headers, libraries and other resources. If any information needs to be altered to make the package portable, add it to /mingw/addons/$pkgname/install.sh which will be executed each time when system starts.

To make the system see those files, add this to your /etc/profile:

Now you generally will only need these steps to install new software:

./configure --prefix=/mingw/addons/$pkgname
make
make install

Now this system is more or less complete and easily extensible.

If you have similar portable system, you can use any Windows computer comfortably and compile your software with favorite compiler.

Portable MinGW and MSYS (image 7)

Portable MinGW and MSYS (image 8)

Written on February 28, 2015