LXC guest OS installation
I tweaked the lxc template of CentOS to support CentOS 7.
A copy of the lxc template I have created is placed at https://github.com/nirmalraj17/lxc/blob/master/templates/lxc-centos.in
This was done because there was some steps which was related to OS version 7 which was not mentioned in the current lxc-centos template, and it was mentioned in lxc-oracle template. I took out the relevant sections out of the lxc-oracle and added it to the current lxc-centos template and created a new template named lxc-centos-7.
Then create a lxc container using the command
lxc-create -n centos7 -t /usr/local/share/lxc/templates/lxc-centos-7 -- -R 7
This will download necessary files required for release version 7
After this if you try to start the LXC container, you will receive "[!!!!!!] Failed to allocate manager object, freezing." when you try to start.
Now create a directory systemd under /cgroup
Mount using the below command.
mount -t cgroup -o none,name=systemd cgroup /cgroup/systemd
Now if you start the LXC container and tried to login, you will receive the error message "server refused to allocate pty"
To avoid that stop the container and create a shell script which will do the necessary actions.
[root@centos ~]# vi /usr/local/var/lib/{container_name}/rooftfs/usr/local/bin/device_initiation.sh
#!/bin/bash
mknod -m 600 /dev/console c 5 1 2>/dev/null
mknod -m 666 /dev/null c 1 3 2>/dev/null
mount -n -t tmpfs none /dev 2>/dev/null
mknod -m 622 /dev/console c 5 1 2>/dev/null
mknod -m 666 /dev/null c 1 3 2>/dev/null
mknod -m 666 /dev/zero c 1 5 2>/dev/null
mknod -m 666 /dev/ptmx c 5 2 2>/dev/null
mknod -m 666 /dev/tty c 5 0 2>/dev/null
mknod -m 444 /dev/random c 1 8 2>/dev/null
mknod -m 444 /dev/urandom c 1 9 2>/dev/null
chown root:tty /dev/{console,ptmx,tty} 2>/dev/null
ln -s /proc/self/fd /dev/fd 2>/dev/null
ln -s /proc/self/fd/0 /dev/stdin 2>/dev/null
ln -s /proc/self/fd/1 /dev/stdout 2>/dev/null
ln -s /proc/self/fd/2 /dev/stderr 2>/dev/null
ln -s /proc/kcore /dev/core 2>/dev/null
mkdir /dev/pts 2>/dev/null
mkdir /dev/shm 2>/dev/null
mount -t devpts -o gid=4,mode=620 none /dev/pts 2>/dev/null
mount -t tmpfs none /dev/shm 2>/dev/null
Since we are placing this file in usr/local/bin, this command will be accessible from the system directly.
Now to startup the server and execute this shell script, I have created a shell script.
[root@centos ~]# vi startup_centos7.sh
#!/bin/bash
lxc-start -n centos7
lxc-attach -n centos7 device_initiation.sh
exit
Once you execute the script, the CentOS 7 will be starting and you will be able to login smoothly.
After doing the above steps, I got working CentOS 7.3 version installed on new LXC container.