nullpo-head / wsl-distrod

Distrod is a meta-distro for WSL 2 which installs Ubuntu, Arch, Debian, Gentoo, etc. with systemd in a minute for you. Distrod also has built-in auto-start feature on Windows startup and port forwarding ability.
MIT License
1.92k stars 92 forks source link

[TUTORIAL] WSL2 + DISTROD + FULL SYSTEMD + GUI DESKTOP #64

Open mgood7123 opened 2 years ago

mgood7123 commented 2 years ago

https://gist.github.com/mgood7123/cb1669169d67218a8518a42e6c585241

COPY

first install distrod

select archlinux

install it

systemd is not fully working yet, lets fix that

next create /etc/wsl.conf with the contents

[user]
default=root

next edit /etc/profile.d/distrod-user-wsl-envs.sh to look like the following

#!/bin/sh

# Load additional WSL session environment variables at runtime by sourcing
# a script Distrod creates at runtime. A Linux user who launches Distrod first
# can manipulte the contents of this script, so the script file is per-user one
# to prevent the user from manipulating other user's environment variables.

if [ -e "/run/distrod/distrod_wsl_env-uid$(id -u)" ]; then
    . "/run/distrod/distrod_wsl_env-uid$(id -u)"
fi

# If the creator of the script is root, a non-root user loading it is harmless
if [ "$(id -u)" != 0 ] && [ -e "/run/distrod/distrod_wsl_env-uid0" ]; then
    . "/run/distrod/distrod_wsl_env-uid0"
fi

if [ "$(id -u)" == 0 ]; then
    echo
    echo "!!! INFO START !!!"
    echo
    echo "To start up the X11 server, please enter the following:"
    echo
    echo "sudo systemctl restart xrdp ; sudo systemctl status xrdp ; startx"
    echo
    echo
    echo
    echo "look for the following lines:"
    echo
    echo "Jul 16 18:14:06 DESKTOP-VJSURS0 xrdp[250]: [INFO ] address [0.0.0.0] port [3389] mode 1"
    echo "Jul 16 18:14:06 DESKTOP-VJSURS0 xrdp[250]: [INFO ] listening to port 3389 on 0.0.0.0"
    echo
    echo
    echo
    echo "then in a new windows terminal:"
    echo
    echo "mstsc.exe /v localhost:3389"
    echo
    echo "with 3389 being the port number you see in the lines above"
    echo
    echo "!!! INFO END !!!"
    echo
    # replace `archlinux` with your username
    su - archlinux -p -c "sudo -S login -f archlinux"
fi

replace archlinux with your username, this will spawn /run/user/ID and the user@ID.service, enabling systemctl --user commands

next exit wsl

then in terminal

wsl --shutdown
wsl -s Distrod
wsl

now we have systemd working, lets get xorg working

wsl xorg requires a headerless xorg setup

install xorg

sudo pacman -S xorg xf86-video-dummy --noconfirm --needed

create /etc/X11/xorg.conf.d/10-headless.conf with the following content

Section "Monitor"
        Identifier "dummy_monitor"
        HorizSync 28.0-80.0
        VertRefresh 48.0-75.0
        Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118
EndSection

Section "Device"
        Identifier "dummy_card"
        VideoRam 256000
        Driver "dummy"
EndSection

Section "Screen"
        Identifier "dummy_screen"
        Device "dummy_card"
        Monitor "dummy_monitor"
        SubSection "Display"
        EndSubSection
EndSection

next, allow X11 to start as normal user

sudo bash -c "echo allowed_users = anybody > /etc/X11/Xwrapper.config"

next, create ~/.xinitrc with the following contents

#!/bin/sh

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# start some nice programs

if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 done
 unset f
fi

/usr/lib/plasma-dbus-run-session-if-needed startplasma-x11

next, install yay, xrpc, and xorgxrdp

pacman -S git base-devel --noconfirm
cd
git clone https://aur.archlinux.org/yay-bin.git
cd yay-bin
makepkg -si
yay -S xrpc
yay -S xorgxrpc

next, open ~/.bashrc and add the following

## test for an existing bus daemon, just to be safe
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
  ## if not found, launch a new one
  eval `dbus-launch --sh-syntax`
fi

if test -z "$XDG_RUNTIME_DIR" ; then
  export XDG_RUNTIME_DIR=/run/user/$(id -u)
fi

export EDITOR=nano

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
    alias pacman='pacman --color=auto'
    alias yay='yay --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

next, we install the plasma desktop

sudo pacman -S kde-desktop konsole dolphin kate konversation firefox discover

next, start xrdp

sudo systemctl start xrdp
sudo systemctl status xrdp

take note of the port number, refer to it as $PORT

and now start X11

startx

next, open a new terminal and login with your LINUX username and password

mstsc.exe /v localhost:$PORT

replace $PORT with the number from earlier