nullpo-head / 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.
MIT License
1.9k stars 91 forks source link

How to change default shell #7

Closed derphilipp closed 2 years ago

derphilipp commented 2 years ago

Is it safe to use a different shell with a user? As the default shell is set to /opt/distrod/alias/usr/bin/bash and I'd like to use fish as the shell for my default user.

Is it changing it to /usr/bin/fish okay, or will this break any distrod functionality?

nullpo-head commented 2 years ago

Yes, it's safe to use a different shell of course! but you have to enable distrod again to hook the default shell. chsh command may show that instruction as well (or may not, which depends on your environment)

So, when you want to change your default shell, run distrod enable as follows

$ chsh
[Distrod] Run 'sudo /opt/distrod/bin/distrod enable' after this command succeeds.
[Distrod] It's necessary for Systemd to work as the pseudo init process.
Password:
Changing the login shell for nullpo
Enter the new value, or press ENTER for the default
        Login Shell [/opt/distrod/alias/bin/bash]: /usr/bin/fish
$ sudo /opt/distrod/bin/distrod enable
[Distrod] Distrod has been enabled. Now your shell will start under systemd.
derphilipp commented 2 years ago

Perfect - thank you very much! And thanks for all your work on the project.

yueyejinghun commented 2 years ago

Thank you for this amazing project And sorry for reopening a closed issue I tried this with zsh today, but no luck. I'm on Windows 10 21H1, Ubuntu Focal installed with wsl-distrod, updated the system and only installed zsh and fish for testing, nothing else. Logged in with a normal user with sudo privilege

After $ chsh -s /bin/zsh

I ran $ sudo /opt/distrod/bin/distrod enable

and it returned [Distrod] Distrod has been enabled. Now your shell will start under systemd.

Terminating wsl for test wsl --shutdown

Then reopening Ubuntu, run $ sudo systemctl status

but it just threw the common error message System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

Fish's working fine though

nullpo-head commented 2 years ago

Hmm.. It's strange that fish works but zsh doesn't. Could you share the result of cat /etc/passwd, please?

yueyejinghun commented 2 years ago

Of course, thanks for replying.

Here's the content of /etc/passwd

It changed to /opt/distrod/alias/bin/zsh after I ran chsh -s /bin/zsh


daemon:x:1:1:daemon:/usr/sbin:/opt/distrod/alias/usr/sbin/nologin
bin:x:2:2:bin:/bin:/opt/distrod/alias/usr/sbin/nologin
sys:x:3:3:sys:/dev:/opt/distrod/alias/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/opt/distrod/alias/bin/sync
games:x:5:60:games:/usr/games:/opt/distrod/alias/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/opt/distrod/alias/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/opt/distrod/alias/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/opt/distrod/alias/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/opt/distrod/alias/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/opt/distrod/alias/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/opt/distrod/alias/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/opt/distrod/alias/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/opt/distrod/alias/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/opt/distrod/alias/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/opt/distrod/alias/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/opt/distrod/alias/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/opt/distrod/alias/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/opt/distrod/alias/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/opt/distrod/alias/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/opt/distrod/alias/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/opt/distrod/alias/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/opt/distrod/alias/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/opt/distrod/alias/usr/sbin/nologin
ubuntu:x:1000:1000::/home/ubuntu:/opt/distrod/alias/bin/bash
yyjh:x:1001:1001::/home/yyjh:/opt/distrod/alias/usr/bin/fish
systemd-coredump:x:999:999:systemd Core Dumper:/:/opt/distrod/alias/usr/sbin/nologin
nullpo-head commented 2 years ago

Thanks a lot! but it looks you set your default shell to fish now. Could you share the contents after changing the default shell to zsh and run sudo /opt/distrod/bin/distrod enable again?

yueyejinghun commented 2 years ago

Shouldn't have edited my last post, which made even more mistakes:)

Here it is


root:x:0:0:root:/root:/opt/distrod/alias/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/opt/distrod/alias/usr/sbin/nologin
bin:x:2:2:bin:/bin:/opt/distrod/alias/usr/sbin/nologin
sys:x:3:3:sys:/dev:/opt/distrod/alias/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/opt/distrod/alias/bin/sync
games:x:5:60:games:/usr/games:/opt/distrod/alias/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/opt/distrod/alias/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/opt/distrod/alias/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/opt/distrod/alias/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/opt/distrod/alias/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/opt/distrod/alias/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/opt/distrod/alias/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/opt/distrod/alias/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/opt/distrod/alias/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/opt/distrod/alias/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/opt/distrod/alias/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/opt/distrod/alias/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/opt/distrod/alias/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/opt/distrod/alias/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/opt/distrod/alias/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/opt/distrod/alias/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/opt/distrod/alias/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/opt/distrod/alias/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/opt/distrod/alias/usr/sbin/nologin
ubuntu:x:1000:1000::/home/ubuntu:/opt/distrod/alias/bin/bash
yyjh:x:1001:1001::/home/yyjh:/opt/distrod/alias/bin/zsh
systemd-coredump:x:999:999:systemd Core Dumper:/:/opt/distrod/alias/usr/sbin/nologin
nullpo-head commented 2 years ago

Considering that it has yyjh:x:1001:1001::/home/yyjh:/opt/distrod/alias/bin/zsh, a shell should start under systemd. How did you start Distrod after installation? Usually your terminal will start your login shell, and it should trigger Distrod.

If it's still not working, could you share the results of the following commands, please?

systemctl status
ps aux
cat /run/distrod/*.json

Also try enabling the logging https://github.com/nullpo-head/wsl-distrod/blob/main/docs/references.md#enable-debug-logging-of-distrod

yueyejinghun commented 2 years ago

I installed it using .\distrod_wsl_launcher.exe -d Ubuntu. No error messages during the whole process Starting it with the profile Windows Terminal automatically generated. Also tried running it directly from PowerShell Core using wsl -d Ubuntu

Output of $ systemctl status

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

Output of $ ps aux

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0    900   528 ?        Sl   18:04   0:00 /init
root         7  0.0  0.0    908    84 ?        Ss   18:04   0:00 /init
root         8  0.0  0.0    908    92 ?        R    18:04   0:00 /init
yyjh         9  0.1  0.1  12776  5652 pts/0    Ss   18:04   0:00 -zsh

Output of $ cat /run/distrod/*.json

zsh: no matches found: /run/distrod/*.json

Ah, after running cat /run/distrod/*.json compare to using fish as the default login shell, I can see the problem now, just don't know the cause When using fish as login shell and run cat /run/distrod/*.json

{"rootfs":"/","init_pid":11}⏎
yueyejinghun commented 2 years ago

I reinstalled Ubuntu and newly installed Fedora 35 today with the new release, both are working fine now. I'm not sure if it was the new release or the reinstallation, but the problem has been solved.