Bash in Windows

One of the things I like least about programming in Windows is the command prompt.  I don’t know if it’s navigation is just bad or just too different from the Linux terminals that I am used to but I can’t stand using it.  The PowerShell is definitely better, but I would rather just have a unified terminal across my systems not to mentions some of the useful command line applications that are standard with Linux.  And Bash is the winner for me.

I have been using Cygwin on my Windows machines for quite a while now but mostly only for Linux command line programs (ls, ls, ls,…) and it wasn’t until recently that I thought about running a bash terminal through Cygwin.  When you first install Cygwin you will probably get a shortcut on your desktop or start menu for the “Cygwin Terminal” (if not then see Creating a Cygwin Terminal Shortcut) and if you open it you’ll get something like this:


When I first saw this I immediately dismissed it because it was, well, ugly.  However, if you type the help command into this terminal, you will see the following message:


This terminal is running Bash!  Problem solved, end of post right?  Well it’s still not quite the way I want it for a couple of reasons:

  1. By default, the terminal will start in the ‘C:\cygwin64\home\user’ directory (or wherever you installed Cygwin) or it might be the ‘/cygdrive/c/WINDOWS/system32’ directory
  2. It’s still ugly!

Thankfully, both of these can be fixed easily.  I’ll start with the second problem.

Problem 1 – Starting Directory

Problem #1 is annoying for me because I want my terminal to act like Bash terminal but run over my regular Windows files.  Therefore, I don’t want to have to migrate all of my files from ‘C:\Users\user’ to the Cygwin directories; I just want it to open in my Windows user directory.  So, if you’re like me and you want to do this, just follow these steps:

    1. Open the Cygwin terminal as described above.  Make sure it is the Cygwin terminal and not the Windows command prompt.
    2. Navigate to the ‘/home’ directory.
    3. You may or may not have a user directory in the home directory.  If you do, move all of the ‘.*’ files to your Windows user directory and then delete the user directory in ‘/home’.
    4. Create a symlink to your Windows user directory in ‘/home’ by executing the following command: ln -s /cygdrive/c/Users/user where ‘user’ is your Windows username.
    5. If step #3 above did not apply to you, create a .bashrc file in your Windows user directory and edit it.  If it did apply to you, then you can just edit the existing .bashrc file.
      1. Add the line cd /home/user where user is the same username you used in step #4.

Now whenever you open the Cygwin terminal it will place you in your Windows user directory.

Problem 2 – Bash with Style

So the default Bash style through Cygwin is pretty ugly.  This style is controlled through the .bashrc file that you should be able to find in your Linux home directory.  The default Cygwin home directories also come with a .bashrc file but it is mostly empty.  If you already do some custom .bashrc modifications to your Linux machines then you can go ahead and copy them to your Windows machine and you’re all set.  If not, then I would recommend copying the default .bashrc file from your favorite Linux distribution.  If you don’t have access to a Linux machine, then you can usually find a download for these files, such as for Ubuntu.

Once you have a .bashrc file with the styling that you like, you just need to place it in your home directory.  If you followed the directions for Problem #1 above then this will be your Windows user directory.  If not then it will be your Cygwin user directory which is located in the ‘C:\cygwin64\home’ directory (or wherever you installed Cygwin).

Now all of your terminals will have the style of your choosing.


Creating a Cygwin Terminal Shortcut

Cygwin uses a terminal emulator called MinTTY.  You can find this program in the bin folder of your Cygwin installation, which by default is located at ‘C:\cygwin64\bin’.  So all you have to do is create a shortcut to mintty.exe.


Linux on a Lenovo Thinkpad W541

[Edit April 25, 2016]

I just updated my system to Ubuntu 16.04 and ran into a login loop.  It seems to be bumblebee that was causing the issue as it seems to have been deprecated in 16.04 due to lack of support in favor of Nvidia Prime[10].  Removing bumblebee fixed the issue for me (I also reinstalled Mesa following the procedure in this article but I am not sure if that helped or not).  I am still using nvidia-current (nvidia-304).

The new 16.04 Live CD seems to resolve my initial issues with installing off of a Linux Live CD as I was able to boot it up with no modifications.

[Original Article]

As a programmer, I have need for Linux at my fingertips.  Windows is great for browsing and gaming, but, unless I am specifically creating a Windows application, I want to be using Linux for any kind of development.  The Lenovo W541 comes pre-loaded with Windows 8.1 and so it is obviously compatible with Windows but Linux distributions seem to give the system some trouble.

On my last laptop, I dual-booted Windows 7 and Fedora Workstation.  I constantly use Ubuntu at work and so I like to have a little bit of variety and use Fedora for my schoolwork and personal development and so I thought I would run Fedora on my new laptop as well.  Little did I know the issues I would run into.

Apparently there are commonly issues with installing Linux distributions on newer systems with Live CDs as the developers of the OSes and the Linux kernel need to work towards integrating new hardware setups.  The support wasn’t quite there yet when I received my W541 but I found some threads relating to the same issues I saw that helped me get Linux installed.

Trying Fedora

So when I first tried booting from a Fedora Workstation Live CD I got a whole lot of nothing.  More specifically, I got the following error messages and never reached the wonderful installation GUI:

"mmc0 unknown controller version(3), You may experience problems"

This was with the default BIOS settings.  I tried changing the UEFI boot settings to Legacy Only which got me to the Fedora Live desktop and I was able to start installation but then Fedora would totally freeze and I would have to hard shutdown the laptop with the power button.  This would occur every time I tried even after further tweaking BIOS settings and even updating the BIOS.

Researching this issue, I did not find anything specific to Fedora but I did find others having issues installing Linux distributions on the Lenovo W541.  The most relevant posts I found were a post on the Ubuntu forums which also linked to a bug ticket on Launchpad.  The issue described seemed to have the same root cause as mine but with Ubuntu.  One reply to the bug ticket laid out a procedure which the poster claimed got the system to work with an Ubuntu installation.  Since I am familiar with Ubuntu and I hold no particular loyalty to Fedora, I decided to try out this procedure to see if I could get any Linux distribution running.[1][2]

Moving to Ubuntu

I normally stick to the Ubuntu LTS versions but some people said they were having better luck with Ubuntu 15.04 so I decided to just go with that.  I had previously installed 15.04 on a VM on my desktop machine and didn’t have any problems so I figured it would be fine.

Using the Live CD

The first issue that people usually see when they try to boot with the Ubuntu Live CD on the W541 is a black screen right when it looks like the Desktop environment is going to load.  This can be circumvented by changing the Linux boot parameters in grub.  This can be accessed on the screen that says “Try Ubuntu without Installing” (i.e. the grub menu).  With the first menu entry highlighted, press the ‘e’ key.  This will bring up a text editor with the grub configuration for that menu entry.  Scroll down to the line which starts with linux and, at the end of the line but before the $vt_handoff parameter, add the nomodeset parameter.  The end of the line should then read quiet splash nomodeset $vt_handoff.  Then press Ctrl+x to boot with those settings.

The nomodeset parameter “instructs the kernel to not load video drivers and use BIOS modes instead until X is loaded.”  This removes the black screen issue which is common for NVIDIA cards which use the nouveau driver by default.[3] You will need to perform this procedure every time Ubuntu is booted until the nouveau driver is blacklisted in a subsequent step.

Now that you have access to the Ubuntu Live Desktop you can install Ubuntu normally with the installation tool.

Initial Setup

Once Ubuntu is installed on the system, we want to blacklist the nouveau driver so that it is not loaded by the kernel on boot and we also want to setup the NVIDIA drivers with bumblebee/primus.  Bumblebee allows for the switching between the integrated Intel graphics cards and the NVIDIA card.

To blacklist nouveau so that we don’t need to set the nomodeset parameter, we need to modify the /etc/modprobe.d/blacklist.conf file by adding the following line:[4]

blacklist nouveau

With that taken care of, we can install bumblebee.  With older versions of Ubuntu, bumblebee had to be installed via a PPA, but it is now integrated into the standard software repositories.  Run the following command to install bumblebee:[5]

sudo apt-get install bumblebee bumblebee-nvidia primus linux-headers-generic

Next we want to install the NVIDIA reference drivers.  This can be done with the following commands:[6]

sudo apt-get remove --purge nvidia*
sudo apt-get install nvidia-current

Next we want to remove the xserver-xorg-video-intel package with the following command:[2]

sudo apt-get remove xserver-xorg-video-intel

Now we want to setup the bumblebee configuration to use our NVIDIA drivers.  The bumblebee configuration file is located in the /etc/bumblebee/bumblebee.conf file.[5]  In the [bumblebeed] section, we want to set the Driver parameter to nvidia.  Then, in the [nvidia] section, we want to set the KernelDriver parameter to nvidia-current[2] and the LibraryPath and XorgModulePath parameters should have their nvidia-current versions of their paths.[6] For example, these are my two versions of these parameters:


Next we will setup our Linux boot parameters. This is done by modifying the /etc/default/grub file by making the GRUB_CMDLINE_LINUX_DEFAULT parameter read like the following:[2]

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=\"!Windows 2013\""

The acpi_osi parameter is supposed to help with backlight and fan control issues.[3] After modifying this file, run the sudo update-grub command and then reboot.

The final step in setting up the graphics is to compile the Mesa driver from source and install it over the mesa drivers which should have already been installed via the package manager. Doing this turns out to have quite a few steps so I decided it should have its own section…

Compiling and Installing Mesa

Follow the following procedure in order to compile and install the Mesa driver from source:

  1. Download the Mesa source with the command:[7]
    git clone git:// mesa.git
  2. Install Mesa dependencies with the following commands:[7]
    sudo apt-get build-dep mesa
    sudo apt-get install llvm
  3. In the mesa.git directory you just downloaded, run the command:[7]
    autoreconf -vfi
  4. Run the command:[7]
    ./configure --prefix=/usr \
                --enable-driglx-direct \
                --enable-gles1 \
                --enable-gles2 \
                --enable-glx-tls \
                --with-dri-driverdir=/usr/lib/dri \
                --with-egl-platforms='drm x11' \
    1. If this command complains about your libdrm version then you will need to also compile and install libdrm from source using the following procedure.  Otherwise, continue with the next step.
      1. Download the latest version of libdrm from the download page.
      2. Extract the downloaded archive using the command
        tar -zxvf libdrm-x.y.z.tar
      3. Install libdrm build dependencies with the following commands:
        sudo apt-get install valgrind
        sudo apt-get install libpciaccess0 libpciaccess-dev
      4. In the libdrm directory which was extracted, run the following commands to compile and install libdrm:[8]
        sudo make install
      5. Check for the /usr/local/lib/pkgconfig/libdrm_intel.pc file. If it does not exist, copy the file from the libdrm source package. It is typically in the intel directory.[8]
      6. Add the /usr/local/lib/pkgconfig/ directory to the PKG_CONFIG_PATH environment variable. This can be done with the following command:[8]
        export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

        or, for a more permanent solution, add that command to your .bashrc file. You can confirm that this is setup properly by running the command:[8]

        pkg-config --modversion libdrm_intel
      7. After libdrm is installed correctly, re-run the configure command for Mesa above.
  5. Run the following commands to finish compiling and install Mesa:
    sudo make install

After installing Mesa, your graphics should be totally setup and therefore your Linux installation on your Thinkpad W541.

Additional Configurations

Trackpad Setup

Synaptics for Linux apparently does not currently support the trackpad on the W541. You should therefore not use Synaptics in your Linux installation but instead use the imps protocol. This can be set up by modifying the /etc/modprobe.d/psmouse.conf file (or creating it if it does not exist) by adding the following line:[2]

options psmouse proto=imps

[Edit September 1, 2015]

The above trackpad setup provided me with a functional trackpad but it did not have trackpad scrolling.  After doing some digging, I removed the above configuration and reinstalled synaptics and the trackpad is working with scrolling so it appears that there is now support for the trackpad in synaptics.  You can reinstall synaptics with the following command:

sudo apt-get install --reinstall xserver-xorg-input-synaptics

You should reboot afterwards.  There are further settings in the System Settings -> Mouse & Trackpad menu.  You can verify that synaptics is running by running the synclient command from a terminal window.  If it outputs a bunch of property values then it is running.


When I first started using Windows with the 3K display of my W541 I didn’t really notice much difference from the 1080p displays which I was used to. As soon as you get to the Ubuntu desktop you see a huge difference. Everything will look super miniature. In a way this is a good thing since it gives you a sense of having much more monitor space for having a million terminals and code editors open for development but it also makes it a bit difficult to see and isn’t totally usable as is.  My best guess as to why there is such a difference in appearance between Ubuntu and Windows is that Windows has “better” built-in scaling for larger resolutions.

