1.Create a directory where the template files will be created
mkdir -p /var/lib/libvirt/lxc/centos-6-x86_64
2. Create yum repo folder within container root
mkdir -p /var/lib/libvirt/lxc/centos-6-x86_64/etc/yum.repos.d/
3. Create CentOS repo
cat /etc/yum.repos.d/CentOS-Base.repo |sed s/'$releasever'/6/g > /var/lib/libvirt/lxc/centos-6-x86_64/etc/yum.repos.d/CentOS-Base.repo
4. Install core packages. --installroot param will install these packages into container root folder
yum groupinstall core --installroot=/var/lib/libvirt/lxc/centos-6-x86_64/ --nogpgcheck -y
5. Install any additional packages if required:
yum install plymouth libselinux-python --installroot=/var/lib/libvirt/lxc/centos-6-x86_64/ --nogpgcheck -y
6. Container can be configured further using chroot
chroot /var/lib/libvirt/lxc/centos-6-x86_64/
7. CloudStack requires template in tar.gz format. Create a tar.gz from container root /var/lib/libvirt/lxc/centos-6-x86_64/
cd /var/lib/libvirt/lxc/centos-6-x86_64/
tar -cvzf centos-6-x86_64.tar.gz *
8. centos-6-x86_64.tar.gz can be registered as a template in CloudStack
Steps to set root password:
a. chroot /var/lib/libvirt/lxc/centos-6-x86_64/ b. passwd root c. #Fix root login on console echo "pts/0" >>/etc/securetty sed -i s/"session required pam_selinux.so close"/"#session required pam_selinux.so close"/g /etc/pam.d/login sed -i s/"session required pam_selinux.so open"/"#session required pam_selinux.so open"/g /etc/pam.d/login sed -i s/"session required pam_loginuid.so"/"#session required pam_loginuid.so"/g /etc/pam.d/login
Steps to set networking to use dhcp:
Configuring networking cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes EOF
Rootfs can be downloaded from here as well: http://images.linuxcontainers.org/images/ubuntu/trusty/amd64/default/
Install lxc: apt-get install lxc
Create a container with any name, in our case 'ubuntu':
sudo lxc-create -t download -n ubuntu -- --dist ubuntu --release trusty --arch amd64
Creation of the LXC container will take a lot of time, it will be stored here: /var/lib/lxc/ubuntu
Next stop the container:
sudo lxc-stop -n ubuntu