How to add a GUI to the new bash console in Windows 10


Our MySQL specialist Peter Laursen shares his hands-on experience with the new anniversary update from Microsoft and provides a step to step guide on how to add a GUI to the new bash console in Windows 10.

 

(update: a new and related blog was published  few days later than this one here)

In this update, released on August 2nd Windows supports the Unix/Linux “bash” shell natively. This is not virtualization and it does not require Cygwin or a similar layer “sitting between” the Unix program and the Windows kernel (or “NT kernel” if you like that term better). The Windows kernel has been modified to understand the “bash” command and quite of lot commands and utilities running in bash exactly like on Unix-type Operating systems. Refer Microsoft’s announcement. Also, the below video (among others) is worth watching.

Video source

It is Canonical that provides the Unix/Linux binaries and the Unix/Linux dialect/flavor is Ubuntu. But still, this is not “Linux”. It is also not “GNU/Linux”. For the simple reason that no Linux kernel is involved at all. It is rather “GNU/Windows” (though Microsoft avoids any reference to GNU). Historically the GNU Operating System was released with GNU’s own kernel. However – when completed – Linus Torvalds’s “Linux” kernel proved superior and replaced the original GNU kernel in the GNU project. Also BSD etc. kernels will support (most of) the GNU subsystem. And now the Windows kernel does too.

But “to some extent” only. It is currently in beta and Microsoft will probably never support all Unix system calls in their kernel. Microsoft’s scope and intention is primarily to “bring bash to Windows”. This may partly be because the Windows “Powershell” introduced with Windows 7 (or was it Vista?) never gained popularity and widespread use. Personally, I also think it is a little awkward to use. But for 10+ years there has been a need for a more powerful Windows console than the traditional “cmd.exe”, what is actually little more than a clone of the 30+ year old DOS command interpreter. So now we have both “Powershell” and “bash” to play with in Windows.

How to get started.

To run bash in Windows 10 just ensure that you have the “anniversary update” installed. Further, you must navigate to Windows 10 settings .. updates and security .. for developers .. and here check the option to define the machine as a “machine for development”. That’s almost all. Now you open a command window and type “bash”. Bash will be downloaded and after a few and simple configuration steps you are ready. This blog elaborates on details(with screenshots).

To see it in action just try to filter the content of your Windows home folder with a regular expression using a typical Unix command “ll | grep Do”. This will list your Windows “Downloads” and “Documents” folders (remember that Unix syntax and file system are case-sensitive).

inline image

The environment installed is very minimal but you can install a lot more things (“sudo apt-get install ..”), that will actually work – including at least:
* Unix scripting languages (Python, Perl, Lua etc.)
* Unix command-line programs (a good example of this is “curl”)
Much of this can be installed on Windows natively, but they were originally designed for a Unix shell and feel more right in this environment.

Launching GUI programs.

Even some GUI programs will work and this is what the rest of blog is about.

I am not a Linux geek but occasionally use several Linux distros for testing our own programs. I am not comfortable with the Linux command line for non-trivial tasks. I prefer a GUI and for the same reason, my preferred Linux distro is SuSE/OpenSuSE (due to the “YaST” GUI available there). But there are few Linux distros I have not tried over the last 10 years – for either curiosity or because I needed to do some testing on the environment.

My three primary GUI requirements are 1) a GUI program launcher 2) a GUI file manager 3) a GUI for software management. With Fedora etc. I will start installing the “Yum Extender” and with Debian/Ubuntu etc. I will install the “synaptic” GUI front-end for the “apt” package manager.

So my first requirement was to run synaptic. It installed with “sudo apt-get install synaptic” without errors. I had already come across this blog that gave an example how to run GUI programs (Firefox in case). What you need to do is basically
1) install an X-server in Windows and ensure that it is running from the system tray. “Xming” is small, has a negligible footprint on your Windows system and does the job.
2) before running a command in bash that requires an X-server for display, run the command “export DISPLAY=:0”. This will forward the output to the X-server sitting and waiting in the Windows system tray.

Now synaptic would not run out of the box from bash. However, it was easy to find a workaround in the Ubuntu Forums – install and use “gksudo”. Synaptic launched in the X-server (with lots of errors in the bash console, though!) and I could install Firefox from Synaptic and next launch Firefox from bash. It connected to the Internet.

Installing a full GUI desktop.

