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
Just curious, why use chroot to set the password instead of systemd-nspawn and just leaving off the boot param? :) If it fails doing it via systemd-nspawn -D /centos_chroot passwd root, sometimes using restorecon helps.