Giter Site home page Giter Site logo

ubuntu-wsl2-systemd-script's Introduction

ubuntu-wsl2-systemd-script

Script is unsupported and will no longer be maintained, but will be up here because it is used by quite some people.

Script to enable systemd support on current Ubuntu WSL2 images from the Windows store.

I am not responsible for broken installations, fights with your roommates and police ringing your door ;-).

Instructions from the snapcraft forum turned into a script. Thanks to Daniel on the Snapcraft forum!

Usage

You need git to be installed for the commands below to work. Use

sudo apt install git

to do so.

Run the script and commands

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
# Enter your password and wait until the script has finished

Then restart the Ubuntu shell and try running systemctl

systemctl

If you don't get an error and see a list of units, the script worked.

Have fun using systemd on your Ubuntu WSL2 image. You may use and change and distribute this script in whatever way you'd like.

ubuntu-wsl2-systemd-script's People

Contributors

brlin-tw avatar david50407 avatar hnakamur avatar patrick330602 avatar paulstelian97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ubuntu-wsl2-systemd-script's Issues

Any way to revert running the script?

I'm new to Linux as a whole, so apologies for bad questions.

I tried running this through the README (Ubuntu 20.04). Running gnome-session does open a desktop environment while using Xlaunch (with -ac argument), but it starts a startup screen that I can't complete as my mouse wont work on it.

Is there anyway I can reverse back to wsl before I ran any of the code?

not working

C:\Users\Alexander>wsl -d Ubuntu-16.04
Cannot execute daemonize to start systemd.

all bash scripts spawn new interactive session

When I run a script with a shebang like #!/usr/bin/env bash or #!/bin/bash, bash is started in interactive mode (so I get a prompt and the script doesn't run).

in the setup script this line: sudo sed -i 2a"# Start or enter a PID namespace in WSL2\nsource /usr/sbin/start-systemd-namespace\n" /etc/bash.bashrc might be the culprit. It puts the source line above the line that exits for noninteractive stuff (i.e. [ -z "$PS1" ] && return). I moved the source line below the noninteractive stuff and things seem to work again.

I think this issue is caused by these scripts.

I also use zsh by default (via chsh)

PS. I realise this isn't likely to be patched as mentioned in the readme, but wanted to put this here in case it helps someone.

ubuntu-wsl2-systemd-script.sh: line 2: $'\r': command not found

The scripts are using windows line breaks (CRLF) instead of unix line breaks (LF). This causes some weird errors:

bash ubuntu-wsl2-systemd-script.sh

Error:

ubuntu-wsl2-systemd-script.sh: line 2: $'\r': command not found
ubuntu-wsl2-systemd-script.sh: line 18: syntax error near unexpected token `$'{\r''
'buntu-wsl2-systemd-script.sh: line 18: `function interop_prefix {

Solution is to convert the windows line breaks to unix line breaks. The easiest way to achieve this is to use a text editor such as VS Code or Notepad++.

System: Ubuntu 18.04 LTS

Question regarding WSL startup

systemd works perfectly! THANK YOU! Only question I have is, I launch a script in my home directory using "wsl ~/startup.sh" However, it appears that systemd doesn't start until after my script is running. Is there anyway around this?

some error

   ~  cd ubuntu-wsl2-systemd-script/  ✔  with root@ubuntu  at 16:54:39 
   ~/ubuntu-wsl2-systemd-script  on   master  bash ubuntu-wsl2-systemd-script.sh
*It appears that you are not running on WSL.
To forcibly install anyway, run this script with the --force parameter.

   ~  uname -a  ✔  with root@DESKTOP-PBHSH3O  at 16:58:02 
Linux DESKTOP-PBHSH3O 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

nsenter: cannot open /proc/320/ns/time: No such file or directory

I get this after running your script.
nsenter: cannot open /proc/320/ns/time: No such file or directory

Luckily, I can "wsl -e bash --norc" and revert the changes to /etc/bash.bashrc. But what is wrong with my /proc since nsenter doesn't like it?

Windows version 19041.388
WSL 2
Pengwin

The USER_HOME variable might not result in a single line/value

The
USER_HOME="$(getent passwd | awk '{ FS=":" } /'"$SUDO_USER"'/ {print $6}')"
line in enter-systemd-namespace may result in multiple entries if the value of $SUDO_USER present in multiple lines.
For example, assume that the $SUDO_USER is bus and a section of the getent passwd is as follows :

bus:x:9:9:bus:/home/bus:/usr/sbin/nologin
xbus:x:118:125::/var/lib/xbus:/bin/false

Then USER_HOME will be set to

/home/bus
/var/lib/xbus

To solve it,
the reg. ex. in awk command should be changed to '"^$SUDO_USER:"'

Sudo systemctl doesn't work

I followed the instructions and running systemctl lists units, but sudo systemctl returns "Failed to connect to bus: No data available"

VSCode terminal broken when using Remote WSL extension and scripts from this repo

This was originally reported at, microsoft/vscode#102628, however I believe that the issue at play is in the scripts used here, not in VSCode.

Observed problem

When running VSCode's Remote WSL extension with this script in place on the most recent Windows Insider build (20175.1000), the terminal fails to start. It flashes the following errors briefly before closing.

xargs: unmatched double quote; By default quotes are special to xargs unless you use the -0 option

Usage: login [-p] name
       login [-p] [-h host] [-f name]
       login [-p] [-r host]

Underlying problems

The output above points to two separate issues:

  1. xargs is choking because of bad quoting somewhere, and
  2. the login command is being run with arguments that it doesn't expect.

Xargs issue

The xargs error above comes from the usage of the xargs command at line 47 of enter-systemd-namespace.

When the WSL Remote extension connects, it creates/modifies ~/.systemd-env. The line below is from that file. When I delete only this line and run the command manually, the xargs error goes away.

SUDO_COMMAND="/bin/bash -c set -a; [ -f \"\$HOME/.systemd-env\" ] && source \"\$HOME/.systemd-env\"; set +a; exec bash -c \\'/home/myuser/.vscode-server/bin/91899dcef7b8110878ea59626991a18c8a6a1b3e/node\\'\\ -p\\ \\'\\\"f3cfc37ff7a5\\\"\\ +\\ JSON.stringify\\(process.env\\)\\ +\\ \\\"f3cfc37ff7a5\\\"\\'"

Fix

I couldn't make sense of that mess of escape sequences, so I simply edited enter-systemd-namespace to use \n as a delimiter by replacing xargs printf ' %q' with xargs -d '\n' printf ' %q' at line 47 of enter-systemd-namespace. This appears to make things work as expected.

Login command issue

Regardless of whether the xargs fix above is in place, the VSCode terminal shows the following error immediately prior to exiting.

With the xargs fix in place, the login command that's failing now looks like the following on my machine

/bin/login -p -f myuser 'AMD_ENTRYPOINT="vs/server/remoteExtensionHostProcess"' 'APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL="true"' <other env vars snipped>

Unfortunately I don't yet have a fix for this one. I assume the failure is either because of the single quotes causing the double quotes to be passed as part of the env var args, or because login doesn't expect a list of env vars when the -f flag is used, as shown at the top of the login man page, which I've included below:

NAME
       login - begin session on the system

SYNOPSIS
       login [-p] [-h host] [username] [ENV=VAR...]

       login [-p] [-h host] -f username

       login [-p] -r host

Error connecting to agent: No such file or directory. Failed to reload daemon: Connection reset by peer

First I tried to run the script using zsh (I shouldn't?) and it prompted:

ubuntu-wsl2-systemd-script.sh:29: = not found

Then I restarted the temrinal and ran it using bash and apparently everything was ok but I notice these lines:

%sudo ALL=(ALL) NOPASSWD: /usr/sbin/enter-systemd-namespace
'\\wsl$\Ubuntu\home\joao\ubuntu-wsl2-systemd-script'
CMD.EXE was started with the above path as the current folder.
UNC paths are not supported. Standardizing to Windows folder.

SUCCESS: the specified value has been saved.
'\\wsl$\Ubuntu\home\joao\ubuntu-wsl2-systemd-script'
CMD.EXE was started with the above path as the current folder.
UNC paths are not supported. Standardizing to Windows folder.

SUCCESS: the specified value has been saved.

Then now when I start the terminal this error is shown:

Error connecting to agent: No such file or directory
Error connecting to agent: No such file or directory
Usage: login [-p] [name]
       login [-p] [-h host] [-f name]
       login [-p] -r host
Failed to reload daemon: Connection reset by peer

Normally it should start PostgreSQL.

Checking the service status:

 service postgresql status
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled;>
     Active: active (exited) since Mon 2020-06-08 20:26:27 -03; 11min>
   Main PID: 320 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 15300)
     Memory: 0B
     CGroup: /system.slice/postgresql.service

Jun 08 20:26:27 DESKTOP-UKICADF systemd[1]: Starting PostgreSQL RDBMS>
Jun 08 20:26:27 DESKTOP-UKICADF systemd[1]: Finished PostgreSQL RDBMS.

Any idea?

breaks wslg

Running the script works to enable systemd. In both 18.04 and 20.04 , this breaks the environment variables that enable wsl gui apps provided by microsoft.

Intead you get display errors when starting from the terminal:

**graham@GrahamBook:~$** sudo virt-manager
[sudo] password for graham:
**graham@GrahamBook:~$** \

(virt-manager:387): Gtk-WARNING **: 08:41:36.307: cannot open display: :0

When running using the wslg shortcuts, it works:

C:\Windows\System32\wslg.exe ~ -d Ubuntu-18.04 virt-manager

Script working, but very weird

Hi everyone!

First of all, thanks for this script!

It works... but very weird for me)

