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.
-
You could also use a symlink or provide the option --lxcpath to the lxc-commands. – jgb Sep 05 '14 at 13:08
3 Answers
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:
lxc.lxcpath
in/etc/lxc/lxc.conf
, consultman lxc.system.conf
for details.lxc-*
tools accepts-P
flag to specify alternate container path.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.

- 351
- 2
- 5
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.

- 21
- 1
For debian template (and some others) you can use environment variable, for example:
LXC_CACHE_PATH=/usr/share/lxc/cache

- 149
- 1
- 5