VPSのDebianをbookwormからtrixieにアップグレードのついでにOpenRCも同時にすることにしました。方法はDebianのwikiを参照してそのとおりにしたのですが、結果はシステムが完全に破綻状態になりました。やはり無謀すぎたようです。それでクリーンインストールしてOpenRC化することにしました。OpenRC化する理由はsystemdはリソースを食いすぎて運用しているVPSにかなり負担になっているからです。
VPSに正規方法ではないインストール方法は手間がかかるのですが不要なパッケージ入れないようにするためにこの方法を使います。
やり方はまずVPSで用意されているCDを使ってブートし、レスキューモードのシェルを立ち上げます。そしてrootパーティションをchrootでマウントし、debootstrapコマンドでOSをインストールします。OSが復旧したら別途保存しておいた設定やデータをリストアします。
OpenRC化
initを置き換えるのはかなりトリッキーですが、Debianのwikiに方法があったのでその通りにやってみました。
apt –purge –allow-remove-essential install sysvinit-core libpam-elogind dbus-x11 systemd-sysv-
これはsysv-initなのでOpenRCの場合は次のようにします。
apt --purge --allow-remove-essential install openrc systemd-sysv-
OS復旧仕立て場合は一発で変更できました。経験としてパッケージを入れすぎると破綻してしまうということでした。そしてsystemdをインストールしないように予防線を張っておきます。
apt-mark hold systemd systemd-sysv
たいていのデーモンは/etc/init.dから起動できますがshorewallだけは起動できなかったので/etc/rc.localから起動するようにしました。
暗号化rootfsのネット経由のunlock
まずは必要なパッケージをインストールします。
apt install dropbear-initramfs
Client側でdropbear用のrsa鍵を作りid_rsa.pubをscp等でサーバに転送します。それを/etc/dropbear/initramfs/authorized_keysに書き込みます。次にinitramfs起動時に固定IPを設定します。
dropbearの設定を特にしなければsshポート22をを使いますが、設定した方が良いので変更します。
DROPBEAR_OPTIONS="-p 1234 -s -j -k -I 90"
各パラメータはmanpageを参照してください。
IP=192.168.1.128::192.168.1.1:255.255.255.0:vps-ablenet
シンタックスはip=<server-ip>::<gw-ip>:<netmask>:<hostname>です。
設定が完了したらinitramfsをアップデートします。
リブートしてクライアント側からリモートログインしてrootfsをアンロックします。
ssh -p 1234 -o "UserKnownHostsFile=~/.ssh/known_hosts.ablenet" \
-i "~/.ssh/id_rsa.ablenet_boot" root@192.168.1.128 \
"echo -ne \"password_for_dm_crypt\" >/lib/cryptsetup/passfifo"
wireguard
google AIに尋ねてみると次のような回答でした。
https://www.google.com/search?q=wireguird+openrc+dsevuan&sca_esv=1fc1f57c86215af9&sxsrf=AE3TifNz7spmj-urtJ6wYPe7HeIimjQEeg%3A1767220613476&ei=haVVae3sHJ6k2roPqYuf8QY&ved=0ahUKEwitw5_n8eiRAxUeklYBHanFJ24Q4dUDCBM&uact=5&oq=wireguird+openrc+dsevuan&gs_lp=Egxnd3Mtd2l6LXNlcnAiGHdpcmVndWlyZCBvcGVucmMgZHNldnVhbjIHECEYoAEYCjIHECEYoAEYCjIHECEYoAEYCkjIGVDmBliJF3ABeACQAQGYAZICoAGbDKoBBTAuOC4xuAEDyAEA-AEBmAIIoALOCcICChAAGLADGNYEGEfCAgYQABgNGB7CAggQABgIGA0YHsICCxAAGIAEGIYDGIoFwgIFEAAY7wWYAwDiAwUSATEgQIgGAZAGCJIHBTEuNi4xoAfNJbIHBTAuNi4xuAfECcIHCTAuNS4yLjUtMcgHW4AIAA&sclient=gws-wiz-serp
#!/sbin/openrc-run
description="WireGuard Quick"
# Change 'wg0' to the name of your configuration file if different
name="wg0"
depend() {
need localmount
need net
# Might also need an explicit dependency on the physical interface if complex networking
}
start() {
ebegin "Starting WireGuard interface ${name}"
wg-quick up ${name}
eend $?
}
stop() {
ebegin "Stopping WireGuard interface ${name}"
wg-quick down ${name}
eend $?
}
dependファンクションのlocalmountとnetがdebianでは起動してないのでそのままだとエラーで起動できません。それなのでdbusならシステムの要であり割と遅く起動するので変更しました。
#!/sbin/openrc-run
description="WireGuard Quick"
# Change 'wg0' to the name of your configuration file if different
name="wg0"
depend() {
#need localmount
#need net
need dbus
# Might also need an explicit dependency on the physical interface if complex networking
}
start() {
ebegin "Starting WireGuard interface ${name}"
wg-quick up ${name}
eend $?
}
stop() {
ebegin "Stopping WireGuard interface ${name}"
wg-quick down ${name}
eend $?
}
cd /etc/init.d
ln -s wg-quick wg-quick@wg0
rc-update add wg-quick@wg0 default
shorewallもこの方法で起動した方が良いでしょう。
#!/sbin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-firewall/shorewall/files/shorewall.initd,v 1.4 2013/07/13 14:09:09 constanze Exp $
command=/usr/sbin/shorewall
extra_commands="check clear"
extra_started_commands="refresh reset safe_restart"
depend() {
# need net
provide firewall
after rsyslog
}
start() {
checkpath -d -m 755 /var/lock/subsys
ebegin "Starting shorewall"
$command -f start 1>/dev/null
eend $?
}
stop() {
ebegin "Stopping shorewall"
$command stop 1>/dev/null
eend $?
}
safe_restart() {
ebegin "Safely restarting shorewall"
$command safe-restart 1>/dev/null
eend $?
}
clear() {
# clear will remove all the rules and bring the system to an unfirewalled
# state. (21 Nov 2004 eldad)
ebegin "Clearing all shorewall rules and setting policy to ACCEPT"
$command clear
eend $?
}
reset() {
# reset the packet and byte counters in the firewall
ebegin "Resetting the packet and byte counters in the shorewall"
$command reset
eend $?
}
refresh() {
# refresh the rules involving the broadcast addresses of firewall
# interfaces, the black list, traffic control rules and
# ECN control rules
ebegin "Refreshing shorewall rules"
$command refresh
eend $?
}
check() {
# perform cursory validation of the zones, interfaces, hosts, rules
# and policy files. CAUTION: does not parse and validate the generated
# iptables commands.
ebegin "Checking configuration files"
$command check
eend $?
}
ting system message bus: dbusdbus-daemon[1455]: Failed to start message bus: Could not get UID and GID for username "messagebus"
# groupadd -g 991 messagebus
# useradd -c 'System Message Bus' -u 991 -g messagebus -d '/nonexistent' -s /usr/sbin/nologin messagebus
useradd warning: dbus's uid 991 outside of the UID_MIN 1000 and UID_MAX 60000 range.
#!/sbin/openrc-run
description="Starts the rsyslogd enhanced system logging daemon"
command="/usr/sbin/rsyslogd"
command_args="-n"
supervisor=supervise-daemon
depend() {
provide logger
after bootmisc
}
LXC
ついでにコンテナのLXCでdebianとopenwrtもアップグレードしました。debianのi386のtrixieは最後のバージョンです。公式にはサポートが外れますがまだ使えるのでそのまま続行します。openwrtは安定版がv24.10.5です。サイトからrootfs.tar.gzをダウンロードして展開すればすぐ使えます。アップグレードは大きな問題はありませんが、dovecotの設定が大幅に変更になって再設定が必要です。詳しくは次のサイトにあります。
- https://openwrt.org/docs/guide-user/virtualization/lxc
- https://www.debian.org/releases/trixie/release-notes/issues.html
参考
- https://www.debian.org/releases/forky/arm64/apds03.en.html
- https://wiki.debian.org/Debootstrap
- https://wiki.debian.org/OpenRC
- https://wiki.debian.org/Init
- https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotely-in-linux/