The easiest solution is to adjust the system font sizes. This can be done by installing the unity-tweak-tool via sudo apt-get install unity-tweak-tool. Then run the utility either via the command line or through unity. Navigate to the Fonts section and then you can adjust several system font sizes to your liking.[9]


  1. Ubuntu Forums: “Problem booting Lenovo Thinkpad W541” by manadi
  2. Ubuntu Launchpad Bug #1437386 by manadi
  3. Ubuntu Forums: “How to set NOMODESET and other kernel boot options in grub2” by P4man
  4. Ask Ubuntu: “install nvidia driver instead nouveau” by Dor Zohar
  5. Ubuntu Wiki: “Bumblebee”
  6. Ask Ubuntu: “bumblee on Ubuntu 15.04” by Dima
  7. Debian: “How to build mesa”
  8. Surfing Troves: “Defeating the MesaLib installation issues”
  9. How-to-Geek: “Resizing Unity Launcher Icons”
  10. Ask Ubuntu: “Does Ubuntu 16.04 support hybrid grafics cards (bumblebee)” by JOnathanJOnes

Lenovo W541 Synaptics Touchpad Scroll Causes Tiny Mouse

I recently bought a new Lenovo W541 with 3K display.  The W541 uses Synaptics UltraNav driver for handling touchpad and trackpoint gestures.  When scrolling a window with the touchpad, the Synaptics software changes the cursor to have some fancy scrolling cursor.  After done scrolling, the software reverts to the regular cursor but a much smaller version (about half the size I think).

I’m not sure if this has anything to do with poor support for displays larger than 1080p but the rest of the software works really great and I didn’t want to do away with it but I cannot live with a tiny cursor after every time that I scroll.

I was able to revert to the regular cursor size in Windows mouse settings (Right Click Desktop -> Personalize -> Change mouse pointers -> Pointers tab) by changing the scheme to something and then back to the default and applying.  Unfortunately the Synaptics software changes the cursor back to a miniature version every time you scroll with the touchpad.

I was able to find a more permanent solution with the following method:

  1. Close the Synaptics software with the Task Manager (Ctrl + Shift + Esc).  It usually has 3-4 processes running.
  2. Download the Resource Hacker freeware tool.
  3. Run Resource Hacker as administrator and open the C:\Program Files\Synaptics\SynTP\SynTPEnh.exe file.  It should look similar to the below image.


  1. Expand the Cursor header in the left pane. By clicking any of the entries in this list, you will display the embedded cursor images which the Synaptics software uses.  The cursors used for scrolling are numbers 41, 43, 64, and 65.  For each of these cursors right click the entry in the left pane and select Replace Cursor.  This will open the menu depicted in the following image.


  1. Click the Select file with new cursor… button.  Navigate to the C:\Windows\Cursors directory.  Now you need to select the default cursor for the theme you have selected.  The default theme uses the aero_arrow.cur file.  Select the cursor and click Open.
  2. Back in the Replace Cursor menu shown above, click the Replace button. Repeat this process for each of the scrolling cursors listed above.
  3. Once all of the cursors have been replaced, click the save button in Resource Hacker.  Resource Hacker will automatically save a backup of the EXE file so you don’t need to worry about creating a backup manually.

At this point, if you were to restart the Synaptics software and scroll with the touchpad it would not change to the scroll cursor but the cursor will still shrink.  This is because there were actually three different versions of the cursor we replaced the originals with, one which is 32×32, one which is 48×48, and another which is 64×64.  Synaptics will always choose the 32×32 one for some reason and then the cursor will stay that size afterwards.  Now we just need to delete the two smaller cursors so it will always use the 64×64 version.  Unfortunately, if you try to do this in Resource Hacker, it will delete all three sizes.  However, another freeware tool called, Anolis Resourcer can achieve this.

  1. Download Anolis Resourcer.
  2. Run Anolis as administrator and open the C:\Program Files\Synaptics\SynTP\SynTPEnh.exe file.  Then click on the Cursor Image header in the left pane.  It should look similar to the below image.


  1. The first 12 cursors correspond to the three different sizes of the four cursors we replaced.  You can identify the size of each cursor by double clicking it, double clicking it again, and then clicking the small Show Information button on the toolbar.  For convenience, the cursors that should be deleted are 2, 3, 5, 6, 8, 9, 11, and 12.  In order to delete a cursor, you need to expand the cursor all the way in the left pane, click the cursor number, click the Delete button on the toolbar, and then click OK.  Repeat this for each of the listed cursors.


  1. After deleting all of the necessary cursors, click the Save button.
  2. Restart the Synaptics software.  I am not sure which executable needs to be launched for this so I wound up just restarting my computer.

Using the touchpad to scroll should no longer change the cursor.

For reference, I was using Windows 8.1 Pro and Synaptics ClickPad V1.1 on SMB Port Driver Version: installed via the Lenovo Software Update tool.  The current software versions when writing this article were 4.2.4 for Resource Hacker and 0.9.3531.38736 for Anolis Resourcer.