Profile specifies mount to nonempty directory

I have a profile which specifies:

terminfo:
  path: /etc/terminfo
  readonly: "true"
  source: /usr/share/terminfo
  type: disk

So as to make the hosts terminfo, which is far more complete, available to containers. On debian images, there is an /etc/terminfo/README file which blocks mounting the disk device with the error

Failed to remove old /etc/terminfo: Directory not empty

This prevents the container from starting, entirely.

Is there a way I can run commands which modify the rootfs at provision time, before the container is started? Or is there a way to instruct lxc to bind-mount directly over existing files?

What container image are you using for this?

https://cloud-images.ubuntu.com/releases bionic

or

https://images.linuxcontainers.org debian/buster
stgraber@castiana:~$ lxc launch ubuntu:bionic bionic
Creating bionic
Starting bionic
stgraber@castiana:~$ lxc config device add bionic terminfo disk readonly=true source=/usr/share/terminfo/ path=/etc/terminfo
Device terminfo added to bionic
stgraber@castiana:~$ lxc exec bionic -- grep terminfo /proc/mounts
castiana/ROOT/ubuntu /etc/terminfo zfs ro,relatime,xattr,posixacl 0 0
stgraber@castiana:~$ lxc stop bionic
stgraber@castiana:~$ lxc start bionic
stgraber@castiana:~$ lxc exec bionic -- grep terminfo /proc/mounts
castiana/ROOT/ubuntu /etc/terminfo zfs ro,relatime,xattr,posixacl 0 0
stgraber@castiana:~$ 

I’ve discovered the root of my issue: If source is not a directory, but a regular file, lxd first tries to delete the existing directory from the containers rootfs. This fails, because the directory is non-empty, producing the error message I reported.

This makes sense to me; I wouldn’t expect to be able to bind-mount a file onto a directory.

Thanks for your help!

Ah yeah, indeed, then the error is correct as indeed we cannot bind-mount different types, so we attempt a delete in the off chance that the thing is empty.