However why not install a full GUI desktop then, I thought? My Linux GUI desktop preference is XFCE. I use it with all Linux ‘flavors’ if possible. So this I would try for a beginning. It installed (“sudo apt-get install xfce4”). However, when launching it (“startxfce”) the X-server complained that communication from XFCE was incorrect. So the two seem to have some problem agreeing about the “handshake” in this environment. However, when I tried the (a little more simple) LXDE desktop, it launched without errors in the console and was pretty functional from the very beginning. I only had to configure the LXDE panel so that it did not hide the Windows taskbar.

inline2

I have added some programs that you would normally not run in this environment – both for having fun, but also in order to show that quite a lot of things will work.  In the panel, I have only the program launcher and a clock. You may see the setup in this image. You will see the LXDE desktop with the bash console that started it brought on top. I have started a few more programs. You will also see the Ubuntu file system display in both Windows Explorer and Thunar. For some programs, the quality of the graphics is (only) similar to when running Windows programs in Wine on Linux – ie. not elegant, but usable. Also, note that my Windows LOCALE setting (Danish in case) is inherited/honored.

Issues and imperfections.

The environment is not perfect, but functional. The most important issues I experienced are:

1) It is somewhat sluggish and irresponsive for 5-10 seconds after it has been started.
2) It does not play well with the Windows 10 desktop scaling mechanism.  Oddities increase if scaling goes beyond 150%. So if you have a high-resolution monitor  .. 🙁
3) It can only display full-screen. You may “minimize” it and “maximize” it. In “normalized” state it does not respond to resizing. However, programs running in LXDE may be brought to the Windows desktop from the X-server icon in the taskbar.
4) Not all programs will launch from the launcher (for different reasons probably). Synaptic does not launch from the panel – in this case probably because the environment does not handle the root prompt for GUI programs properly (synaptic needs root privileges). But I can launch it from a terminal from within LXDE (ie. “sudo /usr/sbin/synaptic”) and it works. The Thunar file manager does and it is an OK file manager (and also what I use mostly with XFCE).
5) There is no sound, as far as I can judge. LXDE’s simple music player actually opens .mp3-files and there is visual feedback in the player that it plays, but no sound comes out. Now, even console tools may want to say “beep” or whatever, so I think sound support is a reasonable request/expectation. I don’t know if it can be installed or if there is no support for sound.
6) I can access all volumes on the system and also USB-attached drives. But I cannot access network shares. It seems that SMB is not available. Again I don’t know if it can be installed or not.

For MySQL users.

Finally, let us try to run the ‘MySQL’ CLI/command-line client. I installed from synaptic where I searched “mysql” and picked the MySQL 5.6 client package alone (no MySQL server) for installation. Let us try to run it. Observe that I specified “–host=127.0.0.1”.  If not the client here will assume it should connect to ‘localhost’ using a Unix SOCKET.

MySQL

As you see, it connects to my MariaDB 10.1 server running in Windows. There are situations where it’s preferable to run the MySQL command-line tools in “bash” and not in “cmd”,  so this is nice.

Summary.

Let us summarize the steps (omitting what I did not manage to get working):

1) Ensure that the Windows 10 “anniversary update” is installed and the machine is configured as a “machine for development”.
2) Install an X-server on Windows and keep it running in the system tray.
3) Install bash. Type “bash” in a command window, accept and go through the few configuration steps.
4) Now you just need to execute the statements below in a command window (approve installation of dependencies listed):

bash
sudo apt-get install lxde
sudo apt-get install synaptic // if you want it
export DISPLAY=:0
startlxde

.. and LXDE starts and you can configure the desktop, the panel and whatever you want. Next go ahead and install software from Ubuntu’s repository.

Nothing to worry about.

One last tip here: When defining your Windows 10 system as a “machine for development” a new Windows command “lxrun” is added to the system. Execute “lxrun /?” to see the options available. So if you messed up things to a state you cannot repair, you can start from scratch by executing “lxrun /uninstall” and next start all over installing bash again. So there is no risk involved experimenting with this.

What will future bring?

What we see now is only the beginning. How far Microsoft wants to take this, we will have to wait and see and this environment is of course not a replacement for my Linux VMs. But if you just need to fire a “curl” command or similar, it is much faster than bringing up a VM and also it uses much fewer system resources. And with the GUI, I just installed, even I can manage and maintain it.

14 Comments

