/etc/fstab not automounted when WSL2 used from Windows Task Scheduler
/etc/fstab is not automounted when a WSL2 Ubuntu distro is used from Windows Task Scheduler via wsl.exe.
This issue does not reproduce in WSL1 Ubuntu. I discovered it during my WSL1->2 migration. It reminds me of the old WSL1 issue https://github.com/microsoft/WSL/issues/1602 Perhaps related to https://github.com/microsoft/WSL/issues/4226
Environment
Windows build number: Microsoft Windows [Version 10.0.19042.541]
Your Distribution version: Ubuntu 20.04.1 LTS on WSL2
Whether the issue is on WSL 2 and/or WSL 1: Linux version 4.19.128-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Tue Jun 23 12:58:10 UTC 2020
Steps to reproduce
- Install Windows 10, WSL2, and Ubuntu 20.04 distribution on WSL2.
- Note your username when you create your first and primary Ubuntu user on install. You must replace
daleusername in below steps with your own username. apt updateandapt upgrade- Create
/etc/wsl.confto have content of[automount] options = "fmask=0027,dmask=0027,metadata" - Edit /etc/fstab to have 3 additional lines
C: /mnt/c drvfs rw,noatime,uid=1000,gid=1000,fmask=0027,dmask=0027,metadata 0 0- The second line should be a bind mount which binds a folder on your Windows C: drive (which
was mounted on the above line) to your Linux home directory. Remember to change usernames!
I chose to do with with my
.sshdirectory. Therefore, I firstmkdir /home/dale/.sshand then added the line/mnt/c/Users/Dale/.ssh /home/dale/.ssh none bind 0 0 - The third line should mount a network share, For example
//home-nas/dale /mnt/n drvfs rw,noatime,uid=1000,gid=1000,fmask=0027,dmask=0027,_netdev,nofail 0 0
- Exit your WSL session(s).
- Open a cmd prompt and run
wsl --shutdown - Open a WSL2 Ubuntu 20.04 prompt
- Verify your 3 mounts from
/etc/fstabare successful; C drive, your bind mount, and your network share. - Create a file
test.shin your Linux home directory, e.g./home/dale/test.sh, with the below content. Remember to change username and use the directory you bind mounted in step 5.ii above.#!/usr/bin/env bash LOGFILE="/home/dale/testout.log" whoami &> $LOGFILE ls -la $HOME &>> $LOGFILE ls -la ~/.ssh &>> $LOGFILE mount &>> $LOGFILE chmod 755 test.sh- Run Windows Task Scheduler
- On the right, click "Create Task..."
- Name
wsltest1 - Choose 2nd radio
Run whether user is logged on or not - Click "Configure for:" pulldown and choose
Windows 10 - Click top tab
Actions - Click bottom button
New... - Keep the default
Start a programat the top - Under program/script type
C:\Windows\System32\wsl.exe - To the right of Add arguments type
bash -lc "/home/dale/test.sh" - Click OK
- Click top tab
Settings - Verify/enable
Allow task to be run on demand - Click bottom right "OK"
- Enter your password as prompted
- Right-click on your newly created task "wsltest1" and choose
Run - Wait 2 seconds
- Inspect the output at
/home/dale/testout.log
Actual Behavior
mounts from /etc/fstab did not successfully occur. The testout.log output will show in sequence
- your username
- your home directory listing. However, notice that the bind mount for
/home/dale/.sshis not corrected listed. Instead, you only see the/home/dale/.sshdirectory that you created. This is easily seen by looking at the datetime and in the following... - the
.sshdirectory shows only the.and..entries. It does not list the files that should be from/mnt/c/Users/Dale/.sshdue to your bind mount - a long list of the mounts, however, there is no entry for your bind mount or network share mount
Expected Behavior
All mounts from /etc/fstab to successfully occur. The testout.log should show the correct
contents of your bind mount, and all three mounts should appear in the list of mounts.
WSL logs
Available at https://aka.ms/AA9ubkh
I didn't find something interesting in the logs, but I guess:
- wsl distros are user specific, so maybe
run only when user is logged onis supported. - mount file system may take time, I would suggest you
mount >> $LOGFILE 2>&1other thanmount &>> $LOGFILE. - It's also possible you need to execute mount first, then do
lsin test.sh
It is unclear to be what your 1-3 comments are. If you are suggesting workarounds for the bug/regression, then that is not needed. I already have a workaround for the actual scenario on my machines. The issue report I provide above is a short, clear, and isolated scenario so you can reproduce the WSL2 regression/bug.
- Thanks for the comment. Please follow my repro steps to reproduce the regression on your test machines.
- a. All executables take CPU time. And a bind mount should take nanoseconds. What are you asking or suggesting?
b.
&>>works fine in bash as it is a deprecated feature not eliminated. It correctly concats stdout/err. No action needed here. - That is not needed. My repro steps should be followed as written so you can reproduce the regression/bug.
If you have questions of me, please do ask them and I'll endeavor to get answers.
I can also confirm that /etc/fstab is ignored with the following configuration:
cat /etc/wsl.conf
[automount] enabled = true options = metadata,umask=22,fmask=11 mountFsTab = true
Is there any update on this? @diablodale what is your workaround?
Last time I tried, still doesn't work as expected.
As my current workaround, I have a task in task scheduler that runs at logon of my user, and that task does wsl.exe bash -lc exit. Doing it at this time (when I am also interactively logged in).
In this scenario, the mounts occur.
So on my computer, I have to always be interactively logged in, therefore I use a short screen lock and Windowskey-L now by habit.
Try add to /etc/wsl.conf
[boot]
command="mount -a"
or in boot script on windows:
wsl.exe -u root -e mount -u
/etc/wsl.conf
[boot]
command="mount -a"
This has no effect. Automount on boot still does not happen.
see #6073
Any update on this problem. Windows 11 still has the problem. It looks like the system ignores the file. Even if I change it for e.g swappiness or swapon... It cannot make it permanent. I made the change in the file, but everytime i reboot It does not read that change. Those files does not make sense in wsl booting.
It seems like /etc/fstab works fine with the following configuration:
WSL version: 1.2.5.0 Kernel version: 5.15.90.1 Windows version: 10.0.22000.2176
/etc/wsl.conf:
[automount]
# Automatically mount Windows drive when the distribution is launched plus /etc/fstab
enabled = false
# Sets the `/etc/fstab` file to be processed when a WSL distribution is launched.
# Redundant if enabled = true
mountFsTab = true
/etc/fstab:
# Mount a network drive
//JoeHost/E$ /mnt/re cifs uid=joe,gid=joe,user=joe,pass=shmo 0 0
# Mount local E:\ drive
drvfs /mnt/e 9p rw,noatime,dirsync,aname=drvfs;path=E:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio 0 0
wsl.conf is ignored when wsl2 is booted by task scheduler in condition "Run whether user is logged on or not". Is there any solution now? 😭
If you have systemd enabled with WSL 2 on Windows 10, there's no need to enable automount, as systemd will parse /etc/fstab and generate the corresponding mount units.
Here follows my current settings.
/etc/wsl.conf
[boot]
systemd=true
[automount]
enabled = false
mountFsTab = false
/etc/fstab
drvfs /mnt/c 9p rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio 0 0
drvfs /mnt/debian 9p ro,aname=drvfs;path=D:\,mmap,access=client,trans=virtio 0 0
$ uname -r -m
5.15.133.1-microsoft-standard-WSL2 x86_64
$ sudo systemctl list-units --type mount mnt-*
UNIT LOAD ACTIVE SUB DESCRIPTION
mnt-c.mount loaded active mounted /mnt/c
mnt-debian.mount loaded active mounted /mnt/debian
mnt-wsl.mount loaded active mounted /mnt/wsl
mnt-wslg-distro.mount loaded active mounted /mnt/wslg/distro
mnt-wslg-doc.mount loaded active mounted /mnt/wslg/doc
mnt-wslg-versions.txt.mount loaded active mounted /mnt/wslg/versions.txt
mnt-wslg.mount loaded active mounted /mnt/wslg
This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.
Thank you!