Migrate/convert existing full CentOS 6 server to LXC container

October 11th, 2015 by bostjan

“Containerization is a great thing!” Ok, great. So, what now? How do I containerize my servers?

Converting whole servers that served more than single purpose goes against main reason for containerization: using dedicated containers for each service and thus eliminating package (and other) dependency conflicts. But sometimes your whole servers (or VMs) need to be containerized for various reasons: they were already used for single purpose, or services on them are enough unimportant and consume very little resources and thus moving HW (or VM) server to container just makes sense from resource conservation’s point of view.

Recently I was tasked with containerizing CentOS 6 host. Below follow steps I did to make it work.

Full CentOS server to LXC container – steps

Here is a list of steps to be performed:

  1. Create empty CentOS 6 container – this will be used to get container-specific /dev contents
  2. Move default rootfs/ out of the way into rootfs-LXC-DEFAULT/
  3. Copy all existing server files to container’s rootfs/ directory – this will be used to get container-specific /dev contents,
  4. Replace rootfs/dev/ contents with contents from rootfs-LXC-DEFAULT/dev/ directory – this ensures that no devices that should not be present in container are really not there,
  5. Edit /etc/init/tty.conf and add –nohangup argument to mingetty command line – this ensures proper console functionality,
  6. Disable ex-hardware-specific services (in my case, mdmonitor, lvm services, multipathd, iscsi daemons, UPS daemons etc) – these will interfere with container startup, but should not impact host if containerized environment is properly secured
  7. Configure LXC container’s config and container’s network interfaces – there might be other adjustments to be done, but these are specific to your environment.
  8. This will enable your full CentOS 6 server to start and run as container. You might hit some other roadbumps along the way (missing kernel modules, mounts etc), but at least you will be well on your way to success :).


One Response to “Migrate/convert existing full CentOS 6 server to LXC container”

  1. […] the guide for converting full CentOS 6 servers to LXC containers, here is the quick update for converting Ubuntu 14.04 hosts to LXC […]

Leave a Reply

 

*