ruebenramirez / blog

My blog
http://blog.ruebenramirez.com/
7 stars 0 forks source link

windows subsystem linux setup #429

Open ruebenramirez opened 4 years ago

ruebenramirez commented 4 years ago

Copy of my current WSL Ubuntu's /etc/wsl.conf:

$ cat /etc/wsl.conf
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11" 
ruebenramirez commented 4 years ago

I stumbled across this: https://www.omgubuntu.co.uk/2019/07/ubuntu-wsl-metapackage-install

Among the highlights: –

wslusc – WSL shortcut creator placed on Windows 10 desktop wslsys – WSL system information wslfetch – terminal based system info (think Neofetch) wslvar – get Windows system environment variables wslview – open link in default Windows browser

install with: sudo apt install ubuntu-wsl

more info in the github repo: https://github.com/wslutilities/wslu

ruebenramirez commented 4 years ago

wsl v2 is supposed to be much faster than v1:

https://itsfoss.com/windows-linux-kernel-wsl-2/ image

How to install WSL v2: https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

ruebenramirez commented 4 years ago

WSL v2 has a memory leak. The fix appears to be on the slow track.

Solution: cap the max amount of ram that a linux VM will consume: https://github.com/microsoft/WSL/issues/4166#issuecomment-526725261

[/mnt/c/Users/ruebe]$ cat .wslconfig
[wsl2]
memory=6GB
swap=0
localhostForwarding=true

after this file is created, we'll need to restart wsl:

wsl --shutdown

I guess this isn't so much a memory leak. It's more that the WSL v2 VM wont ever release RAM that it uses back to the host Windows OS, so you have to cap it's usage. The memory is still "free" for WSL linux OS usage though.

ruebenramirez commented 4 years ago
ruebenramirez commented 4 years ago

docker inside the WSL 2 VM

I've normally just used the ubuntu docker.io package, but it's probably better to use the community edition of docker instead.

installing docker inside WSL 2 (ubuntu 18.04):

[~]$ cat code/install-docker-ce.sh
#!/bin/bash

# Update the apt package list.
sudo apt-get update -y

# Install Docker's package dependencies.
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common                                                                                                                          
                                                                                                                                                                                                                                                                                                                                           # Download and add Docker's official public PGP key.                                                                                                                  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -                                                                                                                                                                                                                                                               

# Verify the fingerprint.                                                                                                                                              sudo apt-key fingerprint 0EBFCD88

# Add the `stable` channel's Docker upstream repository.                                                                                                               #
# If you want to live on the edge, you can change "stable" below to "test" or                                                                                          # "nightly". I highly recommend sticking with stable!

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) \
         stable"

# Update the apt package list (for the new apt repo).
sudo apt-get update -y

# Install the latest version of Docker CE.
sudo apt-get install -y docker-ce

# Allow your user to access the Docker CLI without needing root access.
sudo usermod -aG docker $(whoami)

source: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

Service management inside of the WSL 2 VM:

I'm used to managing linux services with systemctl

services are managed in WSL 2 with the service command (Sys V init) instead: https://linux.die.net/man/8/service

ruebenramirez commented 4 years ago

getting gui apps to run in X with WSL 2

I use remmina to remote desktop into other machines. This client has support for VNC and RDP.

There are many RDP clients, but Remmina is the only free one I'm aware that supports both:

The X server I'm using on windows: VcXsrv

In WSL 1 I was able to connect directly to the X server, but WSL 2 is linux deployed in a VM with a NAT network solution (the VM has a separate IP from the host Windows OS).

source: https://github.com/microsoft/WSL/issues/4106#issuecomment-515566591

ruebenramirez commented 4 years ago

WSL v1 gui apps to display in a 3rd party X server

install one of these 3rd party X server:

update your ~/.bashrc and resource it

echo "export DISPLAY=localhost:0.0" >> ~/.bashrc && source ~/.bashrc

launch your installed xserver windows app

then start a gui app from the command line:

remmina
ruebenramirez commented 4 years ago

I've been using windows terminal (preview) with WSL 1 ubuntu env for mosh'ing into remote servers and to run remmina to RDP into remote servers.

settings for my Windows Terminal WSL 1 ubuntu environment:

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",

    "profiles":
    [
        {
            "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
            "hidden": false,
            "name": "Ubuntu-18.04",
            "source": "Windows.Terminal.Wsl",
            "cursorShape": "filledBox"
        }
    ],

    // Add custom color schemes to this array
    "schemes": [],

    // Add any keybinding overrides to this array.
    // To unbind a default keybinding, set the command to "unbound"
    "keybindings": []
}

sources: