A Dive into Windows Subsystem for Linux
A Dive into Windows Subsystem for Linux
By Rob Woodworth
I received an open-ended assignment to find and research a Linux Utility. I’ve chosen a Windows Utility, but I believe it’s extremely relevant to this assignment. Microsoft has just recently come out with a new Linux utility. Windows 10/11 can now natively run Linux, with no dual boot and no virtual machine. You can now run a GNU/Linux command line environment in WSL 2, including command line tools, applications, and utilities, directly in Windows 10 or 11.
https://docs.microsoft.com/en-us/windows/wsl/about
This utility was just officially released to the public in 2019 and it’s still being developed and modified very often. I’ve installed WSL 2 on my machine and documented the process.
https://docs.microsoft.com/en-us/windows/wsl/setup/environment
To install:
1: Run command prompt as administrator.
2: Enter “wsl --install”
Note: This will install Ubuntu by default. Enter “wsl --list --online” for a list of other distributions. You are limited to the options offered by Microsoft. Any distribution can be installed by sideloading, however.
3: Restart the computer.
Windows update will then install WSL 2, then it will open and begin installing
4: Enter a username and password
5: Update the packages with “sudo apt update && sudo apt upgrade”
Updating windows, and installing Ubuntu
Running apt upgrade in Ubuntu, in Windows
Running Nano and Notepad at the same time in
Windows, able to copy text between them
Now at this point after confirming I could run command line programs, I decided to test out running a GUI application, so I started with the basic gedit. I entered “sudo apt-get install gedit”, and I was surprised when apt-get decided I needed 444 additional packages to run gedit. I told it yes, and it spent the next few minutes installing packages.
I checked my start menu to see if it was available there now, as the documentation said it should be, but it wasn’t. You need Windows 11 Build 22000 to run GUI apps, which is only available to Windows beta testers. This feature was just added on 2/14/22, and is still very unstable.
So I’ll stick with the command line for now.
CURL weather forecast making me glad I’m online this quarter
I can run bash scripts stored on my Windows machine
The most striking feature to me is that I can now run Linux utilities on my Windows system. I can grep my documents, create and delete Windows files through Ubuntu, and I can search my Windows file system with Linux commands.
However, I have read several warnings to NEVER try to navigate or alter the Linux files with the Windows explorer, because it will modify them in ways that Linux can’t read.
I can create a Windows txt file in Ubuntu, edit
it with Notepad, then grep the Windows file
I can run my python programs stored on Windows
Copying directory paths between Windows and Linux is a little hard, because Linux uses forward slashes / and Windows uses backlashes \. Also, in the WSL2, the paths start with /mnt/c/ while in Windows they start with C:\. I could write a bash script to find and replace the differences.
So on to one of the first headaches of using this utility: You can drag and drop files onto the terminal just like you can with the Linux terminal, but it displays the Windows directory path. Ubuntu can’t parse Windows syntax.
Drag and drop could be a very handy shortcut, but it creates these useless paths
I’ve decided to create a short bash script to convert these paths into WSL2 Linux paths for convenience. I’m using the sed command to find and replace. Because naturally, one of the first things to do while learning a new operating system is to start editing the system files.
echo “$1” > rp.txt
sed 's+C:\+/mnt/c/+g' rp.txt
sed 's+\+/+g' rp.txt
cat rp.txt
I will name this script rp and copy it into the /bin/ directory so I can call it with:
rp C:\Users\Jungerfumbler\Documents\Schoolwork\IS125\arithmetic.sh
Which outputs:
/mnt/c/Users/Jungerfumbler/Documents/Schoolwork/IS125/arithmetic.sh
Now it outputs the correct path which I can copy and paste, but I need to experiment more to make the output executable.
In conclusion, Windows Subsystem for Linux is an exciting project that will enable Windows users to use Linux tools without having to run two systems or a virtual machine. There are some massive differences to running a full Linux machine, mainly the file structure. My auth.log grepper script doesn’t work because there is no auth.log file in /var/log. Even entering “last” to view the btmp file shows no logins.
This utility is extremely useful for someone working in Windows who wants to run Linux utilities, like for instance a Cybersecurity pentester who wants to run Kali Linux tools on the same machine where they’re using Windows tools. I am very interested to see the full capabilities of this utility as it’s further developed, and to learn more about what it can do now.
Comments
Post a Comment