Americas

  • United States
sandra_henrystocker
Unix Dweeb

How to use Windows Subsystem for Linux to open Linux on Windows 10 machines

How-To
May 18, 20205 mins
LinuxWindows Server

Opening a Linux terminal on a Windows 10 desktop can help you practice your Linux skills and explore Windows from an entirely different point of view. In this post, we look at Ubuntu 18.04 running through Windows Subsystem for Linux (WSL).

Believe it or not, it’s possible to open a Linux terminal on a Windows 10 system and you might be surprised how much Linux functionality you’ll be able to get by doing so.

You can run Linux commands, traipse around the provided Linux file system and even take a novel look at Windows files. The experience isn’t altogether different than opening a terminal window on a Linux desktop, with a few interesting exceptions.

What is needed to make this happen is something called the Windows Subsystem for Linux (WSL) and a Windows 10 x86 PC.

Linux versions for WSL

There are a number of options for running Linux on top of Windows. The Linux OS choices include:

Ubuntu 18.04 LTS is just one option and, in this post, we’ll take a look at how the terminal runs on Windows using this particular distribution and how much it feels like working on a Linux system directly.

If you want to look into the process of putting an Ubuntu distribution on your Windows system, you can start with this page:

https://ubuntu.com/tutorials/tutorial-ubuntu-on-windows#1-overview

As part of the initial setup of installing your Linux on Windows terminal, you’ll be asked to create your user account. Once you do that and open the terminal, you can start to explore. One of the most noticeable differences between your Linux-on-Windows terminal and a terminal window on a Linux system is that examining processes isn’t going to show you much. After all, Windows will be providing the bulk of the required OS support. You’re likely to see something like this:

myacct@hostname:~$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 12:45 ?        00:00:00 /init
root         7     1  0 12:45 tty1     00:00:00 /init
shs          8     7  0 12:45 tty1     00:00:00 -bash
shs        166     8  0 13:32 tty1     00:00:00 ps -ef

Yes, that’s it.

If you’re anything like me, one of your next moves might be to get a handle on the available commands. If you just count the files in the /bin and /usr/bin directories, you should see that there are a lot of commands:

myacct@hostname:~$ ls /bin | wc -l
171
myacct@hostname:~$ ls /usr/bin | wc -l
707

You can list available commands with commands like these (output truncated for this post):

myacct@hostname:~$ ls /bin | head -25 | column
bash              btrfs-map-logical   bunzip2          bzegrep           bzip2recover
btrfs             btrfs-select-super  busybox          bzexe             bzless
btrfs-debug-tree  btrfs-zero-log      bzcat            bzfgrep           bzmore
btrfs-find-root   btrfsck             bzcmp            bzgrep            cat
btrfs-image       btrfstune           bzdiff           bzip2             chacl

myacct@hostname:~$ ls /usr/bin | head -25 | column
NF            aa-exec             apport-cli      apt                apt-extracttempl*
VGAuthService acpi_listen         apport-collect  apt-add-repository apt-ftparchive
X11           add-apt-repository  apport-unpack   apt-cache          apt-get
[             addpart             appres          apt-cdrom          apt-key
aa-enabled    apport-bug          apropos         apt-config         apt-mark

You can update the system with apt commands (sudo apt update, sudo apt upgrade). You can even use Linux commands to move to the Windows disk partitions as you like and . Notice the last three entries in the output below. These represent several drives on the system.

myacct@hostname:~$ df -k
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         973067784 326920584 646147200  34% /
none           973067784 326920584 646147200  34% /dev
none           973067784 326920584 646147200  34% /run
none           973067784 326920584 646147200  34% /run/lock
none           973067784 326920584 646147200  34% /run/shm
none           973067784 326920584 646147200  34% /run/user
cgroup         973067784 326920584 646147200  34% /sys/fs/cgroup
C:            973067784 326920584 646147200  34% /mnt/c	
I:            976760000 231268208 745491792  24% /mnt/I	
L:            409599996    159240 409440756   1% /mnt/l	

If you’re interested in moving out of the Linux space and into the Windows portion of the file system within your WSL session, you can do that easily. Replace “myname” with your Windows account name and a cd /mnt/c/Users/myname/Desktop will take you to your Windows desktop. From there, don’t be surprised if in listing your files you see WRL####.tmp files that don’t seem to exist when you look at your desktop and don’t show up if you look at your files by opening a command prompt. These appear to be temporary files used by Windows for document management. You might also see files listed that look like ‘~$nux notes.docx’ – perhaps ghosts of files that were once located on your desktop. You won’t see those files when you look at your desktop on Windows – even using a cmd window.

Note that you’ll also see Windows directories such as ‘Program Files’ in single quotes when listed in your Linux terminal as you would any file with blanks included in their names. You can even start a Windows executable from your Linux terminal. For example:

myacct@hostname: $ cd /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0
myacct@hostname: $ powershell.exe

If you do this, type exit when you want to end the powershell session.

Linux commands all seem to work as expected, though I don’t get any output when I run the who command.

Windows .txt files will display with cat commands, but the last line in a file will likely be displayed on the same line as the following shell prompt. This is because these files won’t end with a linefeed as Linux text files do.

You can create other accounts and switch user to them (e.g., su – nemo) if you like, but not log into them directly.

You can also update the system with apt commands (sudo apt update, sudo apt upgrade).

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.