Repository navigation
Description
Windows Version
Microsoft Windows [Version 10.0.19045.3208]
WSL Version
1.3.14.0
Are you using WSL 1 or WSL 2?
- WSL 2
- WSL 1
Kernel Version
Linux 5.15.90.3-microsoft-standard-WSL2
Distro Version
Debian 12
Other Software
No response
Repro Steps
- Fresh install of WSL
- Set WSL to version 2
- Install Debian from Microsoft Store
- Clicked 'Open' from Debian Store page and installed/configured login/password
- Closed Debian window
- Opened Terminal (previously installed)
- From Terminal, opened a tab to the Debian instance
- Added file to Debian instance: sudo nano /etc/wsl.conf with:
[boot] systemd=true(two separate lines)
Saved file, exited nano - Closed Debian tab
- In the Terminal tab, I ran
wslconfig /t Debianto kill Debian instance. - Ran
wsl --shutdownto shut down WSL - Closed Terminal
- Opened Terminal again and added Debian as the second tab.
- In Debian I ran
systemctl list-units --type=serviceand received error message,Failed to connect to bus: No such file or directory. - Checked wsl.conf in Debian as correct. Checked wsl and Debian for any other issues, none found.
This error can be replicated faithfully.
Expected Behavior
Running systemctl list-units --type=service should return the list of services loaded or not and active or not.
I tried modifying wsl.conf with additional entries of [automount], [interop], and [network]. Then killed the Debian instance, shut down WSL. Yes, I even physically turned the PC off and on. But systemd appears not to be running.
Actual Behavior
Instead of getting a list of services, I get the error message, failed to connect to bus: no such file or directory. I can work inside the instance like normal except no services are running. When I try to run a script or process, I get the System has not been booted with systemd as init system (PID 1) error.
POSSIBLE FIX
HOWEVER - Scouring the web, I did find this tidbit from github user, alyleite about running systemd earlier in the boot process?
After deleting everything and starting fresh again. I added these two commands after Step 8 and before Step 9 in the Repro Steps above. I kept wsl.conf to just the [boot] section.
First command in the Debian tab of Terminal:
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig
This added and updated files in the Debian instance and completed successfully.
Second command, same tab:
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
It completed successfully without any other messages. I tried to run exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME but my Debian instance did not know nsenter, I continue with steps 9-14 but this time systemctl returns the proper response. Even after I restart my PC, the Debian instance behaves normally.
Diagnostic Logs
Running a log after it appears to be working will not add anything, I believe.
AFAIK (or see) the commands do two things. First command updates dbus-user-session and daemonize. Second command then basically restructures systemd to start earlier in the boot-up process? (Sorry, Linux is like a second language to me right now. So I am guessing at this point.)
But it does work. And I can repeat it on at least my machine.
Activity
elsaco commentedon Jul 30, 2023
AKA "Thom Wiley' (@The-Monkey-King) install
dbusanddbus-user-sessionpackages. For some reason (unknown to me) this packages are not part of the Debian distro pulled from the store.From
apt info systemdoutput:Recommends: default-dbus-system-bus | dbus-system-busmicrosoft-github-policy-service commentedon Aug 1, 2023
Hello! Could you please provide more logs to help us better diagnose your issue?
To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:
The scipt will output the path of the log file once done.
Once completed please upload the output files to this Github issue.
Click here for more info on logging
Thank you!
The-Monkey-King commentedon Aug 8, 2023
Interesting. Just installed Debian. After first running
sudo apt update, I ranapt info systemdand received the following recommends:Recommends: default-dbus-system-bus | dbus-system-bus, systemd-timesyncd | time-daemonI want to see if the suggested path fixes the issue first, but I am concerned that a time sync is not enabled either.
UPDATE: Installing dbus and dbus-user-session recommends I install a time package, too. But I am going ahead with just dbus for now and if it fixes it, I will install the latter after all else.
The-Monkey-King commentedon Aug 8, 2023
The recommend installation of the missing dbus elements worked. I'd rather not close this defect until I can get the Microsoft WSL / Debian team(s) to install dbus and dbus-user-session at first installation -- even if a user does not want/need systemd to be running.
What are my next steps to seeing this gets resolved at base installation?
lorengordon commentedon Nov 29, 2023
After following the rabbit hole down a bunch of other ideas, simply
sudo apt install dbus-user-sessionworked for me also. Exited and shutdown WSL, started a new session, and now/run/user/1000/busexists and apps looking for it (vscode, firefox) are no longer complaining about its absence.karJac commentedon Aug 27, 2024
For me the problem was solved by doing this:
[10569:0827/004757.735915:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/user/1000/bus: No such file or directorycan be fixed by adding these lines to
~/.bashrcThe issue is that when running program, it expects the socket to be located at a fixed path in /run/user/1000/bus, which doesn't work in WSL2 where the socket is instead created as an abstract socket and is found under /tmp