CnetOS7の検証環境が急遽必要になったので今後の事を考えて Mac + Lima + Debian + systemd-nspawn でインストールした覚書
大まかな流れ
- MacにLimaをインストール
- LimaにDebian11をインストール
- Debianにsystemd-nspawnをインストール
- Debianにyumをインストール
- DebianにCentOS7をインストール
MacにLimaをインストール
% brew install lima
LimaにDebian11をインストール
インストールしたバージョンと同一のものを lima-vm/lima からもってくる
% limactl -v
limactl version 0.8.3
% curl -o debian.yaml https://raw.githubusercontent.com/lima-vm/lima/v0.8.3/examples/debian.yaml
% limactl start ./debian.yaml
起動時尋ねられるので Proceed with the default configuration
を選択
? Creating an instance "default" [Use arrows to move, type to filter]
> Proceed with the default configuration
Open an editor to override the configuration
Debianにsystemd-nspawnをインストール
Debianのシェルに入る。
% limactl shell debian
(debian11)$ sudo apt install systemd-container
Debianにyumをインストール
(debian11)$ sudo apt install dnf
(debian11)$ sudo tee /etc/yum.repos.d/CentOS7-Base.repo<<"EOF"
[base]
name=CentOS-7 - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
enabled=0
gpgcheck=0
EOF
DebianにCentOS7をインストール
CentOS7 インストール
(debian11)$ dnf --releasever=7 \
--installroot=/var/lib/machines/centos7 \
--disablerepo='*' \
--enablerepo=base \
install systemd passwd yum sudo vi
(debian11)$ echo 7 > /var/lib/machines/centos7/etc/yum/vars/releasever
ネットワークをプライベートからホストネットワークに変更
(debian11)$ sudo mkdir -p /etc/systemd/nspawn/
(debian11)$ sudo tee /etc/systemd/nspawn/centos7.nspawn<<EOF
[Network]
VirtualEthernet=no
EOF
コンテナを起動
(debian11)$ systemd-nspawn -D /var/lib/machines/centos7
CentOS7のシェルでログインユーザーを作成する
# ユーザ作成
(centos7)$ useradd -m your-name -s /bin/bash
# パスワード設定
(centos7)$ passwd your-name
# sudo権限付与
(centos7)$ gpasswd -a your-name wheel
# コンテナから一旦ぬける
(centos7)$ exit
コンテナをブート
(debian11)$ systemd-nspawn -bD /var/lib/machines/centos7/
外部と接続できるか確認
(centos7)$ sudo yum update
# 「Ctrl+]」 x 3 で終了
コンテナ起動
# コンテナ起動
(debian11)$ sudo machinectl start centos7
# コンテナの起動状態確認
(debian11)$ sudo machinectl status centos7
# コンテナへログイン
(debian11)$ sudo machinectl login centos7