0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Mac + Lima + Debian + systemd-nspawn = CentOS7

Last updated at Posted at 2022-05-01

CnetOS7の検証環境が急遽必要になったので今後の事を考えて Mac + Lima + Debian + systemd-nspawn でインストールした覚書

大まかな流れ

  1. MacにLimaをインストール
  2. LimaにDebian11をインストール
  3. Debianにsystemd-nspawnをインストール
  4. Debianにyumをインストール
  5. 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
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?