Change lxc container directory

Dumitru picture Dumitru · Aug 13, 2014 · Viewed 23.1k times · Source

Can I change the directory where lxc containers are initialized and kept? Now they are created under /var/cache/lxc, and I would like to have them in another directory, on another partition where I have more space. Changint the mounting point of the partition is not an option as it's already used for something else.

Answer

Arkadi Shishlov picture Arkadi Shishlov · Aug 24, 2014

Yes you can. The /var/cache/lxc prefix is hardcoded into every /usr/share/lxc/templates/ template. You can change the path over there. In case you're building LXC from sources, then the path is actually @LOCALSTATEDIR@/cache/lxc/ where @LOCALSTATEDIR@ is by default --prefix= + /var or --localstatedir you pass to ./configure.

As for /var/lib/lxc, the default path to containers, specific container, and path to container's dir type of datastore could be configured at multiple levels:

  1. lxc.lxcpath in /etc/lxc/lxc.conf, consult man lxc.system.conf for details.
  2. lxc-* tools accepts -P flag to specify alternate container path.
  3. lxc-create -B dir backing store has optional --dir ROOTFS flag.

Also, I highly recommend a series of blog posts by Stéphane Graber and Containers storage specifically.