I am trying to set up a virtual drive from a file. This file will then be written to a flash device (not relevant). Because creating and manipulating the virtual drive will be in a script, I need to do it in user space, i.e., not as root. The script is for building and creating an image for a flash device; so, running as root will be problematic.
In order to mount the file as a virtual drive, I added the following line to /etc/fstab:
/home/user/drive.img /home/user/mnt ext4 loop,rw,user,noauto,noexec 0 0
The problem is that when I mount the virtual drive, root takes ownership of ~/mnt, defeating the purpose of mounting it as a regular user.
I know that other file systems allow you to mount while specifying the uid/gid, but the virtual drive must be ext4 to be compatible with an existing process. I tried udisksctl, but it requires root authentication for loopback.
I am going to try mounting then changing ownership (as root) but never unmount it. I will do a 'sync' then take a snapshot of the virtual drive. I do not like it because it is not clean, but it may work for now.