Make Windows Productive Again with WSL 2

TL;DR

Windows Terminal (Terminal Emulator) + Ubuntu (20.04 latest LTS) via WSL 2 + winget makes Windows 10 productive for Linux / macOS power users.

main()


I was given a Dell Latitude 5300 2-in-1 by a customer for a project. First impression: the build quality is not bad. What? it can be flipped to be a tablet, but no pencil (can’t find it attached).

It runs Windows 10, hmm…

  • BIOS is secured with password.
  • No local Administrator priviledge.
  • VPN needs to stay ON.
  • Seamless Active Directory integration and SSO.
  • Tight Domain security policies enforced.

NOTE: tight security control - give users no choice makes a lot of sense for a non-IT company, which can efficiently reduce helpdesk workload and operational cost.

I planned to install Ubuntu 20.04 in WSL 2 to run Ansible (which does not support Windows as control node) before getting the laptop.

It took a week to get approval to be given Power User.

Then the fun began

  • Added the domain user to local Administrators group (opted out for helpdesk as a result) - this needs to be repeated after each power cycle (domain security poilicy).
  • Installed Windows Terminal
  • Enabled WSL 2
  • Failed to install Ubuntu 20.04 from MicroSoft Store (not provisioned yet based on error message - PUR - not augumented)
  • Installed winget (instead of scoop)

Store doesn’t sell, one can still install from Ubuntu 20.04 focal wsl rootfs tarball, fine ;-)

1
2
3
# wsl --import <DistributionName> <InstallLocation> <FileName>

PS C:\Users\twang\Downloads> wsl --import Ubuntu-20.04 'C:\Users\twang\wsl\ubuntu' C:\Users\twang\Downloads\focal-server-cloudimg-amd64-wsl.rootfs.tar.gz

NOTE: the default login is root, bad even for WSL use case. Create a new user and launch WSL as non-root user:

1
2
3
4
5
6
7
8
9
# create user
useradd -m -U -s /bin/bash terry

# password-less sudo
echo 'terry ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/terry && sudo chmod 0440 /etc/sudoers.d/terry

# launch as user
# wsl -u terry
wsl -d Ubuntu-20.04 -u terry

Set Ubuntu Focal as default

1
wsl -s Ubuntu-20.04

winget works well (early stage) as basic package manager installing required software.

1
2
3
4
5
6
winget install terminal
winget install winscp

# winget search <keyword>
# winget show
# winget source list

NOTE: winget is known to be a AppGet fork, hopefully with Microsoft backed development, I won’t doubt that it’ll soon become homebrew equivalent existence on Windows. Good for users, sad for AppGet, scoop (may still have its place to install CLI utils) and Chocolatey.

Know Just Enough WSL to be Productive

Fun facts

  1. Windows %userprofile% is mounted as /mnt/c/Users/<username> as FSTYPE —> drvfs.

  2. \\wsl$ leads to the parent directory of the list of Linux distributions installed.

  3. In Windows Terminal explorer.exe . launches Windows Explorer in current working directory.

    Equivalent to

    • open . on macOS
    • xdg-open ., dolphin . or other_file_manager . on Linux.
  4. Copying files from Windows to Linux (WSL 2), produces weird <filename>.Zone.Identifier files (NTFS related bug) which it should not, wtf…

    Never mind, just get rid of it find ~ -type f -iname '*.Identifier' -exec rm -rfv {} +

    Use fd if more comfortable with it ;-)

  5. Don’t forget to symlink to Windows %userprofile% to make life in WSL easier

    ln -sf /mnt/c/Users/<username> ~/userprofile
    
    cd ~/userprofile
    

Overall Windows Terminal user experience is OK, it has huge room for improvements though, long way to go.

Last but not least, Linux in WSL 2 is NOT real Linux virtual machne. It is highly customised light-weight Hyper-V VM running customised kernel (Ubuntu 20.04 uses 4.4.0). It doesn’t use systemd as init to initialise userspace, as a result none of the systemd *ctl commands works. Some other GNU or open source utils may not work either, compatibility will improve for sure.

Ubuntu in WSL is definitely NOT perfect.

It definitely won’t replace Linux on workstations and laptops for me in any sense, however, I won’t look back at Cygwin or running Linux VM using VirtualBox if I have to use Windows machines to get things done and deliver.

NOTE: Cygwin popularity declines with the rise of WSL. It is still the preferred choice for people running Windows 7 or older who needs quick & dirty light-weight POSIX-compatible programming and runtime environment.

EOF