Skip to content

Instantly share code, notes, and snippets.

@sunsongxp
Forked from djfdyuruiry/README.md
Created September 1, 2022 04:32
Show Gist options
  • Save sunsongxp/b38bc36d204d8e3564df41e292290718 to your computer and use it in GitHub Desktop.
Save sunsongxp/b38bc36d204d8e3564df41e292290718 to your computer and use it in GitHub Desktop.

Revisions

  1. @djfdyuruiry djfdyuruiry revised this gist Sep 4, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ This guide will enable `systemd` to run as normal under WSL 2. This will enable
    ```bash
    cd /tmp
    wget --content-disposition \
    "https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/46085955818d83b483fd62c65383a7f8dda84f5f/install-sg.sh"
    "https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/952347f805045ba0e6ef7868b18f4a9a8dd2e47a/install-sg.sh"
    ```

    - Make it executable:
  2. @djfdyuruiry djfdyuruiry revised this gist Sep 4, 2021. 1 changed file with 8 additions and 33 deletions.
    41 changes: 8 additions & 33 deletions install-sg.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    #! /usr/bin/env bash
    set -e

    GENIE_VERSION="1.23" # update if you need
    # change these if you want
    UBUNTU_VERSION="20.04"
    GENIE_VERSION="1.44"

    GENIE_FILE="systemd-genie_${GENIE_VERSION}_amd64"
    GENIE_FILE_PATH="/tmp/${GENIE_FILE}.deb"
    GENIE_DIR_PATH="/tmp/${GENIE_FILE}"
    @@ -13,49 +16,22 @@ function installDebPackage() {
    rm -rf "${GENIE_FILE_PATH}"
    }

    function fixDebDependencies() {
    # repackage systemd-genie to require dotnet 3.1 instead of 3.0
    rm -rf "${GENIE_DIR_PATH}"
    mkdir -p "${GENIE_DIR_PATH}"

    dpkg-deb -x "${GENIE_FILE_PATH}" "${GENIE_DIR_PATH}"

    pushd "${GENIE_DIR_PATH}"

    dpkg-deb -e "${GENIE_FILE_PATH}"

    popd

    sed -i 's/dotnet-runtime-3[.]0/dotnet-runtime-3.1/g' "${GENIE_DIR_PATH}/DEBIAN/control"

    rm -f "${GENIE_FILE_PATH}"

    pushd /tmp

    dpkg-deb -b "${GENIE_DIR_PATH}"

    popd

    rm -rf "${GENIE_DIR_PATH}"
    }

    function downloadDebPackage() {
    rm -f "${GENIE_FILE_PATH}"

    pushd /tmp

    wget --content-disposition \
    "https://packagecloud.io/arkane-systems/wsl-translinux/packages/debian/bookworm/${GENIE_FILE}.deb/download.deb"
    "https://github.com/arkane-systems/genie/releases/download/v${GENIE_VERSION}/systemd-genie_${GENIE_VERSION}_amd64.deb"

    popd
    }

    function installDependencies() {
    # install systemd-genie dependencies
    sudo apt-get update

    wget --content-disposition \
    "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb"
    "https://packages.microsoft.com/config/ubuntu/${UBUNTU_VERSION}/packages-microsoft-prod.deb"

    sudo dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb
    @@ -65,7 +41,8 @@ function installDependencies() {
    sudo apt-get update
    sudo apt-get install -y \
    daemonize \
    dotnet-runtime-3.1
    dotnet-runtime-5.0 \
    systemd-container

    sudo rm -f /usr/sbin/daemonize
    sudo ln -s /usr/bin/daemonize /usr/sbin/daemonize
    @@ -76,8 +53,6 @@ function main() {

    downloadDebPackage

    fixDebDependencies

    installDebPackage
    }

  3. @djfdyuruiry djfdyuruiry revised this gist May 29, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Enable `systemd` in WSL 2

    This guide will enable `systemd` to run as normal under WSL 2. This will enable services like `microk8s`, `docker` and many more to `just work` during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

    - To enable `systemd` under WSL we require a tool called `systemd-genie`
  4. @djfdyuruiry djfdyuruiry revised this gist May 29, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,9 @@ This guide will enable `systemd` to run as normal under WSL 2. This will enable
    - Copy the contents of `install-sg.sh` to a new file `/tmp/install-sg.sh`:

    ```bash
    nano /tmp/install-sg.sh
    cd /tmp
    wget --content-disposition \
    "https://gist.github.com/djfdyuruiry/6720faa3f9fc59bfdf6284ee1f41f950/raw/46085955818d83b483fd62c65383a7f8dda84f5f/install-sg.sh"
    ```

    - Make it executable:
  5. @djfdyuruiry djfdyuruiry created this gist May 29, 2020.
    39 changes: 39 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    This guide will enable `systemd` to run as normal under WSL 2. This will enable services like `microk8s`, `docker` and many more to `just work` during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

    - To enable `systemd` under WSL we require a tool called `systemd-genie`

    - Copy the contents of `install-sg.sh` to a new file `/tmp/install-sg.sh`:

    ```bash
    nano /tmp/install-sg.sh
    ```

    - Make it executable:

    ```bash
    chmod +x /tmp/install-sg.sh
    ```

    - Run the new script:

    ```bash
    /tmp/install-sg.sh && rm /tmp/install-sg.sh
    ```

    - Exit the WSL terminal and shutdown the WSL env:

    ```bash
    wsl --shutdown
    ```

    - To open a new WSL terminal with `systemd` enabled, run:

    ```powershell
    wsl genie -s
    ```

    - Prove that it works:

    ```bash
    sudo systemctl status time-sync.target
    ```
    84 changes: 84 additions & 0 deletions install-sg.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    #! /usr/bin/env bash
    set -e

    GENIE_VERSION="1.23" # update if you need
    GENIE_FILE="systemd-genie_${GENIE_VERSION}_amd64"
    GENIE_FILE_PATH="/tmp/${GENIE_FILE}.deb"
    GENIE_DIR_PATH="/tmp/${GENIE_FILE}"

    function installDebPackage() {
    # install repackaged systemd-genie
    sudo dpkg -i "${GENIE_FILE_PATH}"

    rm -rf "${GENIE_FILE_PATH}"
    }

    function fixDebDependencies() {
    # repackage systemd-genie to require dotnet 3.1 instead of 3.0
    rm -rf "${GENIE_DIR_PATH}"
    mkdir -p "${GENIE_DIR_PATH}"

    dpkg-deb -x "${GENIE_FILE_PATH}" "${GENIE_DIR_PATH}"

    pushd "${GENIE_DIR_PATH}"

    dpkg-deb -e "${GENIE_FILE_PATH}"

    popd

    sed -i 's/dotnet-runtime-3[.]0/dotnet-runtime-3.1/g' "${GENIE_DIR_PATH}/DEBIAN/control"

    rm -f "${GENIE_FILE_PATH}"

    pushd /tmp

    dpkg-deb -b "${GENIE_DIR_PATH}"

    popd

    rm -rf "${GENIE_DIR_PATH}"
    }

    function downloadDebPackage() {
    rm -f "${GENIE_FILE_PATH}"

    pushd /tmp

    wget --content-disposition \
    "https://packagecloud.io/arkane-systems/wsl-translinux/packages/debian/bookworm/${GENIE_FILE}.deb/download.deb"

    popd
    }

    function installDependencies() {
    # install systemd-genie dependencies
    sudo apt-get update

    wget --content-disposition \
    "https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb"

    sudo dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb

    sudo apt-get install apt-transport-https

    sudo apt-get update
    sudo apt-get install -y \
    daemonize \
    dotnet-runtime-3.1

    sudo rm -f /usr/sbin/daemonize
    sudo ln -s /usr/bin/daemonize /usr/sbin/daemonize
    }

    function main() {
    installDependencies

    downloadDebPackage

    fixDebDependencies

    installDebPackage
    }

    main