Skip to content

Commit

Permalink
feat: add manjaro-wsl
Browse files Browse the repository at this point in the history
  • Loading branch information
rising3 committed Jul 11, 2023
1 parent 61c6de7 commit 1b6c91d
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
base.tar
rootfs
rootfs.tar.gz
ziproot
icons.zip
Manjaro-wsl2.zip
Manjaro.exe
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM manjarolinux/base:latest

RUN pacman-mirrors --fasttrack 5; pacman-key --init; pacman-key --populate \
&& sed -ibak -e 's/#Color/Color/g' -e 's/CheckSpace/#CheckSpace/g' /etc/pacman.conf; sed -ibak -e 's/IgnorePkg/#IgnorePkg/g' /etc/pacman.conf \
&& sed -i 's/#\[multilib\]/\[multilib\]/g' /etc/pacman.conf; sed -i '/\[multilib\]/ { n; s/#Include/Include/; }' /etc/pacman.conf \
&& grep -q builder /etc/passwd && userdel -r builder \
&& pacman --noconfirm -Syyu \
&& pacman -Sy --noconfirm --needed aria2 aspell base base-devel bc ccache curl dos2unix figlet git grep hspell hunspell hwdata inetutils iputils iproute2 keychain libxcrypt-compat libvoikko linux-tools lolcat nano ntp nuspell procps socat sudo usbutils vi vim wget xdg-utils xmlto yay yelp-tools \
&& mkdir -p /etc/pacman.d/hooks; echo '%wheel ALL=(ALL) ALL' > /etc/sudoers.d/wheel \
&& sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen \
&& locale-gen; systemd-machine-id-setup; rm /var/lib/dbus/machine-id; dbus-uuidgen --ensure=/etc/machine-id; dbus-uuidgen --ensure \
&& LC_ALL=en_US.UTF-8 pacman -Scc \
# install wslutilities
&& wget https://pkg.wslutiliti.es/public.key > /dev/null 2>&1 && pacman-key --add public.key && pacman-key --lsign-key 2D4C887EB08424F157151C493DD50AA7E055D853 && rm public.key \
&& echo '[wslutilities]' | sudo tee -a /etc/pacman.conf > /dev/null 2>&1; echo 'Server = https://pkg.wslutiliti.es/arch/' | sudo tee -a /etc/pacman.conf > /dev/null 2>&1 \
&& pacman -Sy --noconfirm wslu \
&& echo 'export BROWSER="wslview"' | sudo tee -a /etc/skel/.bashrc > /dev/null 2>&1
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
OUT_ZIP=Manjaro-wsl2.zip
WSLDL_ZIP=icons.zip
WSLDL_URL=https://github.com/yuk7/wsldl/releases/download/22020900/$(WSLDL_ZIP)
WSLDL_EXE=Manjaro.exe

all: $(OUT_ZIP)

zip: $(OUT_ZIP)

$(OUT_ZIP): ziproot
@echo -e 'Building $(OUT_ZIP)...'
cd ziproot; bsdtar -a -cf ../$(OUT_ZIP) *

ziproot: $(WSLDL_EXE) rootfs.tar.gz
@echo -e 'Building ziproot...'
mkdir ziproot
cp $(WSLDL_EXE) ziproot/
cp rootfs.tar.gz ziproot

$(WSLDL_EXE): $(WSLDL_ZIP)
@echo -e 'Extracting wsldl exe...'
unzip $(WSLDL_ZIP) $(WSLDL_EXE)

$(WSLDL_ZIP):
@echo -e 'Downloading $(WSLDL_ZIP)...'
curl -L $(WSLDL_URL) -o $(WSLDL_ZIP)

rootfs.tar.gz: rootfs
@echo -e 'Building rootfs.tar.gz...'
cd rootfs; sudo bsdtar -zcpf ../rootfs.tar.gz `sudo ls`
sudo chown `id -un` rootfs.tar.gz

rootfs: base.tar
@echo -e 'Building rootfs...'
mkdir rootfs
sudo bsdtar -zxpf base.tar -C rootfs
sudo cp bash_profile rootfs/root/.bash_profile
sudo cp wsl.conf rootfs/etc/wsl.conf
sudo chmod +x rootfs

base.tar:
@echo -e 'Exporting base.tar using docker...'
docker build . -t manjarolinux/wsl:latest
docker run --name manjarolinux manjarolinux/wsl:latest echo > /dev/null 2>&1
docker export --output base.tar manjarolinux > /dev/null 2>&1
docker rm -f manjarolinux > /dev/null 2>&1

