I am finally able to configure WSL2 to automount my SDcard as non-root user and preserve owner:group and rwx permissions on SDCard. My SDcard is NTFS in format.
Step1. enable automount. Create
/etc/wsl.conf with this content
enable = true
options = "defaults,user"
mountFsTab = true
mnt/d where we want to mount our drive
Step3: Enable fstab entry for SDCard to be mounted at /mtn/d.
In my case, D: drive (on surface pro 7)
$ cat /etc/fstab
LABEL=cloudimg-rootfs / ext4 defaults 0 1
D: /mnt/d drvfs defaults,user,metadata,exec 0 0
- there are two lines, first one was already there. I added the second line.
user is requires, else it mounts as
root user. and option
metadata is required, else it wont be able preserve user, group etc permissions.
exec is needed, else you may not be able to execute files in mounted file system. (I was not able to execute file in windows 11)
Step 4: restart wsl
#exit bash or linux, go to dos/windows prompt
wsl # or bash