0

My root filesystem is full and I'd like to create a container in my home directory, which has a lot of free space. I made a config file like this:

  LXC_AUTO="true"
  LXC_DIRECTORY="/home/al/lxc"

And I'm creating a container like this:

  $ sudo lxc-create -f lxc.conf -t ubuntu -n foo

But it's still filling up /var.

How can I tell lxc to create a container in my home dir?

2 Answers 2

1

EDIT #2:

Wow, can't believe I missed this:

When first installing lxc (version: 0.8.0~rc1-8+deb7u1) ("apt-get install lxc") it will ask you in what directory you want the containers to go.

EDIT #2 END

EDIT:

Apparently if you install "lxc" from source with the command:

make install --localstatedir=/home

it should allow automatic creation of a VE in the /home directory. This will impact all lxc-* tools.

EDIT END

You need to edit "lxc-create" (for me it's in "/usr/bin"). In that file where it defines "localstatedir" and "lxc_path" you need to change that.

Based on what you want, you would need:

localstatedir=/home
lxc_path=${localstatedir}/al/lxc

Or possibly:

localstatedir=/home/al
lxc_path=${localstatedir}/lxc

My setup:

localstatedir=/home
lxc_path=${localstatedir}/lxc

I have just figured this out; it creates the container without any errors, but I have not tested it beyond that. As for the line "LXC_DIRECTORY=" in the config file "/etc/default/lxc", it needs to match the line "lxc_path=" in the file "lxc-create" or it will create a rootfs in two different directories.

So your config file "/etc/default/lxc" would need to read:

LXC_DIRECTORY="/home/al/lxc"

and mine reads:

LXC_DIRECTORY="/home/lxc"

This is of course a workaround, and I do not know the impact this has on other lxc-* tools. They may need to be edited as needed also; perhaps someone else can chime in on how to install lxc with this built into the program.

3
  • Installing from source with the --localstatedir option did the trick. Apr 5, 2014 at 8:05
  • is it possible to set the backing directory on a per container basis?
    – andresp
    Dec 14, 2014 at 14:13
  • 2
    You can just use the '-P' argument of lxc-create. Other commands as lxc-console and lxc-start accepts it too. I think it is easier than define environment variables. Jan 29, 2015 at 17:46
1

You can override container path with --lxcpath/-P option like this:

sudo lxc-create -P /home/al/lxc -f lxc.conf -t ubuntu -n foo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .