- Notifications
You must be signed in to change notification settings - Fork15
Utility to run systemd in WSL2 with a Linux namespace
License
sorah/subsystemctl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Maintanence Note: You may want to usenullpo-head/wsl-distrod which provides better compatibility with systemd and easier installation, and well maintained.
Run systemd under Linux namespace in WSL2. Heavily inspired byarkane-systems/genie, but written in Rust.
Slightly followinggenie's behavior, but noted below...
- Interface
- Command line interface is not compatible.
- Behavior
- Hostname altertion is optional with
--hostname
,--hostname-suffix
/etc/hosts
are not updated. Users are encouraged to usenss-myhostname
.
- Uses
machinectl shell
to launch a user shell; this allows running systemd user session
- Hostname altertion is optional with
- Internal
- Removed dependency to
unshare
,daemonize
,nsenter
command line tools - systemd-wide environment variables are set via
systemd.conf
drop-in, usingDefaultEnvironment=
- systemd PID from root namespace is stored at
/run/subsystemctl/systemd.pid
- Removed dependency to
PKGBUILD:https://github.com/sorah/arch.sorah.jp/tree/master/aur-sorah/PKGBUILDs/subsystemctl
(PKGBUILD originally submitted to AUR (https://aur.archlinux.org/packages/subsystemctl) was deleted asthey unwelcomes WSL-exclusive packages.)
Refer tohttps://github.com/nkmideb/subsystemctl for debian source.
Pre-built package binaries available athttps://github.com/nkmideb/subsystemctl/releases for your convenient.
cargo install subsystemctl
or from git source:
cargo build --releaseinstall -m6755 -oroot -groot ./target/release/subsystemctl /usr/local/bin/subsystemctl
PS> wsl-u root-- subsystemctl start
PS> wsl subsystemctl shellConnected to the local host. Press ^] three times within 1s toexit session.someone@hostname$ ...
PS> wsl-u root-- subsystemctl shell--uid=1000Connected to the local host. Press ^] three times within 1s toexit session.someone@hostname$ ...
PS> wsl-u root-d Arch-- subsystemctl shell--uid=1000--start[2021-06-27T16:32:20ZINFOsubsystemctl] Starting systemdConnected to the local host. Press ^] three times within 1s toexit session.someone@hostname$ ...
PS> wsl subsystemctl exec iduid=1000(sorah) gid=1000(sorah) groups=1000(sorah),116(admin)
PS> wsl-u root-- subsystemctl exec iduid=0(root) gid=0(root) groups=0(root)PS> wsl-u root-- subsystemctl exec--uid=1000 iduid=1000(sorah) gid=1000(sorah) groups=1000(sorah),116(admin)PS> wsl-u root-- subsystemctl exec--uid=1000--gid=116 iduid=1000(sorah) gid=116(admin) groups=116(admin)
#!/bin/bashif subsystemctl is-running;thenecho"running"elseecho"not-running"fi
#!/bin/bashif subsystemctl is-inside;thenecho"inside"elseecho"outside"fi
otherwise/etc/resolv.conf
might get overwritten to resolved stub-resolver.
Sorah Fukumorihttps://sorah.jp/
MIT
About
Utility to run systemd in WSL2 with a Linux namespace