clean:
@echo -e 'Cleaning files...'
-rm ${OUT_ZIP} > /dev/null 2>&1
-rm -r ziproot > /dev/null 2>&1
-rm $(WSLDL_EXE) > /dev/null 2>&1
-rm $(WSLDL_ZIP) > /dev/null 2>&1
-rm rootfs.tar.gz > /dev/null 2>&1
-rm base.tar > /dev/null 2>&1
-docker rmi -f manjarolinux/wsl:latest > /dev/null 2>&1
-sudo rm -r rootfs > /dev/null 2>&1
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
# manjaro-wsl2
# manjaro-wsl2

Manjaro on WSL2 (Windows 10 FCU or later) based on [wsldl](https://github.com/yuk7/wsldl).

![manjaro-wsl2](img/manjaro-wsl2.png)

## Overview

A very simply Manjaro on wsl2 using wsldl.

* Using the [manjarolinux/base:latest](https://hub.docker.com/r/manjarolinux/base) images
* [wslutilities](https://github.com/wslutilities/wslu) installed
* Create a new user and set the user as default
* Enable systemd for WSL version 0.67.6 and higher

## Requirements

* For x64 systems: Version 1903 or higher, with Build 18362 or higher.
* Builds lower than 18362 do not support WSL 2.

## How to install

* Make sure all the steps mentioned under "Requirements" are completed.
* [Download](https://github.com/rising3/manjaro-wsl2/releases/latest) installer zip
* Extract all files in zip file to same directory
* Set version 2 as default. Note that this step is required only for manual installation.
```dos
wsl --set-default-version 2
```
* Run Manjaro.exe to extract rootfs and register to WSL

**Note:**
Exe filename is using the instance name to register. If you rename it you can register with a diffrent name and have multiple installs.

## How to use installed instance
* [exe usage](https://github.com/yuk7/wsldl#exe-usage)

## How to build from source

### prerequisites

Docker, tar, zip, unzip, bsdtar, make, git(gh) need to be installed.

```dos
gh repo clone rising3/manjaro-wsl2
cd manjaro-wsl2
make
```
Run the command below to clean.
```dos
make clean
```

## License

[MIT License](LICENSE)

## Referred to:

* [Advanced settings configuration in WSL](https://learn.microsoft.com/en-us/windows/wsl/wsl-config)
* [Import any Linux distribution to use with WSL](https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro)
* [Creating a Custom Linux Distribution for WSL](https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro)
* [Advanced WSL launcher / installer](https://github.com/yuk7/wsldl)
* [Manjaro for WSL2 using wsldl](https://github.com/sileshn/ManjaroWSL2)
48 changes: 48 additions & 0 deletions bash_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
grn=$(tput setaf 2)
red=$(tput setaf 1)
ylw=$(tput setaf 3)
rst=$(tput sgr0)

echo -e ${grn}"Initializing and populating keyring..."${rst}
pacman-mirrors --fasttrack > /dev/null 2>&1
pacman-key --init > /dev/null 2>&1
pacman-key --populate > /dev/null 2>&1
pacman --noconfirm -Syyu > /dev/null 2>&1

echo -e ${grn}"Creating default user..."${rst}
while read -p "Plase enter the username : " username; do
if [ -z "${username}" ]; then
echo -e ${red}"Blank username entered. Try again!!"${rst}
username=""
elif grep -q "${username}" /etc/passwd; then
echo -e ${red}"Username already exists. Try again!!"${rst}
username=""
else
useradd -m -u 1000 -U -G users,wheel -s /bin/bash "${username}"
echo "%wheel ALL=(ALL) ALL" >/etc/sudoers.d/wheel
passwd ${username}
sed -i "/\[user\]/a default = ${username}" /etc/wsl.conf >/dev/null
break;
fi
done

echo "@echo off" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
echo "wsl.exe --terminate $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
if env | grep "WT_SESSION" >/dev/null 2>&1; then
echo "wt.exe -w 0 nt wsl.exe -d $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
else
echo "cmd /c start \"$WSL_DISTRO_NAME\" wsl.exe --cd ~ -d $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
fi
echo "del C:\Users\Public\shutdown.cmd" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
cp ~/shutdown.cmd /mnt/c/Users/Public && rm ~/shutdown.cmd

secs=3
printf ${ylw}"\nManjaroWSL2 will shutdown and restart to setup systemd!!!\n\n"${rst}
while [ $secs -gt 0 ]; do
printf "\r\033[KShutting down in %.d seconds. " $((secs--))
sleep 1
done

rm ~/.bash_profile
powershell.exe -command "Start-Process -Verb Open -FilePath 'shutdown.cmd' -WorkingDirectory 'C:\Users\Public' -WindowStyle Hidden"
exec sleep 0
Binary file added img/manjaro-wsl2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions wsl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[automount]

[network]

[interop]

[user]

# enable systemd for WSL version 0.67.6 and higher.
[boot]
systemd=true

0 comments on commit 1b6c91d

Please sign in to comment.