2

I created this following the instructions of official kubernetes site: https://kubernetes.io/blog/2020/05/21/wsl-docker-kubernetes-on-the-windows-desktop/

My WSL is not working now. It is stuck at the prompt: /usr/sbin/enter-systemd-namespace: line 10: /usr/sbin/daemonize: No such file or directory

Kindly help. I am a beginner.

Create the enter-systemd-namespace

   sudo vi /usr/sbin/enter-systemd-namespace

#!/bin/bash

if [ "$UID" != 0 ]; then
    echo "You need to run $0 through sudo"
    exit 1
fi

SYSTEMD_PID="$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')"
if [ -z "$SYSTEMD_PID" ]; then
    /usr/sbin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
    while [ -z "$SYSTEMD_PID" ]; do
        SYSTEMD_PID="$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')"
    done
fi

if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then
    if [ -n "$1" ] && [ "$1" != "bash --login" ] && [ "$1" != "/bin/bash --login" ]; then
        exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a \
            /usr/bin/sudo -H -u "$SUDO_USER" \
            /bin/bash -c 'set -a; source "$HOME/.systemd-env"; set +a; exec bash -c '"$(printf "%q" "$@")"
    else
        exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a \
            /bin/login -p -f "$SUDO_USER" \
            $(/bin/cat "$HOME/.systemd-env" | grep -v "^PATH=")
    fi
    echo "Existential crisis"
fi
7
  • I see the package daemonize stores its executable in /usr/bin, not /usr/sbin. Try that.
    – ubfan1
    Oct 5, 2022 at 22:04
  • Yeah. I looked it up and found the error. But how could have I known. I copied it from the official site. what to do now? How to do change the path? My CLI is stuck. It is not exiting the prompt screen.
    – Amna
    Oct 5, 2022 at 22:07
  • I assume that Ctrl+C does not exit your script for you and drop you back to the CLI? That typically will help to exit scripts you're running in the foreground that 'freeze' your CLI.
    – Thomas Ward
    Oct 5, 2022 at 22:14
  • Ctrl+C closed my WSL/Ubuntu window.
    – Amna
    Oct 5, 2022 at 22:23
  • 2
    Issue resolved. I edited the script file by accessing it through cmd. learn.microsoft.com/en-us/windows/wsl/filesystems 'wsl vi /usr/sbin/enter-systemd-namespace'
    – Amna
    Oct 5, 2022 at 23:52

1 Answer 1

1

It's good to hear you were able to resolve the issue using the recovery mechanism wsl vi /usr/sbin/enter-systemd-namespace.

But a few points about the process that you are following (with the most important one being last):

I created this following the instructions of official kubernetes site

Note that the page you linked to appears to me to be a guest blog, not "official" documentation. Also note the warning at the top of the page -- I personally really appreciate Kubernetes putting an automatic notice on blog entries that are over a year old:

This article is more than one year old. Older articles may contain outdated content. Check that the information in the page has not become incorrect since its publication.

Considering it uses Ubuntu 18.04, which is only about 6 months away from its End-of-Standard-Support, it could definitely use a refresh.


From the blog post title:

WSL+Docker: Kubernetes on the Windows Desktop

Perhaps I'm misunderstanding a bit, since I'm not a K8s expert, but I think the post should have been more accurately titled, "Minikube on the Windows Desktop".

If you just need Kubernetes, without Minikube, then Docker Desktop includes a K8s server and client with a single-node cluster. See the Docker doc for more information.

Note that the Docker Desktop Kubernetes implementation does not require Systemd.


Also from the blog post:

In order to enable SystemD on WSL2, we will apply the scripts from Daniel Llewellyn.

If you do need Minikube specifically, I'll say that I not a fan of scripts that enable Systemd on WSL. I give my reasons in this answer, but suffice it to say that running inside a Systemd namespace like this drastically changes the way things work in WSL. At the very least, there are/were better (more up-to-date, more robust) options out there than that script.

And now, if you are a Windows 11 user at least, you can use an official Microsoft release of WSL that enables Systemd support. This would almost certainly be a better approach than the script that blog post recommends. See this answer for details on how to enable Systemd support in WSL on Windows 11 using the latest release.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .