[Lxc-users] lxcpath

Stéphane Graber stgraber at ubuntu.com
Mon Mar 4 14:34:18 UTC 2013


On 03/02/2013 06:45 PM, Papp Tamas wrote:
> On 02/25/2013 02:56 PM, Serge Hallyn wrote:
>>
>> Quoting Papp Tamas (tompos at martos.bme.hu):
>>> hi Serge and Others,
>>>
>>> lxc version: 0.9.0.alpha3
>>>
>>> lxcpath=/data/lxc
>>>
>>> tank/lxc/ltest on /tank/lxc/ltest type zfs (rw,noatime)
>>>
>>>
>>> # sh -x /usr/bin/lxc-create -n ltest -t ubuntu
>>> + . /usr/share/lxc/lxc.functions
>>> + globalconf=/etc/lxc/lxc.conf
>>> + bindir=/usr/bin
>>> + templatedir=/usr/share/lxc/templates
>>> + lxcinitdir=/usr/lib/x86_64-linux-gnu
>>> + get_default_lxcpath
>>> + grep -v ^# /etc/lxc/lxc.conf
>>> + grep [ \t]*lxcpath[ \t]*=
>>> + awk -F= { print $2 }
>>> + lxc_path=/data/lxc
>>> + backingstore=_unset
>>> + fstype=ext4
>>> + fssize=500M
>>> + vgname=lxc
>>> + custom_rootfs=
>>> + [ 4 -gt 0 ]
>>> + opt=-n
>>> + shift
>>> + optarg_check -n ltest
>>> + [ -z ltest ]
>>> + lxc_name=ltest
>>> + shift
>>> + [ 2 -gt 0 ]
>>> + opt=-t
>>> + shift
>>> + optarg_check -t ubuntu
>>> + [ -z ubuntu ]
>>> + lxc_template=ubuntu
>>> + shift
>>> + [ 0 -gt 0 ]
>>> + wantedhelp=0
>>> + [ -z /data/lxc ]
>>> + [ ! -r /data/lxc ]
>>> + [ -z ltest ]
>>> + [ -z  ]
>>> + lvname=ltest
>>> + id -u
>>> + [ 0 != 0 ]
>>> + [ -n  ]
>>> + :
>>> + [ -d /data/lxc/ltest ]
>>> + basename /usr/bin/lxc-create
>>> + echo lxc-create: 'ltest' already exists
>>> lxc-create: 'ltest' already exists
>>> + exit 1
>>>
>>>
>>>
>>> So a new container cannot be created, because the directory already exists, as it's on an own
>>> filesystem.
>>
>> Yes lxcpath does not address the case of wanting to import an existing
>> rootfs.  Only the case of wanting to keep the rootfs on a different
>> partition.  But you can now keep the container config in
>> /data/lxc/ltest/config instead of under /var/lib/lxc/ltest, which
>> might keep things (like where the fstab should be) less confused.
> 
> I'm not sure, I understand, what you get to point. Or maybe I miss that:)
> 
> This is, what I do:
> 
> 1. I create a partition or zfs volume for the container to keep
> 2. lxc-create -t ubuntu
> 
> 
> What about this small change?
> 
> --- /usr/bin/lxc-create.ORIG	2013-03-03 00:38:19.749777404 +0100
> +++ /usr/bin/lxc-create	2013-03-03 00:39:17.050725908 +0100
> @@ -205,7 +205,7 @@
>           ;;
>   esac
> 
> -if [ -d "$lxc_path/$lxc_name" ]; then
> +if [ -d "$lxc_path/$lxc_name/rootfs" ]; then
>       echo "$(basename $0): '$lxc_name' already exists" >&2
>       exit 1
>   fi
> 
> 
> Though not perfect at all since it cannot handle the case, when there is a mountpoint inside the 
> rootfs (eg. rootfs/var).
> But I think with this change it would work way comfortable.
> 
> 
> tamas


The change proposed above wouldn't work for cases where you create the
container config in /var/lib/lxc/<container> but don't store the rootfs
there. For example when using lvm-backed containers.

In such case, a second call to lxc-create would completely destroy the
config of the existing container...


I guess we could do 'if [ -f "$lxc_path/$lxc_name/config" ]' instead,
which should work fine for any lxc-create generated container.

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20130304/bb22bf3a/attachment.pgp>


More information about the lxc-users mailing list