[Lxc-users] Howto detect we are in LXC contener

Stéphane Graber stgraber at ubuntu.com
Thu May 26 01:32:21 UTC 2011


On Thu, 2011-05-26 at 01:51 +0200, David Touzeau wrote:
> Dear all
> 
> to detect if we are inside an OpenVZ, openvzve,xen machine
> we can check the presence of :
> /proc/vz/veinfo
> /proc/vz/version
> /proc/sys/xen
> /sys/bus/xen
> /proc/xen
> 
> But i did not find any information inside the LXC contener in order to
> detect We are really in an LXC contener.
> 
> Is there a tip ??
> 
> Best regards

My current trick is to check:
if [ -f "/proc/1/cgroup" ] && grep -vq "/$" /proc/1/cgroup; then
    echo "lxc!"
fi

This check won't guarantee it's LXC but there shouldn't be too many
other setups where init is in a cgroup.

If there's a more reliable way of doing it, I'm also interested!

-- 
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: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20110525/59257d97/attachment.pgp>


More information about the lxc-users mailing list