Skip to content

Commit

Permalink
Update getting-started.md
Browse files Browse the repository at this point in the history
add description for creating the mount with `create=dir` mount option

Signed-off-by: Peter Michaux <[email protected]>
  • Loading branch information
petermichaux committed Jan 21, 2024
1 parent 4d618b5 commit 421d62a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions content/lxc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,33 @@ If you will never need the container again, then you can permanently destroy it.

A container's file system activity is restricted to `/var/lib/lxc/<container-name>/rootfs`. When a container is destroyed all of `/var/lib/lxc/<container-name>` is also destroyed. You may have multiple containers and would like to share some file system space between them. You may have disposable containers and would like some file system space to outlive the container. In cases like these, you can create a host volume outside the container's `rootfs` and then mount that volume inside the container.

Suppose we have already created a container named `mycontainer` as described above.
Suppose we have already created and started a container named `mycontainer` as described above.

Create the host volume.

root@host:~# mkdir -p /host/path/to/volume

Create the container mount point.
To mount the volume inside the container there are two options.

The first option requires two steps: manually create the mount target inside the container and then configure the container mount.

root@host:~# lxc-attach --name mycontainer -- mkdir -p /container/mount/point

Stop the container so that we can reconfigure it with the volume mount.
root@host:~# echo "lxc.mount.entry = /host/path/to/volume container/mount/point none bind 0 0" >>/var/lib/lxc/mycontainer/config

root@host:~# lxc-stop --name mycontainer
The second option requires only one step: use `create=dir` when configuring the mount so that the mount target is automatically created inside the container for you.

Add the volume mount to the container's configuration. (Note that the container mount point path is relative. It does not have a leading `/` character.)
root@host:~# echo "lxc.mount.entry = /host/path/to/volume container/mount/point none bind,create=dir 0 0" >>/var/lib/lxc/mycontainer/config

root@host:~# echo "lxc.mount.entry = /host/path/to/volume container/mount/point none bind 0 0" >>/var/lib/lxc/mycontainer/config
With either option, note that the container mount target path `container/mount/point` is relative. It does not have a leading `/` character.

After configuring the container, restart it so the new configuration is used.

Restart the container so the new configuration is used.
root@host:~# lxc-stop --name mycontainer

root@host:~# lxc-start --name mycontainer

Now that we have created the volume and mounted it in the container, we can test it works.
Now that we have created the volume and mounted it in the container, we can test that it works.

On the host, add a text file to the volume.

Expand All @@ -130,7 +134,7 @@ The container can add text to the text file.

root@mycontainer:~# echo "mycontainer message" >>/container/mount/point/messages.txt

Exit the container.
Exit the container shell.

root@mycontainer:~# exit

Expand Down

0 comments on commit 421d62a

Please sign in to comment.