My environment:

Windows 10
OS version: 2004
OS build: 20190.1000 (insider preview "dev")
WSL: Ubuntu-20.04.1
Linux kernel: 4.19.121

The script itself works strange: when I run wsl for the first time and execute a command:

snap version

The result of the command execution:

snap    2.45.1+20.04.2
snapd   unavailable
series  -

Then I execute the command:

systemctl

The result of the command execution:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Then I execute the command:

sudo snap --list

The result of the command execution:

error: access denied (see 'snap help login')

Then I execute the command:

wslfetch

And, oh! miracle! Once this command is executed, snap packages become available.

But the weird thing doesn't end there - if I to run snap packets in a new session — an error will be displayed:

error: cannot find installed snap "bashtop" at revision 112: missing file /snap/bashtop/112/meta/snap.yaml

In addition, in the session where snap packages are available, are no longer commands available, such as: "code .zshrc" or "explorer.exe ."

code ~/.zshrc
zsh: command not found: code
explorer.exe .
zsh: command not found: explorer.exe

It seems that if systemd is available in the current session, which in turn makes snapd and snap packages available, this makes it impossible to use commands to run windows applications in this current session.

But if systemd is not available in the session, then application windows commands will be available.

And this is somehow affected by the command "wslfetch".

Obviously, if the error "zsh: command not found: code" or "zsh: command not found: code" is displayed, it is somehow related to the PATH environment variable.

It looks like that activation of systemd somehow modifies the PATH environment variable - but how? I don't understand that.

What result do I want to achieve? Ideally, for systemd to start with any new ubuntu session and this should not modify the PATH environment variable in any way - I should be able to use "code .something" or "explorer.exe ." and similar commands to run windows applications from ubuntu when systemd is activated.

This is a link to the video for a better understanding of the problem, where I show everything I wrote above: https://yadi.sk/i/gRPIMDwaDqt6uw

Config Windows to use WSL2 IPTABLES i/o to network

I would like to use WSL FW instead of Windows, allowing all IPTABLES functions as mangle for all communications to the network. Windows NDIS or firewall will not allow me to set TTL/HOP by app port.

I would like WSL2 stack to selectively replace windows NDIS STACK.

I would like this to be a Windows Control panel easy to choose selection.

NDIS, nor Windows Firewall allow any such capabilities as can be done by Linux without coding software.

I want to be able to have advanced IPTABLES mangle table config without software or 3rd party added software.

Thanks

Terminal doesn't open with the working directory.

Before running the script vscode open the working directory path for each terminal. But now it's always loaded with the following path which seems a little bit annoying for me. How can I get the working path if I new terminal each time in vscode?
image

The fork Distribution can not work !!?

Dear Sir

i install Ubutu 20.04 and then set systemd is ok

but when i use "wsl --export" to export this env

and then i use " wsl --import " to restore (name Ubuntu_fork)

the Ubuntu_fork login is root ??!!

and i lost systemd !!

can help me ?

THX

It breaks sharing environment vars between WSL and Windows

WSL Ubuntu 20.04 LTS, Windows 20H2 (OS Build 19042.1052)

After installation, env variables defined in WSLENV are not present in bash environment.

Before the installation:

mlembke@mlembke:~$ echo $WSLENV
WT_SESSION:WT_PROFILE_ID
mlembke@mlembke:~$ echo $WT_PROFILE_ID
{2c4de342-38b7-51cf-b940-2309a097f518}
mlembke@mlembke:~$ 

After the installation:

mlembke@mlembke:~$ echo $WSLENV
WT_SESSION:BASH_ENV/u:WT_PROFILE_ID
mlembke@mlembke:~$ echo $WT_PROFILE_ID

mlembke@mlembke:~$ 

Any ideas how to fix it?

Systemd starts but services don't

After several tests, I can't find out how to do for systemd starts all the services.

If I start it without entering bash, I've got this:

>wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Stopped         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

>wsl /bin/false
Sleeping for 1 second to let systemd settle

>wsl ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  2 14:36 ?        00:00:00 /lib/systemd/systemd --unit=basic.target
root          46       1  2 14:36 ?        00:00:00 /lib/systemd/systemd-journald
root          63       1  2 14:36 ?        00:00:00 /lib/systemd/systemd-udevd
systemd+      67       1  1 14:36 ?        00:00:00 /lib/systemd/systemd-networkd
root         240       1  0 14:36 ?        00:00:00 snapfuse /var/lib/snapd/snaps/lxd_18150.snap /snap/lxd/18150 -o ro,n
message+     246       1  0 14:36 ?        00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfil
root         247       1  1 14:36 ?        00:00:00 /usr/sbin/NetworkManager --no-daemon
root         255       1  0 14:36 ?        00:00:00 /lib/systemd/systemd-hostnamed
systemd+     266       1  1 14:36 ?        00:00:00 /lib/systemd/systemd-resolved
root         316      63  2 14:36 ?        00:00:00 /lib/systemd/systemd-udevd
root         317      63  2 14:36 ?        00:00:00 /lib/systemd/systemd-udevd
root         318      63  0 14:36 ?        00:00:00 /lib/systemd/systemd-udevd
root         319       0  0 14:36 pts/0    00:00:00 /usr/bin/sudo -H -u [USER] /bin/bash -c set -a; [ -f "$HOME/.system
[USER]      320     319  0 14:36 pts/0    00:00:00 ps -ef

The /bin/false command is for trigger your script to enter the systemd namespace, without doing any else.

In case I enter the shell, I've got this:

>wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Stopped         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

>wsl
Sleeping for 1 second to let systemd settle
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of vie 27 nov 2020 14:37:24 CET

  System load:  0.6                Processes:             39
  Usage of /:   2.6% of 250.98GB   Users logged in:       0
  Memory usage: 6%                 IPv4 address for eth0: 192.168.26.186
  Swap usage:   0%

 * Introducing self-healing high availability clustering for MicroK8s!
   Super simple, hardened and opinionated Kubernetes for production.

     https://microk8s.io/high-availability

0 actualizaciones se pueden instalar inmediatamente.
0 de estas actualizaciones son una actualización de seguridad.


Last login: Fri Nov 27 14:37:06 CET 2020 on pts/0

$ ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  1 14:37 ?        00:00:00 /lib/systemd/systemd --unit=basic.target
root          46       1  0 14:37 ?        00:00:00 /lib/systemd/systemd-journald
root          63       1  0 14:37 ?        00:00:00 /lib/systemd/systemd-udevd
systemd+      70       1  0 14:37 ?        00:00:00 /lib/systemd/systemd-networkd
root         180       0  0 14:37 pts/0    00:00:00 /bin/login -p -f         'HOSTTYPE=x86_64' 'PWD=/mnt/d/apps/System'
root         256       1  0 14:37 ?        00:00:00 snapfuse /var/lib/snapd/snaps/lxd_18150.snap /snap/lxd/18150 -o ro,n
message+     262       1  0 14:37 ?        00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfil
root         263       1  0 14:37 ?        00:00:00 /usr/sbin/NetworkManager --no-daemon
systemd+     283       1  0 14:37 ?        00:00:00 /lib/systemd/systemd-resolved
root         366       1  0 14:37 ?        00:00:00 /lib/systemd/systemd-logind
[USER]      368       1  0 14:37 ?        00:00:00 /lib/systemd/systemd --user
[USER]      369     368  0 14:37 ?        00:00:00 (sd-pam)
[USER]      374     368  0 14:37 ?        00:00:00 /usr/bin/pulseaudio --daemonize=no --log-target=journal
[USER]      376     368  0 14:37 ?        00:00:00 /usr/libexec/tracker-miner-fs
[USER]      377     180  0 14:37 pts/0    00:00:00 -bash
[USER]      385     368  0 14:37 ?        00:00:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfi
rtkit        394       1  0 14:37 ?        00:00:00 /usr/libexec/rtkit-daemon
root         398       1  0 14:37 ?        00:00:00 /usr/lib/policykit-1/polkitd --no-debug
[USER]      406     368  0 14:37 ?        00:00:00 /usr/libexec/gvfsd
[USER]      421     368  0 14:37 ?        00:00:00 /usr/libexec/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
[USER]      427     368  0 14:37 ?        00:00:00 /usr/libexec/gvfs-udisks2-volume-monitor
root         431       1  0 14:37 ?        00:00:00 /usr/lib/udisks2/udisksd
[USER]      456     368  0 14:37 ?        00:00:00 /usr/libexec/gvfs-goa-volume-monitor
[USER]      460     368  0 14:37 ?        00:00:00 /usr/libexec/goa-daemon
[USER]      467     368  0 14:37 ?        00:00:00 /usr/libexec/goa-identity-service
[USER]      473     368  0 14:37 ?        00:00:00 /usr/libexec/gvfs-afc-volume-monitor
[USER]      478     368  0 14:37 ?        00:00:00 /usr/libexec/gvfs-mtp-volume-monitor
[USER]      482     368  0 14:37 ?        00:00:00 /usr/libexec/gvfs-gphoto2-volume-monitor
root         487       1  0 14:37 ?        00:00:00 /usr/lib/upower/upowerd
[USER]      513     377  0 14:37 pts/0    00:00:00 ps -ef

In any case I can start the services manually, but not all of them. For example:

>wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Stopped         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

>wsl /bin/false
Sleeping for 1 second to let systemd settle

>wsl ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  1 14:41 ?        00:00:00 /lib/systemd/systemd --unit=basic.target
root          46       1  1 14:41 ?        00:00:00 /lib/systemd/systemd-journald
root          63       1  1 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
systemd+      70       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-networkd
root         242       1  0 14:41 ?        00:00:00 snapfuse /var/lib/snapd/snaps/lxd_18150.snap /snap/lxd/18150 -o ro,n
message+     248       1  0 14:41 ?        00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfil
root         249       1  0 14:41 ?        00:00:00 /usr/sbin/NetworkManager --no-daemon
root         254       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-hostnamed
root         258       1  0 14:41 ?        00:00:00 /usr/lib/NetworkManager/nm-dispatcher
systemd+     269       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-resolved
root         322      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         323      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         324      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         325      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         327      63  1 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         330       0  0 14:41 pts/0    00:00:00 /usr/bin/sudo -H -u [USER] /bin/bash -c set -a; [ -f "$HOME/.system
[USER]      331     330  0 14:41 pts/0    00:00:00 ps -ef

>wsl sudo systemctl start cron.service
[sudo] password for [USER]:

>wsl ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 14:41 ?        00:00:00 /lib/systemd/systemd --unit=basic.target
root          46       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-journald
root          63       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
systemd+      70       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-networkd
root         242       1  0 14:41 ?        00:00:00 snapfuse /var/lib/snapd/snaps/lxd_18150.snap /snap/lxd/18150 -o ro,n
message+     248       1  0 14:41 ?        00:00:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfil
root         249       1  0 14:41 ?        00:00:00 /usr/sbin/NetworkManager --no-daemon
systemd+     269       1  0 14:41 ?        00:00:00 /lib/systemd/systemd-resolved
root         339      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         340      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         341      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         342      63  0 14:41 ?        00:00:00 /lib/systemd/systemd-udevd
root         347       1  0 14:41 ?        00:00:00 /usr/sbin/cron -f
root         348       0  0 14:42 pts/0    00:00:00 /usr/bin/sudo -H -u [USER] /bin/bash -c set -a; [ -f "$HOME/.system
[USER]      349     348  0 14:42 pts/0    00:00:00 ps -ef

Any idea how to do for starting all the missing services?

help: can't start wsl after following instructions

I couldn't get snap to run, so I tried the instructions (link)
I made sure to execute:

sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig

but after completing the instructions, I can't start wsl, and I get the following error:

/usr/sbin/enter-systemd-namespace: line 10: /usr/sbin/daemonize: No such file or directory

I can't enter wsl, to fix or delete this change
please help

update: using wsl --exec cmd I was able to start undoing the damage

/etc/resolv.conf is regenerated with an invalid config

I've installed Ubuntu 20.04 via rootfs as indicated on the ubuntu website

I've installed the script, but /etc/resolv.conf is rewritten with an invalid DNS configuration

before the call to /usr/sbin/enter-systemd-namespace

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.28.144.1

After:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0

It seems to happen during the call to "nsenter"

Is there a way to get around this issue?

/proc/30/ns/time is missing

The wsl cannot be started due to this error after running the script

nsenter: cannot open /proc/30/ns/time: No such file or directory

After executing: vscode doesn't start in project path.

After executing this script, when starting a project in vscode via wsl in the terminal, it opens the path 'mnt/c/Program Files/vscode instead of project root directory. I'm using ubuntu 20.04

CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

vscode is using the wrong directory in default terminal.

When you open a terminal inside vscode within WSL2 it is defaulting to /mnt/c/Users/username/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.3 not the folder you open it in.
I understand that its getting it from the ~/.system-env file and we are setting the env with this command cmd.exe /C setx WSLENV BASH_ENV/u

More than happy to work on a PR to help fix the issue. I am not 100% sure what this command cmd.exe /C setx WSLENV BASH_ENV/u is setting

Dealing with error: nsenter: failed to parse pid

Weirdest thing ever,

Sometimes, I get this error when trying to run WSL:

nsenter: failed to parse pid: '48
49'

It is defiantly something related to that package (systemd) since it never happened before I install it.
Now the way to solve it is to open PowerShell and run wsl --shutdown and then it loads OK.

The weird part is that I'm trying to run it from a bat script and shutdown the WSL every time I run the script using

powershell -Command "& {wsl --shutdown}"
timeout /t 5

or this:

:wsl_stop
for /F "tokens=3 delims=: " %%H in ('sc query "Lxssmanager" ^| findstr "        STATE"') do (
  if /I "%%H" NEQ "STOPPED"  (
   wsl --terminate %DISTRIBUTION%
   timeout /t 1
   sc stop "Lxssmanager"
   goto wsl_stop
  )
)

But the wsl still wont come up, only when I run then wsl --shutdown command manually on PowerShell.

Any thoughts or a way around it?

NOT WORKING!!! BUT WORKED :)

Script run OK. Restarted.
Call systemctl:

blk-availability.service loaded active exited Availability of block devices
dbus.service loaded active running D-Bus System Message Bus
keyboard-setup.service loaded active exited Set the console keyboard layout
polkit.service loaded active running Authorization Manager
rtkit-daemon.service loaded active running RealtimeKit Scheduling Policy Service
setvtrgb.service loaded active exited Set console scheme
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-modules-load.service loaded failed failed Load Kernel Modules
systemd-networkd-wait-online.service loaded active exited Wait for Network to be Configured
systemd-networkd.service loaded active running Network Service
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
[email protected] loaded active running User Manager for UID 1000

But I am able to install microk8s :) Weird !

Any hint ?
Steve

snap gets broken after first run

Snap is having a weird behavior. It works well the 1st time you run ubuntu-wsl2-systemd-script, but after reboot the distro it gets broken.

Steps to reproduce:

  • Install a brand new distribution of Ubuntu 20.04 (I'm doing it manually, outside the Store)
  • Install ubuntu-wsl2-systemd-script
  • Reboot the distribution
  • Login into WSL
  • Install a snap package
  • IT WORKS!
  • Logout WSL
  • Reboot the distribution
  • Login into WSL
  • Install a snap package
  • Snap is BROKEN!

The error is

$ sudo snap install inkscape
error: cannot perform the following tasks:
- Run configure hook of "inkscape" snap if present (run hook "configure": cannot perform operation: mount --rbind /dev /tmp/snap.rootfs_7dlI1W//dev: No such file or directory)

All the steps described before are done without restart the Windows session.

You can delete de distribution and reinstall it, with the same result?

Any idea how to solve it?

Endless startup loop

Running this made ubuntu endlessly loop with echo pausing one second to let ubuntu start.

Docker WSL2 not accessible from within WSL2 Ubuntu-20.04

I've run the script and snapworks, but docker does not. I'm running WSL 2 with Ubuntu 20.04 and I'm using Windows terminal.

When I do docker ps, I get the error docker command not found

Although, when I open VSCode Remote-Extension and type docker ps in the VSCode terminal, Docker works there.

Inspecting ps -ef on both, VSCode and Terminal, gives me:

VSCode: root 1 0 0 13:16 ? 00:00:00 /init
Terminal: root 1 0 0 13:16 ? 00:00:00 /lib/systemd/systemd --system-unit=basic.target

Both env-variables are set

cmd.exe /C setx WSLENV BASH_ENV/u
cmd.exe /C setx BASH_ENV /etc/bash.bashrc

Is this scenario even supposed to work with systemd enabled?

Cheers,

Unable to launch WSL 2 after running script.

After running the script in my WSL 2 Pengwin distro, I can no longer open a terminal. The terminal window flashes a brief message "Cannot execute daemonize to start systemd" and immediately closes.

I can mount and navigate the vhdx, but am not clear exactly what to modify to revert the changes made by the script.

I'm assuming reverting the changes to /etc/bash.bashrc and removing usr/sbin/start-systemd-namespace
and /usr/sbin/enter-systemd-namespace would be the place to start.

Thanks.

Too many levels of symbolic links when running ls -l /proc/sys/fs/binfmt_misc

After running bash ubuntu-wsl2-systemd-script.sh and wsl.exe -t ${DISTRIBUTION_NAME} and reopen a terminal for WSL2 VM, I get the following error when I run ls -l /proc/sys/fs/binfmt_misc.

$ ls -l /proc/sys/fs/binfmt_misc
ls: cannot open directory '/proc/sys/fs/binfmt_misc': Too many levels of symbolic links

It would be nice to fix this problem.

nsenter: cannot open /proc/25/ns/time: No such file or directory

i'm trying to install the qemu in my windows and i got this error message

after WSL installed and configured

i've install the Ubuntu-22.04

run it int terminal...

and do this steps:

apt-get update

sudo apt install qemu qemu-kvm libvirt-cliebts libvirt-daemon-system bridge-utils virt-manager

sudo apt install x11-apps

and after doing this steps:

https://www.youtube.com/watch?v=oILBqhnyCPA

and trying to star the dist Ubuntu-22.04 in the prompt:

wsl -d Ubuntu-22.04

i'm getting this:

nsenter: cannot open /proc/320/ns/time: No such file or directory

please somebody can help?

"Sleeping for 1 second to let systemd settle"

Getting the following after installing :-

C:\Users\aaron>wsl
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
Sleeping for 1 second to let systemd settle
...

Linux binds aren't seen in Windows/Docker

Hi,

After installing this script bind mounts aren't visible in windows and docker/kubernetes anymore.

sudo mkdir /mnt/wsl/somedir
sudo mount --bind /some/folder/withfiles/ /mnt/wsl/somedir
ls /mnt/wsl/somedir
<shows files>

Windows explorer: \\wsl$\<distro>\mnt\wsl\somedir
<no files shown>

In bash.bashrc comment out:

# Start or enter a PID namespace in WSL2
#source /usr/sbin/start-systemd-namespace <-- this line

Restart WSL:

powershell: wsl --shutdown

Repeat these steps:

sudo mkdir /mnt/wsl/somedir
sudo mount --bind /some/folder/withfiles/ /mnt/wsl/somedir
ls /mnt/wsl/somedir
<shows files>

Windows explorer: \\wsl$\<distro>\mnt\wsl\somedir
<shows files> <-- this now works

Any ideas?

Update zshrc if it exists

It'd be nice if the script would also source /usr/sbin/start-systemd-namespace in .zshrc (or /etc/zsh/zshrc to match the existing use of bash.bashrc).

Right now, the behavior in zsh is very misleading:

~  λ snap list
error: access denied (try with sudo)
~  λ sudo snap list
error: access denied (see 'snap help login')

wslg is broken with script

Hi,
I had the same problem like described in microsoft/wslg#238

xclock Error: Can't open display: :0

and the only solution for me was microsoft/wslg#238 (comment)

export DISPLAY=:0 sudo rm -rf /tmp/.X11-unix ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix

Then it works. Is this really related to your script ?

thanks for your feedback.

Miro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.