LXC Template creation - Apache Cloudstack (2024)

Steps to create minimal CentOS 6 container template:

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 -cvzfcentos-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 rootc.#Fix root login on consoleecho "pts/0" >>/etc/securettysed -i s/"session required pam_selinux.so close"/"#session required pam_selinux.so close"/g /etc/pam.d/loginsed -i s/"session required pam_selinux.so open"/"#session required pam_selinux.so open"/g /etc/pam.d/loginsed -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 << EOFDEVICE=eth0BOOTPROTO=dhcpONBOOT=yesEOF

Creating template on Ubuntu

Rootfs can be downloaded from here as well:http://images.linuxcontainers.org/images/ubuntu/trusty/amd64/default/

  1. Install lxc: apt-get install lxc

  2. Create a container with any name, in our case 'ubuntu':

    sudo lxc-create -t download -n ubuntu -- --dist ubuntu --release trusty --arch amd64

  3. Creation of the LXC container will take a lot of time, it will be stored here: /var/lib/lxc/ubuntu

  4. Next stop the container:
    sudo lxc-stop -n ubuntu

  5. Next create a temp director, tar the rootfs and export the template:
    mkdir -p /tmp/lxc-template
    cd /tmp/lxc-template
    sudo tar --numeric-owner -czf /tmp/lxc-template/template.tar.gz /var/lib/lxc/ubuntu/rootfs/

LXC Template creation - Apache Cloudstack (2024)
Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 5661

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.