WSL1を使い続けていると、WSL2しか見ていない人達によってWSL1が見捨てられているのを感じていますが、WSL1はWSL1でいいところがあるのです。
WSL1が本家のWSLであってWSL2はおもてたんと違う! #WSL - Qiita
Better CygwinとしてWSL1を使っているのでこれからもWSL1を使いたいのですが、Ubuntu 24.04をうまく動かせないことがあるため、その知見をためておきます。
大抵systemdが悪いです。
systemdの更新を止める
WSL1でUbuntu24.04を使うと、apt upgradeや他のパッケージインストール時にsystemd周辺でエラーが出る。(そもそもWSL1でsystemdは使えないのに)
Errors were encountered while processing:
systemd
systemd-timesyncd
udev
libpam-systemd:amd64
systemd-resolved
systemd-sysv
ubuntu-minimal
ubuntu-wsl
libnss-systemd:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)
WSL1はsystemdをサポートしていないので当然ではあるが、これでは他のパッケージを入れられない。これはapt-mark holdで更新を止めることで回避できる。
sudo apt-mark hold systemd
sudo apt-mark hold systemd-dev
mikuta0407@S12Pro:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
mikuta0407@S12Pro:~$ uname -a
Linux S12Pro 4.4.0-22621-Microsoft #4391-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 x86_64 x86_64 GNU/Linux
mikuta0407@S12Pro:~$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
Hit:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
mikuta0407@S12Pro:~$
参考: windows subsystem for linux - Upgrade of a freshly installed WSL1 Ubuntu 24.04 fails - Super User
systemd-sysusersを偽装してエラーを回避
systemdが動かないことでsystemd-sysusersがうまく動かず、こんなエラーが出てくることがある。
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
installed systemd package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
systemd
E: Sub-process /usr/bin/dpkg returned an error code (1)
これはsystemd-sysusersをechoのシンボリックリンクにすることで回避できる。
cd /bin && mv -f systemd-sysusers{,.org} && ln -s echo systemd-sysusers && cd -