全てはArchの意思のままに WSLにArch Linuxをインストールする


滅亡迅雷.netには接続しません。あと、Arch Linuxはアークではなくアーチと読みます。

さて、WSLが出たばかりのころからずっとWSLを使っていて、当時はUbuntuしかディストリビューションが無かったので ずっとUbuntuを使ってきたのですが、Arch Linuxに乗り換えていこうかと思いました。

理由としては以下のとおりです。

ということで、WSLにArch Linuxを導入していこうと思うのでメモを残しておこうと思います。

今のUbuntuの環境が継ぎ足し継ぎ足しで、いろいろターミナル周りもごちゃごちゃしてきたので、そこのリファクタリングも噛ねて。

インストール

WSLはpowershellから簡単にインストールできます。

> wsl --install -d archlinux
ダウンロードしています: Arch Linux
インストールしています: Arch Linux
ディストリビューションが正常にインストールされました。'wsl.exe -d archlinux' を使用して起動できます
archlinux を起動しています...
Welcome to the Arch Linux WSL image!

This image is maintained at <https://gitlab.archlinux.org/archlinux/archlinux-wsl>.

Please, report bugs at <https://gitlab.archlinux.org/archlinux/archlinux-wsl/-/issues>.
Note that WSL 1 is not supported.

For more information about this WSL image and its usage (including "tips and tricks" and troubleshooting steps), see the related Arch Wiki page at <https://wiki.archlinux.org/title/Install_Arch_Linux_on_WSL>.

While images are built regularly, it is strongly recommended running "pacman -Syu" right after the first launch due to the rolling release nature of Arch Linux.

Generating pacman keys...
Done

Populating keyring...
Done
[root@host ~]#

Ubuntuの場合は、最初に一般ユーザの作成が入ったが、Archの場合は特になく、rootユーザだけが作られるようです。

ユーザを作成

ユーザを作成し、sudoが使えるようにしていきます。

パッケージを更新し、sudoを導入。

pacman -Syu
pacman -S sudo

ユーザを作成する。

groupadd -g 1000
useradd -u 1000 -g 1000 -G wheel -m grugrut
passwd grugrut

sudoの設定をしようと思ったら、vimも入っていないので導入します。

pacman -S vim

sudoの設定をして、作成したユーザが sudo を使えるようにします。

(前略)
  ##
  ## User privilege specification
  ##
  root ALL=(ALL:ALL) ALL

  ## Uncomment to allow members of group wheel to execute any command
  ## ↓コメント化されているのでコメント解除する
  %wheel ALL=(ALL:ALL) ALL

  ## Same thing without a password
  # %wheel ALL=(ALL:ALL) NOPASSWD: ALL

  ## Uncomment to allow members of group sudo to execute any command
  # %sudo ALL=(ALL:ALL) ALL
(後略)

ユーザ作成の動作確認

# su - grugrut
$ id
uid=1000(grugrut) gid=1000(grugrut) groups=1000(grugrut),998(wheel)
$ pwd
/home/grugrut
$ sudo id

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

For security reasons, the password you type will not be visible.

[sudo] password for grugrut:
uid=0(root) gid=0(root) groups=0(root)

せっかくユーザを作ってもこのままだと、rootユーザでログインされるので、 WSL実行時のユーザを変更します。

[boot]
systemd=true

[user]
default=grugrut

設定したら、Powershellからwslを一度終了して反映させます。

PS> wsl --shutdown
PS> wsl -d archlinux

ちなみに、ArchLinuxだけを以下のように終了させるとWSL起動時にエラーメッセージが出ました。 手抜きはよくないですね。

#+attr_html :caption ダメなパターン

PS> wsl -t archlinux
PS> wsl -d archlinux
wsl: Failed to start the systemd user session for 'grugrut'. See journalctl for more details.
$

初期セットアップ

ArchLinuxのパッケージマネージャは pacman です。 pacmanだけでもそこそこ多くのパッケージを扱えますが、さらに便利にするために AUR も使えるようにします。 特にこだわりがないので、AURのフロントエンドには yay を使います。

Gitの導入

AURを扱うためには、gitが必要なので導入、初期設定をおこないます。 gitを利用する際には、ghqがあると便利なので、こちらも導入します。

sudo pacman -S git ghq

ghqでクローンするリポジトリは個人的な好みで ~/src 配下にたまっていってほしいので、 .gitconfig を設定します。

[ghq]
    root = /home/grugrut/src

AUR / yayの導入

mkdir src

# yayの取得
ghq get aur.archlinux.org/yay.git
cd src/aur.archlinux.org/yay

# makepkgの前提パッケージの導入
sudo pacman -S debugedit fakeroot base-devel
makepkg -si

これで yay が使えるようになりパッケージ導入が簡単になりました。

まとめ

今回は、以前のラップトップにつづき、WindowsでもArch Linuxが触れるように、 WSLにArch Linuxを導入しました。

次回以降は、ちゃんと設定を整えていこうと思います。


関連記事

comments powered by Disqus