How to add or mount directory in LXD (Linux container)

How to add or mount directory in LXD (Linux container)

To add or mount a directory in an LXD (Linux container) on a Linux system, you can use the lxc command with the config subcommand. Here's an example of how you can do this:

  1. First, create a directory on the host system that you want to mount in the LXD container. For example:
refer to‮ual:‬tturi.com
mkdir /mnt/lxd
  1. Use the lxc command to list the available containers on your system:
lxc list
  1. Identify the container that you want to mount the directory in and make a note of its name.

  2. Use the lxc command with the config subcommand to add a new configuration value for the container. For example, to mount the /mnt/lxd directory in the container named my-container, you can use the following command:

lxc config set my-container raw.lxc "lxc.mount.entry = /mnt/lxd hostbind,create=dir 0 0"

This will add a new configuration value to the container that specifies the /mnt/lxd directory on the host system should be mounted in the container.

  1. Use the lxc command with the start subcommand to start the container with the new configuration value applied. For example:
lxc start my-container

This will start the container and mount the /mnt/lxd directory in the container.

  1. Use the lxc command with the exec subcommand to execute a command in the container. For example, to list the contents of the mounted directory, you can use the following command:
lxc exec my-container -- ls -l /mnt/lxd

This will execute the ls command in the container and display the contents of the /mnt/lxd directory.

Note: The lxc command has many options and features available for managing LXD containers on a Linux system. Consult the documentation and online resources for more information on the various options and features available with this command. It is recommended to use the lxc command with caution, as improper use can cause problems or disrupt the operation of the container.

Created Time:2017-10-28 21:38:58  Author:lautturi