Add yours
  1. 2
    Vincent de Lau

    The technical description you are providing is not very accurate. The “Windows Subsystem for Linux” that Microsoft is providing in this update, does not require Cygwin to run applications. The subsystem provides system calls that are compatible with the Linux kernel. This means that Linux binaries can run natively on the NT kernel, without requiring compilation or other special tricks. Canonical is providing the userspace side of this solution, but in theory you could run any flavour of Linux userspace. One thing to note, is that what we recognize as Windows, is actually the Win32 subsystem running on the NT kernel.

    More information: https://msdn.microsoft.com/en-us/commandline/wsl/faq

  2. 3
    peter_laursen

    This was a plain typo – what I also think should be clear from the context here: “In this update, released on August 2nd Windows supports the Unix/Linux “bash” shell natively. This is not virtualization and it does [not] require Cygwin or a similar layer “sitting between” the Unix program and the Windows kernel (or “NT kernel” if you like that term better). The Windows kernel has been modified to understand the “bash” command and …”

    Corrected now!

  3. 5
    peter_laursen

    Now, there are many ways to scroll – at least
    1) scrollbar
    2) arrow keys
    3) mouse scroll wheel
    4) touch screen
    5) two-finger gesture on touchpad

    For no other reasons than historical ones, I myself mostly use the scrollbar. It has simply become a habit. Even the mouse scrollwheel was not invented when I started using a computer GUI interface (Windows 3.1 and OS2 v.2) back in the 1980’s.

    i have seen some other websites where the scrollbar looks the sames here. The various toolkits for web development today mostly assume availablity of other and more convenient scroll options than the scrollbar (and focuses on providing a design fit for smartphones and tablets). However in particular users with a ~3+ year laptop running Win7 (or older Windows) or Linux laptop users will not always have other options than scrollbar and arrow keys (no mouse, no touchscreen, no gesture support on touchpad).

    So, though I think that both you and I will have to accept that one (maybe not so far) day the scrollbar may cease to exist as a common control, I have asked for improvement for the users for whom using the scrollbar is the best option.

  4. 6
    Toner

    Hi nice article, very helpful but I have one problem

    after following every step in your Article everithing woks BUT I have two screens (one 4K and on 1080p), once I run “startlxde” the desktop window fills BOTH my screens, how do I set a usable resolution (like 1280×720) for the Window ?

  5. 7
    peter_laursen

    I don’t knoiw if it is possible. It may very well be a limitaton with Xming that it cannot be configured to use only a single monitor if more are available.. And actually I wrote that “in normalized state it does not respond to resizing”.

    What you can do, is to ‘minimize’ LXDE and next (from the context menu of the X-server icon in Windows status bar) bring program windows that are open in LXDE to the WIndows desktop.

    • 8
      Toner

      I got it!

      1. Start Xming by running “path\to\xming.exe :0 -clipboard -screen 0 1280×720” in cmd
      2. run “startlxde” in bash

      Ihope that was understandable

  6. 9
    masbagus

    I have confused with your explanation above:
    1) Ensure that the Windows 10 “anniversary update” is installed and the machine is configured as a “machine for development”.
    2) Install an X-server on Windows and keep it running in the system tray.
    3) Install bash. Type “bash” in a command window, accept and go through the few configuration steps.
    4) Now you just need to execute the statements below in a command window (approve installation of dependencies listed):

    In Point number 2 that says “Install an X-server on Windows”, how do I install it? what command should I type?
    Please I’m waiting your reply.

  7. 11
    peter_laursen

    @sai .. even though you have installed MySQ (server) in ‘bash on Windows’ I think it is not running. ‘bash on Windows’ is not a (virtualized) Operating system. It is just a shell and services do not run here.

    If I am right, you may still be able to start MySQL (but not as a service) with a “mysqld_safe” command (http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html). something like “mysqld_safe –datadir=… –port=xxxx” or “mysqld_safe –datadir=… defaults-file=…”. In any case you should specify a port not conflicting with any MySQl server running in Windows (if you have). ‘bash on Windows’ does not create a private network interface for itself. Not sure either where apt/Ubutu puts the datadir, but it could be /var/lib/mysql.

    However i would not do it that way around. I would have the MySQL server running as a native Windows service and (sometimes) use clients running in bash. It is a funny and interesting execercise what you are doing here, but not much more IMO.

  8. 12
    Coliflower

    I see the problem you got, you are running Ubuntu and thinking ts a proper Linux?? Ubuntu is pretty much everything linux does not stand for, why not go use a real linux distro like Debian or Arch?

  9. 14
    peter_laursen

    I think it is free. At least I never paid a cent for the copy I use. I downloaded from https://sourceforge.net/projects/xming/.

    Xming website http://www.straightrunning.com/XmingNotes/ says “By donating you will get a Donor Password sent by email, enabling access to Xming Website Releases and Development Snapshots for private individuals.”. So donation is volunntary,. but a donation gives you some more access/information.

    If you have another point, please elaborate.

+ Leave a Comment