To think of Linux on Windows 10 you may be imagining running it under VirtualBox. Now, you can run Linux on Windows 10 in a Command Shell.
For now, it is only Ubuntu 14.04 but later Fedora and OpenSUSE should be added.
First you need to Prepare Windows 10 for the addition of Ubuntu.
Perform an update in Windows to make sure the Operating System is up-to-date. Windows 10 must be a client and not a server version. It must also be the 64-bit and not the 32-bit OS.
Open the Windows Menu and click on the icon for ‘Settings’. Once the Settings window opens you will need to select ‘Update and Security’. Click on ‘For Developers’ and then select the ‘Developers mode’ radio button. You will be prompted to verify that you want to place Windows in Developer Mode. Select ‘Yes’ from the window to continue. The process may take a little to perform its necessary changes. Once Windows is in Developer Mode you will need to open the Windows Menu again. In the dialogue box type ‘Turn Windows Features on or off’. Click on the option which appears for your search.
A new window will open which shows the various Windows Features. Check the box for the option ‘Windows Subsystem for Linux’ as shown in Figure 1. After the necessary files are downloaded you will be asked to restart the system. Allow the system to restart and perform the updates it needs to complete the change to Developer Mode and set up the windows Subsystem for Linux.
After Windows restarts and you’re logged back into the Operating System you need to open the Windows Menu. In the dialogue box type in ‘cmd’ and open a command shell.
Installation of Linux
At the time this article was written the Windows Subsystem for Linux is/was a Beta version. Only Ubuntu is available for installation. In the Command Shell type the command ‘bash’. The Linux Subsystem will be downloaded and installed after you affirm the installation by typing ‘y’.
After the Linux System is installed you will be prompted for a user name and password. The password will be asked for again to confirm the password was typed correctly.
Once the password has been verified you will be at a Linux prompt as shown in Figure 2.
You can now update your system by performing the following commands:
sudo apt-get update
sudo apt-get -y upgrade
You should now have a fully updated Ubuntu Operating System (OS) on your Windows 10 system.
Linux Folder Structure
The Linux files are stored on the Windows drive at: ‘%localappdata%/lxss’. You cannot see this protected folder unless you choose to see Hidden files and folders as well as being able to see Protected files. The settings are made in the File Explorer under ‘View’, ‘Options’ and then ‘Change folder and search options’. Select the option to ‘Show hidden files, folders and drives’ as well as uncheck the option for ‘Hide protected operating system files’.
To see the location of ‘%localappdata’ you can open a Command Prompt and type the command ‘echo %localappdata%’. The output should be something like ‘c:Users[username]appdatalocal’. The ‘[username]’ is your Windows username. Each user account can have a separate copy of Linux installed and updated to their wishes.
Do not make any changes to these folders from Windows. The account settings for these folders are different and any new files added by Windows will have Windows security settings. By making any changes you take the chance of corrupting your Linux install.
At the current stage it is best to not try to load a desktop environment. Most will fail or produce errors. Some people have been able to get the Graphical User Interface (GUI) to start, but some programs will not run correctly.
Linux can save files to the folders as well as to mounted drives. For example, you can change the directory to ‘/mnt/c’ and run the command ‘mkdir TEMP’. If you open Windows File Manager you can see the folder ‘TEMP’ in the root of C. Inside Windows you can create a folder inside ‘TEMP’ and call it ‘test.txt’. Place some text in the file using Windows Notepad and save it. After exiting Notepad bring the ‘bash’ window to the front again and change to the folder ‘TEMP’. Once in ‘TEMP’ you can use the command ‘cat test.txt’ and see the text you placed into the file.
Within the ‘lxss’ folder you can perform all file functions just like on Linux. For example, in the HOME folder under ‘bash’ you can perform the following commands:
- mkdir Temp
- mkdir TEMP
Now, when you perform an ‘ls’ command you will see two folders with the same name but different case. The files and folders you create will have the permissions of the current Linux user.
If you open Windows File manager and go to the ‘lxss’ folder and then to ‘HOME’ you will see the two folders ‘Temp’ and ‘TEMP’.
If you should change to the root of C ‘cd /mnt/c’. Perform the following commands:
- mkdir Temp
- mkdir TEMP
When you execute the second command you will get an error since the folder already exists. There is no case-sensitivity when outside the Linux file structure. Outside the Linux file structure is ‘/mnt/c/’ and other drives which are controlled by Windows.
Any files or folders created outside Linux in the Windows file system will have the permissions of the currently logged in Windows user.
How it works
The Windows Subsystem for Linux (WSL) allows for the 64-bit ELF binaries to be run in the Windows kernel.
The WSL is made up of two subsystems. The two subsystems are:
These two subsystems manage the Linux virtualization on the Windows NT Kernel.
The ‘lxss’ manager will control how the ‘bash’ environment invokes the binaries. All user process are placed into a ‘Linux Instance’. The ‘Instance’ tracks the processes, threads and run time states. Once a user enters the command ‘exit’ then the ‘Instance’ is shut down. When the Linux ‘Instance’ is shut down then every process, thread and run time state is also turned off.
The ‘lxcore.sys’ translates the Linux system calls into compatible Windows system calls. If a compatible call is not found, then the Windows Mode Kernel will manage the system call. Once a translation is made to a compatible system call then the Windows kernel will receive the translated call and perform it.
Inside the Linux file system, when using Linux System Calls, the driver used is the Windows Virtual File System (VoiFS). VoiFS allows you to perform all file functions on the Windows system just as if you were running Linux. This is proven when you created the folders ‘Temp’ and ‘TEMP’ inside the ‘HOME’ folder.
If you change the directory to that of a Windows drive (/mnt/c) then you will use the Microsoft Distributed File System (DrvFS).
If you corrupt Linux, or the WSL, you can easily remove and reinstall it. Once you have performed all the prerequisites from the ‘Preparation’ section, the rest is easy.
To remove WSL you can run the following command from a command-shell in Windows:
lxrun /uninstall /full
NOTE: Before removing WSL you may need to make copies of any files you have under Linux that you want to keep.
Once WSL has been removed you can reinstall it with the command:
You can also use the optional parameter ‘/y’ so there are no prompts to accept. The parameter ‘/setdefaultuser’ followed by a user name will automatically create the user. When using ‘setdefaultuser’ you can use the option ‘/y’ so there is no prompt for a password.
To update the package index the command ‘lxrun /update’ can be used.
NOTE: You can, of course, run the command ‘bash’ as before.
lxrun Adding Linux to Windows can allow Windows users to get a taste of Linux. For those of you running Windows 10 you can now have Linux too. Maybe you can get rid of Windows and make the switch.
- Upgrading to Ubuntu 17.04
- Post a screenshot of your Desktop