Skip to content

Instantly share code, notes, and snippets.

@akirak
Forked from bhouse/centos_nspawn.md
Created February 20, 2020 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirak/de7545129c0fb5ba2941837891460327 to your computer and use it in GitHub Desktop.
Save akirak/de7545129c0fb5ba2941837891460327 to your computer and use it in GitHub Desktop.
Centos 7.2.1511 via systemd-nspawn

Make a directory to install CentOS 7.2.1511 in

[root@localhost ~]# mkdir /centos_chroot

Make a directory for the rpm database

[root@localhost ~]# mkdir -p /centos_chroot/var/lib/rpm

Create the RPM database

[root@localhost ~]# rpm --rebuilddb --root=/centos_chroot/

Download the release rpm for CentOS 7.2.1511

[root@localhost ~]# wget http://mirror.centos.org/centos-7/7.2.1511/os/x86_64/Packages/centos-release-7-2.1511.el7.centos.2.10.x86_64.rpm

Install the release rpm for CentOS 7.2.1511

[root@localhost ~]# rpm -i --root=/centos_chroot --nodeps centos-release-7-2.1511.el7.centos.2.10.x86_64.rpm

Install CentOS 7.2.1511 via yum

[root@localhost ~]# yum --installroot=/centos_chroot groups install -y -q 'Minimal Install'

Set the password for the root user

[root@localhost ~]# chroot /centos_chroot passwd root

Boot the centos vm via systemd-nspawn

[root@localhost ~]# systemd-nspawn -D /centos_chroot -b

Login to root account with the previously set password

CentOS Linux 7 (Core)
Kernel 3.10.0-327.3.1.el7.x86_64 on an x86_64

centos_chroot login: root
Password:
[root@centos_chroot ~]#

in a separate window, use the machinectl command to poweroff the vm

[root@localhost ~]# machinectl poweroff centos_chroot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment