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
$cat /etc/wsl.conf
[automount]
enable = true
options = "defaults,user"
mountFsTab = true
Step2: create mnt/d
where we want to mount our drive
mkdir /mnt/d
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
Note:
- there are two lines, first one was already there. I added the second line.
- options
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 --shutdown
wsl # or bash
mount
and see if that gives you clues. If usingcygwin
bash, the path is /cygdrive/.Aaron@MYPC:~$ mount rootfs on / type rootfs (rw,relatime) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204320k,mode=755)
[etc]