Last active
January 12, 2022 05:31
-
-
Save mykysyk/1b644f28f2891a055577a468776464f7 to your computer and use it in GitHub Desktop.
[systemd-nspawn] CentOS8Stream コンテナ作成 (Debian 11)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# systemd-containerパケージをインストール | |
apt install systemd-container | |
# パッケージマネージャーのインストール | |
apt install dnf debootstrap | |
# BaseOS repo 作成 | |
cat<<"EOF">/etc/yum.repos.d/CentOS8-Linux-BaseOS.repo | |
[baseos] | |
name=CentOS Stream 8 - BaseOS | |
mirrorlist=http://mirrorlist.centos.org/?release=8&arch=$basearch&repo=BaseOS&infra=$infra | |
enabled=0 | |
gpgcheck=0 | |
EOF | |
# AppStream repo 作成 | |
cat<<"EOF">/etc/yum.repos.d/CentOS8-Linux-AppStream.repo | |
[appstream] | |
name=CentOS Stream 8 - AppStream | |
mirrorlist=http://mirrorlist.centos.org/?release=8&arch=$basearch&repo=AppStream&infra=$infra | |
enabled=0 | |
gpgcheck=0 | |
EOF | |
# コンテナ名 | |
CONTAINER_NAME=centos8 | |
# CentOS8 インストール | |
dnf --releasever=8 \ | |
--installroot=/var/lib/machines/${CONTAINER_NAME} \ | |
--disablerepo='*' \ | |
--enablerepo=baseos \ | |
--enablerepo=appstream \ | |
install systemd passwd dnf sudo vi | |
# コンテナのreleaseverを8にしておく(おまじない) | |
echo 8 > /var/lib/machines/${CONTAINER_NAME}/etc/dnf/vars/releasever | |
# nspawnディレクトr作成 | |
mkdir -p /etc/systemd/nspawn/ | |
# ネットワークをプライベートからホストネットワークに変更 | |
cat<<EOF>/etc/systemd/nspawn/${CONTAINER_NAME}.nspawn | |
[Network] | |
VirtualEthernet=no | |
EOF | |
# コンテナを起動 | |
systemd-nspawn -D /var/lib/machines/${CONTAINER_NAME} | |
# ユーザ作成 | |
useradd -m your-name -s /bin/bash | |
# パスワード設定 | |
passwd your-name | |
# sudo権限付与 | |
gpasswd -a your-name wheel | |
# centos-release-stream インストール | |
dnf install centos-release-stream | |
# repo 変更 | |
dnf swap centos-{linux,stream}-repos | |
# distro-sync 実行 | |
dnf distro-sync | |
# コンテナから一旦ぬける | |
exit | |
# コンテナをブート | |
systemd-nspawn -bD /var/lib/machines/${CONTAINER_NAME}/ | |
# locale を UTF-8 にする | |
sudo localectl set-locale LANG=ja_JP.utf8 | |
# 外部と接続できるか確認 | |
sudo dnf update | |
# 「Ctrl+]」 x 3 で終了 | |
# コンテナ起動 | |
machinectl start ${CONTAINER_NAME} | |
# コンテナの起動状態確認 | |
machinectl status ${CONTAINER_NAME} | |
# コンテナへログイン | |
machinectl login ${CONTAINER_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment