Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

@bplaxco

This comment has been minimized.

Copy link

@bplaxco bplaxco commented Aug 11, 2017

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.

@samliddicott

This comment has been minimized.

Copy link

@samliddicott samliddicott commented Oct 4, 2017

I could not set password initially, I had to copy a line from /etc/shadow of the host -- then I could login with that password and change it

@towo

This comment has been minimized.

Copy link

@towo towo commented Oct 8, 2017

@samliddicott If you start the container without booting (i.e. no -b flag), you should just be able to use passwd.

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