cloudstack-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francois Gaudreault <fgaudrea...@cloudops.com>
Subject Re: LXC template
Date Wed, 02 Apr 2014 15:07:29 GMT
On 2014-04-02, 1:34 AM, Chinu wrote:
> Hello all,
>
>      Please can someone advice how to create an LXC template image  in tar format to
spawn containers in KVM for Cloudstack version 4.2 or 4.3
> Regards,
> Chinu
>
>
>
I have that. This is for a CentOS image. I apologize for the formatting, 
I am using text emails ;)

On your *HOST* run:

|mkdir||/var/lib/libvirt/lxc/centos-6-x86_64/etc/yum||.repos.d/ -p |
|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|
|yum groupinstall core 
--installroot=||/var/lib/libvirt/lxc/centos-6-x86_64/||--nogpgcheck -y|
|yum||install||plymouth libselinux-python 
--installroot=||/var/lib/libvirt/lxc/centos-6-x86_64/||--nogpgcheck -y|

On your *CHROOTED* container:
|chroot||/var/lib/libvirt/lxc/centos-6-x86_64/|
|echo||password |||passwd||root --stdin|
|#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|
|#Configuring basic networking|
|cat||>||/etc/sysconfig/network||<< EOF|
|NETWORKING=||yes|
|HOSTNAME=lxc1.||test||.centos.org|
|EOF|
|cat||>||/etc/sysconfig/network-scripts/ifcfg-eth0||<< EOF|
|DEVICE=eth0|
|BOOTPROTO=dhcp|
|ONBOOT=||yes|
|EOF|
|#Enabling sshd|
|chkconfig sshd on|
|# Fixing root login for sshd|
|sed||-i s/||"session required     pam_selinux.so close"||/||"#session 
required     pam_selinux.so close"||/g||/etc/pam||.d||/sshd|
|sed||-i s/||"session required     pam_loginuid.so"||/||"#session 
required     pam_loginuid.so"||/g||/etc/pam||.d||/sshd|
|sed||-i s/||"session required     pam_selinux.so open 
env_params"||/||"#session required     pam_selinux.so open 
env_params"||/g||/etc/pam||.d||/sshd|
||
|cat||>||/etc/fstab||<< END|
|/dev/root| |/ rootfs   defaults        0 0|
|none ||/dev/shm| |tmpfs nosuid,nodev    0 0|
|END|
||
|cat||>||/etc/init/lxc-sysinit||.conf << END|
|start on startup|
|env||container|
|pre-start script|
|||if||[||"x$container"||!=||"xlxc"||-a||"x$container"||!=||"xlibvirt"||];||then|
|||stop;|
|||fi|
|||initctl start||tty||TTY=console|
|||rm||-f||/var/lock/subsys/||*|
|||rm||-f||/var/run/||*.pid|
|||telinit 3|
|||exit||0;|
|end script|
|END|
||
|#Exit the chroot|
|exit|

Tar it:
|cd||/var/lib/libvirt/lxc/centos-6-x86_64|
|tar||cvf centos-6-x86_64_lxc.||tar||.

Upload to CloudStack and enjoy!
|


-- 
Francois Gaudreault
Architecte de Solution Cloud | Cloud Solutions Architect
fgaudreault@cloudops.com
514-629-6775
- - -
CloudOps
420 rue Guy
Montréal QC  H3J 1S6
www.cloudops.com
@CloudOps_


Mime
View raw message