Can't mount directory from MacOS

:wave: Hi all, and thanks for LXC/LXD.

I’m playing locally with LXD using Multipass.
I can’t mount a device in a container.

From mount, I see that my disk is /dev/disk1s1s1

⚡ mount
/dev/disk1s1s1 on / (apfs, sealed, local, read-only, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk1s5 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk1s3 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
/dev/disk1s6 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
/dev/disk1s2 on /System/Volumes/Data (apfs, local, journaled, nobrowse)
map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)

From the directory where I created the container, I want to mount the directory itself.

⚡ lxc config device add app /dev/disk1s1s1 disk source=$(pwd) path=/app
Error: Failed add validation for device "/dev/disk1s1s1": Missing source path "/Users/jodosha/Code/jodosha/star_wars" for disk "/dev/disk1s1s1"

I also tried only with disk1s1s1, but it still doesn’t work:

⚡ lxc config device add app disk1s1s1 disk source=$(pwd) path=/app
Error: Failed add validation for device "disk1s1s1": Missing source path "/Users/jodosha/Code/jodosha/star_wars" for disk "disk1s1s1"

What am I doing wrong?

You seem to be looking at your mount table on MacOS but LXD is running inside of the Linux VM so it doesn’t see the same filesystem or devices that you do.

1 Like

Can I make the disk visible to LXD so I can mount it Into the container?

I make it to work, @stgraber thanks for your insight. :pray:

1. Mount the host directory into Multipass VM

From the host:

⚡ multipass mount ~/Code lxd

~/Code is the directory to mount, lxd is the Multipass instance that runs LXD.

2. Mount the shared directory as a device

Shell from the host into Multipass instance:

⚡ multipass shell lxd

Within the Multipass instance, create the device, then mount the shared directory (see step 1) into the newly created device (/dev/code).

ubuntu@lxd:~$ sudo mkdir -p /dev/code
ubuntu@lxd:~$ sudo mount --bind /Users/jodosha/Code /dev/code

Exit the Multipass shell.

3. Restart the Multipass instance

From the host:

⚡ multipass restart lxd

4. Mount the directory inside the LXC container

From the host, within the application directory:

⚡ lxc config device add mycontainer1 /dev/code disk source=$(pwd) path=/app

I have an application under /Users/jodosha/Code (the shared directory mounted as /dev/code), named star_wars.

To run the command above I will do cd /Users/jodosha/Code/star_wars first. That means $(pwd) returns this path.

I have an LXC container named mycontainer1.

The command above reads as:

Add a device to mycontainer1 within /dev/code as type disk using the current host (MacOS) directory ($(pwd)), mounted into the container at /app.

5. Verify it works

From the host, ssh into the LXC container.

⚡ lxc exec mycontainer1 -- bash

List the files from the destination path /app.

root@mycontainer1:~ ll /app/

This command should list the structure of your application.

While I perfectly understand to have your dev code live under the convenient name /dev/code I think that’s a bit risky as /dev is meant to have Linux devices files in it. It’s also a special filesystem you are probably better not to abuse for other purposes.

I think mounting it to /home/ubuntu/code or similar would be safer.

My 2c :slight_smile:

2 Likes