puppetlabs/facter — pull request #630 by jeffmccune (2014-02-10 07:16:14+00:00)
Title: Add LXC detection to virtual and is_virtual fact

Without this patch the virtual and is_virtual facts are returning "physical" and "false" respectively. This is a problem because Linux Containers are a virtual environment and it is useful to configure things differently in lxc when compared to other virtual environments.

This patch addresses the problem by detecting if the process is running inside of a linux container by looking at the cgroup entries for the init process. This method is described at http://stackoverflow.com/questions/20010199/determining-if-a-process-runs-inside-lxc-docker#

Basically, if /proc/1/cgroup looks like this, we're not in a lxc container:

9:hugetlb:/
8:perf_event:/
7:blkio:/
6:freezer:/
5:devices:/
4:memory:/
3:cpuacct:/
2:cpu:/
1:cpuset:/

But if they look like this then we are in a container:

9:hugetlb:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
8:perf_event:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
7:blkio:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
6:freezer:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
5:devices:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
4:memory:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
3:cpuacct:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
2:cpu:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be
1:cpuset:/lxc/e411045bbbc61eca5d3af7eb0764c30833606f51d20c176f406afbdb47bb04be

The identifier is the container id and might be useful for a future fact to identify the container Facter is running in.