All Projects → sorah → subsystemctl

sorah / subsystemctl

Licence: MIT license
Utility to run systemd in WSL2 with a Linux namespace

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to subsystemctl

dotfiles
Cross platform home directory settings
Stars: ✭ 17 (-94.57%)
Mutual labels:  wsl, wsl2
proton wsl2
Proton Kernel for the Windows Subsystem for Linux 2 (WSL 2). Highly experimental and always at the mercy of Windows Update.
Stars: ✭ 23 (-92.65%)
Mutual labels:  wsl, wsl2
runx
Provide X server on MS Windows with cookie authentication.
Stars: ✭ 67 (-78.59%)
Mutual labels:  wsl, wsl2
WSLackware
Slackware for WSL!
Stars: ✭ 38 (-87.86%)
Mutual labels:  wsl, wsl2
nvim-ghost.nvim
👻 GhostText plugin for Neovim with zero dependencies 🎉 Supports neovim running inside WSL too! 🥳 Windows/Linux/macOS supported out-of-the-box! 😄 (Other OSes need python3.6+ installed)
Stars: ✭ 32 (-89.78%)
Mutual labels:  wsl, wsl2
dotfiles
Dotbot managed dotfiles for a polyglot dev using WSL. Includes PowerShell stuff for Windows Installation
Stars: ✭ 14 (-95.53%)
Mutual labels:  wsl, wsl2
webi-installers
Primary and community-submitted packages for webinstall.dev
Stars: ✭ 421 (+34.5%)
Mutual labels:  wsl, wsl2
usbipd-win
Windows software for sharing locally connected USB devices to other machines, including Hyper-V guests and WSL 2.
Stars: ✭ 1,321 (+322.04%)
Mutual labels:  wsl, wsl2
wsl-systemd
A script that spawns a namespace with systemd as PID1, and allows you to spawn interactive sessions or exec commands inside it
Stars: ✭ 37 (-88.18%)
Mutual labels:  systemd, wsl2
WSL-Context-Menu-Manager
Manages the context menu for your Linux tools in WSL/WSL2 for Windows.
Stars: ✭ 25 (-92.01%)
Mutual labels:  wsl, wsl2
nix-config
NixOS configuration (also on WSL)
Stars: ✭ 51 (-83.71%)
Mutual labels:  wsl, wsl2
convey
Communication through a serial port or named pipe
Stars: ✭ 46 (-85.3%)
Mutual labels:  wsl, wsl2
one-script-wsl2-systemd
The one-script variant of the systemd hack for WSL2
Stars: ✭ 196 (-37.38%)
Mutual labels:  systemd, wsl2
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.
Stars: ✭ 1,637 (+423%)
Mutual labels:  wsl, wsl2
dotfiles
My dotfiles for Mac / Linux boxes and WSL
Stars: ✭ 35 (-88.82%)
Mutual labels:  wsl2
wsl-firststep
WSL을 설치하면서 처음에 하는 일들을 모아놓은 리포지터리입니다.
Stars: ✭ 47 (-84.98%)
Mutual labels:  wsl
VoidMuslWSL
Install Void Linux (with musl-libc) as a WSL Instance (for Windows 10 1803 64bit or later)
Stars: ✭ 30 (-90.42%)
Mutual labels:  wsl
sysdweb
Control systemd services through Web or REST API
Stars: ✭ 65 (-79.23%)
Mutual labels:  systemd
WSL2setup
Install WSL2 and handle dependencies
Stars: ✭ 55 (-82.43%)
Mutual labels:  wsl2
lua-systemd
Systemd bindings for Lua
Stars: ✭ 33 (-89.46%)
Mutual labels:  systemd

subsystemd: Run systemd in WSL2

Maintanence Note: You may want to use nullpo-head/wsl-distrod which provides better compatibility with systemd and easier installation, and well maintained.

Run systemd under Linux namespace in WSL2. Heavily inspired by arkane-systems/genie, but written in Rust.

Difference with arkane-systems/genie

Slightly following genie'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 use nss-myhostname.
    • Uses machinectl shell to launch a user shell; this allows running systemd user session
  • Internal
    • Removed dependency to unshare, daemonize, nsenter command line tools
    • systemd-wide environment variables are set via systemd.conf drop-in, using DefaultEnvironment=
    • systemd PID from root namespace is stored at /run/subsystemctl/systemd.pid

Install

Arch Linux

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 as they unwelcomes WSL-exclusive packages.)

Debian/Ubuntu

Refer to https://github.com/nkmideb/subsystemctl for debian source.

Pre-built package binaries available at https://github.com/nkmideb/subsystemctl/releases for your convenient.

Self build

cargo install subsystemctl

or from git source:

cargo build --release
install -m6755 -oroot -groot ./target/release/subsystemctl /usr/local/bin/subsystemctl

Usage

subsystemctl start: Start systemd environment

PS> wsl -u root -- subsystemctl start

subsystemctl shell: shell login to systemd-enabled environment

PS> wsl subsystemctl shell
Connected to the local host. Press ^] three times within 1s to exit session.
someone@hostname$ ...

Specifying uid to login

PS> wsl -u root -- subsystemctl shell --uid=1000
Connected to the local host. Press ^] three times within 1s to exit session.
someone@hostname$ ...

Automatically starting and entering a user shell

PS> wsl -u root -d Arch -- subsystemctl shell --uid=1000 --start
[2021-06-27T16:32:20Z INFO  subsystemctl] Starting systemd
Connected to the local host. Press ^] three times within 1s to exit session.

someone@hostname$ ...

subsystemctl exec: Raw nsenter like interface

PS> wsl subsystemctl exec id
uid=1000(sorah) gid=1000(sorah) groups=1000(sorah),116(admin)

Specifying uid (and gid)

PS> wsl -u root -- subsystemctl exec id
uid=0(root) gid=0(root) groups=0(root)

PS> wsl -u root -- subsystemctl exec --uid=1000 id
uid=1000(sorah) gid=1000(sorah) groups=1000(sorah),116(admin)

PS> wsl -u root -- subsystemctl exec --uid=1000 --gid=116 id
uid=1000(sorah) gid=116(admin) groups=116(admin)

subsystemctl is-running

#!/bin/bash
if subsystemctl is-running; then
  echo "running"
else
  echo "not-running"
fi

subsystemctl is-inside

#!/bin/bash
if subsystemctl is-inside; then
  echo "inside"
else
  echo "outside"
fi

Tips

systemd-resolved, networkd are recommended to be disabled

otherwise /etc/resolv.conf might get overwritten to resolved stub-resolver.

Author

Sorah Fukumori https://sorah.jp/

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].