[Lxc-users] [RFC] best way to add creation of lvm containers

Ramez Hanna rhanna at informatiq.org
Wed Aug 24 11:15:46 UTC 2011


first thought put it in lxc-create
then again, conversion is needed too hence i also want an lxc-convert
i am coming from a qemu background
so qemu-img does create and convert
so optimum is to see an lxc-convert and have that function also
available as part of lxc-create


On Fri, Jul 1, 2011 at 8:31 PM, Serge E. Hallyn <serge at hallyn.com> wrote:
> Hey,
>
> so lxc-clone will create a snapshot-based clone of an lvm-backed
> container in about a second.  Creating the first lvm-backed
> container is a bit of a pain though.  I do it using the script
> below, called 'lxclvmconvert' on my machine.  So I do
>
>   lxc-create -t ubuntu -f /etc/lxc.conf -n mavbase -- -r maverick
>   lxclvmconvert mavbase
>
> and from then on I can do fast
>
>   lxc-clone -s -o mavbase -n mav-bugxyz
>
> My question is, where do we want to put this functionality?  Of course
> I *can* put it in the ubuntu template itself, but I'm leary of adding
> too many options to that.  Consider that just for the lvm support we'd
> need to add optional arguments for:
>
>   backing store type:  (lvm, loopback file, real blockdev)
>   backing store fstype
>   backing store size
>   other options, i.e. lvm volume group name
>
> So, do you think it would be better for the container creation templates
> to offer this support, or to have a separate tool, not lxclvmconvert, but
> maybe 'lxc-convert', which converts a container from any supported backing
> type to any other.  Backing types I guess could start out by including
>
>   directory (the current way)
>   lvm
>   loopback file
>   raw device
>
> thanks,
> -serge
>
> #!/bin/sh
>
> if [ $# -lt 1 ]; then
>        echo "Usage: $0 container-name <size> <fstype>"
>        exit 1
> fi
>
> c=$1
> size=2G
> fstype=ext3
> echo "converting container $c"
>
> if [ $# -gt 1 ]; then
>        size=$2
>        echo "Using size $size"
> fi
>
> if [ $# -gt 2 ]; then
>        fstype=$3
>        echo "Using fstype $fstype"
> fi
>
> if [ ! -d /var/lib/lxc/$c/rootfs ]; then
>        echo "Container $c doesn't seem to exist?"
>        exit 1
> fi
>
> if [ -e /dev/lxc/$c ]; then
>        echo "/dev/lxc/$c already exists.  Bailing"
>        exit 1
> fi
>
> lvcreate -L $size -n $c lxc || cleanup
> sleep 1
> mkfs -t $fstype /dev/lxc/$c
> if [ $? -ne 0 ]; then
>        echo "Failed to create the filesystem"
>        lvremove -f /dev/lxc/$c
>        exit 1
> fi
>
> mkdir /var/lib/lxc/$c/lvm || { lvremove -f /dev/lxc/$c; exit 1; }
> mount -t $fstype /dev/lxc/$c /var/lib/lxc/$c/lvm || { lvremove -f /dev/lxc/$c; exit 1; }
> rsync -va /var/lib/lxc/$c/rootfs/ /var/lib/lxc/$c/lvm || echo "Rsync had errors, you may want to check;  continuing"
> umount /var/lib/lxc/$c/lvm
> rmdir /var/lib/lxc/$c/lvm
> rm -rf /var/lib/lxc/$c/rootfs
> mkdir /var/lib/lxc/$c/rootfs
>
> sed -i '/lxc.rootfs/d' /var/lib/lxc/$c/config
> echo "lxc.rootfs = /dev/lxc/$c" >> /var/lib/lxc/$c/config
>
> echo "Finished"
>
>
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously valuable.
> Why? It contains a definitive record of application performance, security
> threats, fraudulent activity, and more. Splunk takes this data and makes
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2d-c2
> _______________________________________________
> Lxc-users mailing list
> Lxc-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-users
>




More information about the lxc-users mailing list