-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distrod doesn't run user.slice? #13
Comments
Yes, that's right. It is how Distrod runs today. I've been putting off implementing user slice because I didn't think there were that many use cases for it in WSL, where everyone has root. As a workaround, if you run |
+1 |
Thanks, looking forward to it. Once distrod automatically starts user slice, does this mean that if I run wsl:vlc from the windows Start Menu that an sftp network link will work? |
I'm not exactly sure what you want to do because I'm not familiar with |
I was just using wsl:vlc as a short cut to saying "run vlc from wsl from the start menu". Sorry, it must have been confusing! |
To just trigger user systemd services, do it once per boot of WSL instance. |
Thanks a lot, really appreciate it |
I'm not familiar with systemd internals, but is it possible that when distrod is creating the "bottle", it also runs |
@nullpo-head How can we add So long story short, I was doing a deep dive on how these systemd stuffs work and how to enable systemd user session. Geine uses this command https://github.com/systemd/systemd/blob/main/src/machine/machine-dbus.c#L732 The important property here is So In a distrod configued wsl distro, I can execute the following commands to get a shell with systemd user session. # from powershell start wsl to root user
wsl -d UbuntuMain --user root
# now in ubuntu, inside systemd thanks to distrod
systemd-run --pty --service-type=simple --uid=gittu -p PAMName=login /bin/bash
# now in user session. Can run the followings succesfully
env | grep XDG
systemctl --user status So can this be added to distrod? I don't know rust but looking at the code of distrod and geine, while geine executes commands like "machinectl daemonize unshare systemd" to do its job, distrod seems to be doing these programatically by api call? Is it a builtin or a rust library to interface with linux systemd / namespace etc... ? Maybe there is a option to add Or you can maybe simply append Update: I've created a small hack in go to run in user session: https://github.com/sarim/gbash |
create a
next edit #!/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
# replace `archlinux` with your username
su - archlinux -p -c "sudo -S login -f archlinux"
fi
|
I found that enabling user-linger means that the user-session gets launched automatically when WSL boots:
|
That might break systemd, not sure |
I don't think it will break systemd. Enabling linger means that the systemd user instance is started right after boot, and kept running after the last session closes. This basically means that my user's It's not how I'd do things on a desktop linux install, but for my use-case with WSL it suits me. |
this works for ubuntu kenetic wsl2 windows 11 my original one fails, idk why
|
combined with this, it works for windows 11 ubuntu kinetic
create a
next create a if [ "$(id -u)" == 0 ]; then
# put your user name here
SYSTEMD_ROOT_LOGIN_NAME_DISTROD=USER
# start distrod if it has not already been started
/opt/distrod/bin/distrod start
# wait for systemd to start, systemd is started by distrod
while [ ! -e /var/run/dbus/system_bus_socket ];
do
echo "waiting for systemd to start..."
sleep 1
done
# fix DISPLAY for wslg on windows 11
export DISPLAY="$(grep nameserver /etc/resolv.conf | sed 's/nameserver //'):0"
rm -r /tmp/.X11-unix
ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix
# login to our user shell, we have no easy way to inherit our parent environment so we must manually specify it
# use -l to preserve our path, attempting to declare our path manually will fail
systemd-run --pty --service-type=simple --uid=$SYSTEMD_ROOT_LOGIN_NAME_DISTROD -p PAMName=login --same-dir -E DISPLAY="$DISPLAY" -E WAYLAND_DISPLAY="$WAYLAND_DISPLAY" -E PULSE_SERVER="$PULSE_SERVER" -E WT_PROFILE_ID="$WT_PROFILE_ID" -E WT_SESSION="$WT_SESSION" -E WSLENV="$WSLENV" -E HOSTTYPE="$HOSTTYPE" -E LS_COLORS="$LS_COLORS" -E WSL_INTEROP="$WSL_INTEROP" -E WSL_DISTRO_NAME="$WSL_DISTRO_NAME" -E NAME="$NAME" -E WSL2_GUI_APPS_ENABLED="WSL2_GUI_APPS_ENABLED" /bin/bash -l
# systemd-run above will execute a bash shell, automatically dropping us into our user shell, blocking here
# we never enter the root unless `$ su` or `$ sudo -i` is used from the user shell
# the following command runs after the user has exited the bash shell
# by exiting here, we exit the root shell that wsl starts to drop us into our user shell
# this avoids us having to exit twice when we only entered once:
# PS C:\Users\small> wsl
# Waiting for system socket
# Waiting for system socket
# Running as unit: run-u8.service
# Press ^] three times within 1s to disconnect TTY.
# user@LAPTOP-5PKRTSDE:/$ exit
# exit
# root@LAPTOP-5PKRTSDE:/mnt/c/Users/small# exit
# logout
# PS C:\Users\small>
exit
fi unfortunately this breaks su a workaround is
|
You are right, enable-linger for the user breaks the user's systemd, at least on my machine. You saved my time. |
After installing distrod, systemctl status only showed init.scope and system.slice running - there is no user.slice (and user-1000.slice, etc). Have I done something wrong? Or if not, there is a way perhaps to configure it to run the user systemd units? I was hoping to get gvfs-daemon running to allow nautilus to connect to sftp:// locations.
I installed distrod as per the instructions to add it to my existing distro, ie I downloaded and ran install.sh with the install argument and then ran "/opt/distrod/bin/distrod enable" (both as sudo, as the commands complain if not run as sudo). I then terminated wsl with "wsl --shutdown" (note that "wsl --terminate Distrod" as per the instructions didn't work, since I had only added distrod to my existing distro, so Distrod did not exist) and re-ran wsl.
The text was updated successfully, but these errors were encountered: