1

I have created a LXC virtualized physical server with Centos 6.8 as host OS.
Now when I am creating guest VM using the default template of Centos, it is creating the VM's with Centos 6.8 as the guest OS.
I wanted to create a VM with Centos 7.2 version as the guest OS. Is this possible?

I have done the below steps for creating the VM and starting.

  1. Created a copy of the centos template and hard coded the 7.2 version inside the template. (As I understand it checks for /etc/os-release for CPE ID)
  2. Created a guest VM pointing to this new template created. ( Centos 7.2 version was downloaded and placed in the LXC cache)
  3. Guest VM is created. I changed the network link in the config file to bridge network.
  4. I started the guest VM, But I can see only systemd process is started (using pstree command), there is no IP address assigned to the VM and I am not able to login to guest VM.

I needed a VM with Centos 7.2 in this environment. Please guide on how to achieve this.

  • LXC uses the same kernel as the host, afaik you can't run a newer kernel on an "old" host. – Lenniey May 9 '17 at 7:36
  • @Lenniey I have updated the kernel to 4.10 (centos 6.8) while I have done the LXC configuration (Host system). The kernel which Centos 7 is using is 3.10. – nirmalraj17 May 9 '17 at 8:00
  • Sorry, I was not being clear: the kernel has to be the same, not "newer", for full functionality as far as I know. Maybe there are some tricks / workarounds, but I never did such a thing myself. – Lenniey May 9 '17 at 8:08
  • @Lenniey Thanks for making it clear. I would consider upgrading my host server to centos 7.2 as a last option. But looking for some workarounds at the VM level to avoid this – nirmalraj17 May 9 '17 at 10:10
  • Try this: stgraber.org/2013/12/23/… – Lenniey May 9 '17 at 10:27
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.