8

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.

Dumitru
  • 771
  • 2
  • 12
  • 23
  • You could also use a symlink or provide the option --lxcpath to the lxc-commands. – jgb Sep 05 '14 at 13:08

3 Answers3

14

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.

Arkadi Shishlov
  • 351
  • 2
  • 5
1

The least painful would be probably just mount -o bind a directory on the partition with space to /var/lib/lxc or /var/lib/lxd whichever is your case. This works from /etc/fstab too.

Dosya
  • 21
  • 1
1

For debian template (and some others) you can use environment variable, for example:

LXC_CACHE_PATH=/usr/share/lxc/cache
arvati
  • 149
  • 1
  • 5