LoginSignup
0
0

More than 3 years have passed since last update.

CentOS7 に systemd-nspawn用 CentOS7 コンテナを作成する

Last updated at Posted at 2020-02-23
NEW_MACHINE='centos7'
yum --releasever=7 \
    --nogpg \
    --installroot=/var/lib/machines/${NEW_MACHINE} \
    --disablerepo='*' \
    --enablerepo=base \
    install systemd passwd yum vim

sudo systemd-nspawn -D /var/lib/machines/${NEW_MACHINE}
passwd
useradd -m -r user
passwd user
exit

# 起動確認
sudo systemd-nspawn -bD /var/lib/machines/${NEW_MACHINE}
Ctrl+]
Ctrl+]
Ctrl+]

# unit file 
systemctl enable systemd-nspawn@${NEW_MACHINE}.service

(echo '[Service]'
 echo 'ExecStart='
 echo 'ExecStart=/usr/bin/systemd-nspawn --quiet --keep-unit --boot --link-journal=try-guest --machine=%I'
) | SYSTEMD_EDITOR=tee systemctl edit systemd-nspawn@${NEW_MACHINE}.service

cat /usr/lib/systemd/system/systemd-nspawn@.service.
cat /etc/systemd/system/machines.target.wants/systemd-nspawn@${NEW_MACHINE}.service
cat /etc/systemd/system/systemd-nspawn@${NEW_MACHINE}.service.d/override.conf

machinectl start ${NEW_MACHINE}
0
0
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
0