4

I have created two containers(say TestOneContainer and TestTwoContainer) in ubuntu server using LXC. Now the lxc filesystem is in /home folder and two containers also use /home folder. I have created two partition(100 GB for TestOneContainer and 200 GB for TestTwoContainer) for those two containers while Ubuntu server OS installation. I want to mount TestOneContainer in 100 GB space and TestTwoContainer in 200 GB space. How can I do this?

I have tried these commands from this link

create and symlink two directories:

sudo mkdir /srv/lxclib /srv/lxccache
sudo rm -rf /var/lib/lxc /var/cache/lxc
sudo ln -s /srv/lxclib /var/lib/lxc
sudo ln -s /srv/lxccache /var/cache/lxc

or, using bind mounts:

sudo mkdir /srv/lxclib /srv/lxccache
sudo sed -i '$a \
/srv/lxclib /var/lib/lxc    none defaults,bind 0 0 \
/srv/lxccache /var/cache/lxc none defaults,bind 0 0' /etc/fstab
sudo mount -a

But these commands are to mount lxc in different filesystem not TestOneContainer or TestTwoContainer.

user3002180
  • 431
  • 6
  • 19

2 Answers2

1

suppose 100GB free space is under /mnt/sd1 and 200GB is under /mnt/sd2, and you want to mount them under /work in containers, use following commands to mount it to the containers:

#create mount point from host
sudo mkdir /var/lib/lxc/TestOneContainer/rootfs/work
sudo mkdir /var/lib/lxc/TestTwoContainer/rootfs/work

#mount them from host
sudo mount --bind /mnt/sd1/ /var/lib/lxc/TestOneContainer/rootfs/work
sudo mount --bind /mnt/sd2/ /var/lib/lxc/TestTwoContainer/rootfs/work

Then start the containers, and you will see /work with that big space with

df -h
Jiang
  • 491
  • 5
  • 9
1

You should read this LXC source, specifically to the section

Host Setup --> Using a separate filesystem for the container store.

There is a very clear explanation.

Robert
  • 10,403
  • 14
  • 67
  • 117