I have a bunch of LXC containers running on a machine. All of them have their rootfs in the default location /var/lib/lxc/*/rootfs. This directory lives on a rather small partition on the host. I have a much, much bigger partition mounted on /home.

Is there an option to move the backing storage to /home? Preferably per container.

I know I could have done that before I had a couple of running containers (lxc-create -P PATH). But now they're up and I don't want to lose them.

  • Can't you make /var/lib/lxc a symbolic link to a directory in /home? – daniel kullmann Mar 11 '15 at 14:01
  • 1
    ... That was so obvious I didn't think of it. It works. Wow. – harm Mar 11 '15 at 14:51

rootfs is the configuration option. If the container is stopped, you can move the backing directory wherever you want and specify that in the config file:

lxc.rootfs = /home/utsname

This is probably better than using a symlink.

LXC also allows backing files. You can use block devices and raw images.

Source: https://linuxcontainers.org/lxc/manpages/man5/lxc.container.conf.5.html


I, personally prefer a different approach. Given that the OS part of the containers is relatively small (max. 2GB a debian jessie server with plenty of services running, about 3Gb a working ubuntu image with remote desktop), I leave the OS reside in /var/lib/lxc and use a separate partition for the container's data.

This is simply accomplished modifing the /var/lib/lxc/container/fstab file:

/mnt/data/container-data/ /var/lib/lxc/container/rootfs/home/        none    bind    0       0

Create the folders (both source and target) on the main host, stop your container, move your data and restart the container!

In the case above, both direcories reside on a /mnt/data partition on the lxc host, in my case a large disk.

There are many advantages associated with this method: splitting the OS and the data allows you to rapidly copy and start test containers when you have to accomplish hazardous tasks (ex: "aptitude -f dist-upgrade"):

  • stop the container (the partitions in fstab will detach from the /var/lib/lxc/container/rootfs/ directory):

    lxc-stop -n container
  • copy the container:

    mkdir /var/lib/lxc/containertest
    rsync -Pavv /var/lib/lxc/container/ /var/lib/lxc/containertest/

Remember to modify accordingly /var/lib/lxc/containertest/config and /var/lib/lxc/containertest/fstab

  • start the new containertest, work with it and see the results!

    lxc-start -n containertest

Also, answering to your concerns, you should not worry about not haveing done this before: one of the great advanages of lxc is it's versatility!


Call me lazy - but why mess around with the config files if you could (bind) mount your large directory at /var/lib/lxc?

Simply shutdown your containers, move things over to /home/lxc/whatever and bind-mount them back in - done!


Better to change path for all new containers by default:

# vim /etc/lxc/lxc.conf

All containers will be in /media/other/programs/OS/containers/ directory

All old containers move via mv and edit configs for them as this guy https://unix.stackexchange.com/a/191620/53139

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.