Windows Subsystem for Linux (WSL) is a compatibility layer that allows you to run Linux distributions, such as Ubuntu, directly on your Windows computer. With WSL, you can access the powerful tools and utilities of Linux without the need for a separate virtual machine or dual-boot setup.
One of the convenient features of WSL is the ability to automatically mount your Windows drives within the Linux environment. This allows you to easily access and work with your Windows files from the Linux command line. However, there may be situations where you want to restrict certain drives from auto-mounting in WSL. In this article, we will guide you through the process of achieving this on Ubuntu 20.04.
To begin, open the WSL terminal by searching for "Ubuntu 20.04" in the Windows Start menu. Once the terminal is open, follow the steps below:
- First, you need to identify the drive letters of the drives you want to restrict from auto-mounting. To do this, run the following command in the WSL terminal:
$ sudo fdisk -l
This command will display a list of all the drives connected to your system along with their corresponding drive letters. Make note of the drive letters you want to restrict.
- Next, you will need to edit the WSL configuration file. Run the following command to open the file in a text editor:
$ sudo nano /etc/wsl.conf
If the file doesn't exist, it will be created. You may be prompted to enter your password.
- In the text editor, add the following lines:
[automount]
enabled = true
options = "metadata,umask=22,fmask=11"
mountFsTab = false
These lines enable the automount feature and specify the default options for mounting drives. The "metadata" option ensures that the drives are mounted with proper permissions.
- Now, you need to define the drives you want to restrict from auto-mounting. Below the lines you added in the previous step, add the following lines:
[automount]
disabled = true
root = /
options = "metadata,umask=22,fmask=11"
Replace "/" with the drive letters you want to restrict, separated by commas. For example, if you want to restrict drives C and D, the line would be:
root = /mnt/c,/mnt/d
- Save the changes and exit the text editor by pressing
Ctrl + X, thenY, and finallyEnter.
That's it! The drives you specified will no longer be automatically mounted when you start WSL. If you want to mount them manually in the future, you can still do so using the mount command.
By following these steps, you can easily restrict certain drives from auto-mounting in Windows Subsystem for Linux (WSL) with Ubuntu 20.04. This allows you to have more control over which drives are accessible within your Linux environment.
References
| 1. | Microsoft Docs - Windows Subsystem for Linux Documentation | https://docs.microsoft.com/en-us/windows/wsl/ |
| 2. | Ubuntu Documentation - Windows Subsystem for Linux | https://help.ubuntu.com/community/WindowsSubsystemForLinux |