ArchWSL icon indicating copy to clipboard operation
ArchWSL copied to clipboard

Starting Systemd automatically

Open nisarg-ujjainkar opened this issue 4 years ago • 16 comments

Hi,

Is there a way to start thee Systemd automatically while booting WSL2? Both subsystemctl and genie require users to execute them manually after boot. Is there a way to start them automatically without calling the commands through .zshrc/.bashrc?

Also, What happened to ArchWSL2? I taught it was pretty stable.

nisarg-ujjainkar avatar Nov 23 '20 12:11 nisarg-ujjainkar

ArchWSL2 has been discontinued due to a bug found that is difficult to fix. I'm currently researching if we can do the same thing using other methods. Microsoft's init is a difficult road because it's proprietary.

yuk7 avatar Nov 24 '20 10:11 yuk7

I used to aim to work with all shells and programs. However, it will be easier to some extent if it works only with a specific shell such as bash or zsh.

yuk7 avatar Nov 24 '20 10:11 yuk7

Could you tell me what the bug is? I have been using it for a couple of months now, and it has a lot of things. Do I need to migrate to AwchWSL?

nisarg-ujjainkar avatar Nov 24 '20 13:11 nisarg-ujjainkar

The most serious bug is a mounting bug that causes the file update to fail. If possible, I think it is better to migrate to ArchWSL.

(However, I'm still using ArchWSL2 personally and haven't completely migrated.)

yuk7 avatar Nov 24 '20 13:11 yuk7

Ok, can I use these scripts to start systemd at boot? https://github.com/yuk7/container-systemd-init-tool

nisarg-ujjainkar avatar Nov 24 '20 16:11 nisarg-ujjainkar

It can't be used. It is buggy. Also, it's not intended for manual use.

yuk7 avatar Nov 24 '20 16:11 yuk7

ok, thanks.

nisarg-ujjainkar avatar Nov 24 '20 16:11 nisarg-ujjainkar

FYI, I use genie-systemd to launch systemd. I haven't encountered any major problems so far, and I'm using it comfortably.

My custom PKGBUILD file is here.

gifnksm avatar Feb 08 '21 03:02 gifnksm

FYI, I use genie-systemd to launch systemd. I haven't encountered any major problems so far, and I'm using it comfortably.

My custom PKGBUILD file is here.

Can I execute windows commands like code or explorer.exe when inside systemd environment?

nisarg-ujjainkar avatar Feb 09 '21 15:02 nisarg-ujjainkar

Can I run Windows commands such as code and explorer.exe in a systemd environment?

Yes, you can launch explorer by executing /mnt/c/Windows/explorer.exe.

Since genie removes Windows paths from PATH environment variable by default, you must specify a full path starting with /mnt/<drive letter>/ to execute programs in Windows paths. This behavior can be changed by setting clone-path=true in /etc/genie.ini. See genie README for details.

gifnksm avatar Feb 10 '21 00:02 gifnksm

Use something like wsl -d Arch --cd ~ -- genie -s

PhyX-Meow avatar Oct 05 '21 05:10 PhyX-Meow

Maybe this one is what you want Launch systemd-enabled shell directly from start menu https://github.com/lungothrin/bottled-shell

lungothrin avatar Nov 28 '21 15:11 lungothrin

There is also this wsl-distrod. It automatically starts systems when wsl boots. So far, I have not encountered any problems which I encountered with genie or other such tools.

nisarg-ujjainkar avatar Nov 28 '21 16:11 nisarg-ujjainkar

I stop using wsl-distrod as it failed to start user.slice in Arch Linux. but anyway good to know

lungothrin avatar Nov 28 '21 16:11 lungothrin

If you use Ubuntu, it seems to be fixed, maybe the developer can use this: https://bugs.launchpad.net/ubuntu/+source/wsl-setup/+bug/1962556

kevincrans avatar Apr 22 '22 11:04 kevincrans

You can also start systemd automatically through Windows Task Scheduler.

First of all, install a systemctl bottle. My setup is based on subsystemctl.

Simply press "Create basic task" and follow the wizard. For trigger I use "When I log on" and the action is wsl with arguments -u root -- <path to subsystemctl> start. For me, <path to subsystemctl> is /home/sigurd/.cargo/bin/subsystemctl, since I installed subsystemctl with cargo as my own user (sigurd).

If you have a laptop, I also highly recommend to disable "Start the task only if the computer is on AC power" under "Conditions". This option is not in the wizard, and has to be done by modifying the task properties afterwards.

sigurdo avatar Jun 26 '22 14:06 sigurdo

Systemd support is now available in WSL! https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

@yuk7 You can mark this as resolved now

rollingmoai avatar Sep 22 '22 00:09 rollingmoai

The docs should probably be also updated

rollingmoai avatar Sep 22 '22 01:09 rollingmoai