Mount host directory inside LXD container.

Create a directory on a host operating system.

$ sudo mkdir /mnt/disk/archivebox

Look for subuid and subgid files.

$ ls  /snap/lxd/current/etc/
bash_completion.d  ethertypes  logrotate.conf  lvm  nanorc  protocols  ubuntu-sb.crt  vimrc

Snap package does not provide these files, so the beginning of the uid/gid range will be 1000000. This means that you need to use 1002000:1002000 uid:gid combination to get 2000:2000 uid:gid inside guest instance.

$ sudo chown -R 1002000:1002000 /mnt/disk/archivebox

Mount /mnt/disk/archivebox host directory to /opt/archivebox inside archivebox instance.

$ sudo -i lxc config device add archivebox archivebox_directory disk source=/mnt/disk/archivebox path=/opt/archivebox
Device archivebox_directory added to archivebox

Directory will be created automatically and defined user and group will reflect subordinate user/group IDs.

$ sudo -i lxc exec archivebox -- stat /opt/archivebox
File: /opt/archivebox
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 800h/2048d      Inode: 36306945    Links: 9
Access: (0755/drwxr-xr-x)  Uid: ( 2000/archivebox)   Gid: ( 2000/archivebox)
Access: 2021-12-19 16:22:54.660738431 +0000
Modify: 2021-12-19 20:09:24.424730331 +0000
Change: 2021-12-19 20:09:24.424730331 +0000
 Birth: 2021-12-19 16:22:54.660738431 +0000

Alternatively, it will be owned by 65534/nobody user when you skip setting subordinate user/group IDs.

Display device configuration for archivebox instance.

$ sudo -i lxc config device show archivebox
archivebox_directory:
  path: /opt/archivebox
  source: /mnt/disk/archivebox
  type: disk

Edit instance configuration.

$ sudo -i lxc config edit archivebox
### This is a YAML representation of the configuration.
### Any line starting with a '# will be ignored.
###
### A sample configuration looks like:
### name: instance1
### profiles:
### - default
### config:
###   volatile.eth0.hwaddr: 00:16:3e:e9:f8:7f
### devices:
###   homedir:
###     path: /extra
###     source: /home/user
###     type: disk
### ephemeral: false
###
### Note that the name is shown but cannot be changed

architecture: armv7l
config:
  image.architecture: armhf
  image.description: Debian bullseye armhf (20211219_05:25)
  image.os: Debian
  image.release: bullseye
  image.serial: "20211219_05:25"
  image.type: squashfs
  image.variant: default
  volatile.base_image: c5cb7135fbb8785c9971daf29709d4840efc3b2b4397684752ddd0f34f078dc5
  volatile.eth0.host_name: vethd3c7b49e
  volatile.eth0.hwaddr: 00:16:3e:38:03:48
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]'
  volatile.last_state.power: RUNNING
  volatile.uuid: 3cc4ff6e-e343-4312-b285-68b75272bdb0
devices:
  archivebox_directory:
    path: /opt/archivebox
    source: /mnt/disk/archivebox
    type: disk
ephemeral: false
profiles:
- default
stateful: false
description: ""

Remove device configuration.

$ sudo -i lxc config device remove archivebox archivebox_directory
Device archivebox_directory removed from archivebox

Additional information

Instance configuration [disk]

ko-fi