How to Dual Boot Windows 11 and Linux

How to Mount Windows Folders from Linux

If you’ve been looking for a solution on how to mount Windows folders on Linux, we’ve got just the right guide for you to follow. 

Mounting Windows OS folders on your Linux system is possible depending upon your Linux distribution, and the Windows folders are automatically mounted on Linux. However, this may need to be revised. Note that Linux and Windows have significant file system differences. Sharing files between them can be difficult as they may use two different sharing protocols. 

We will first discuss how we can share folders from Windows. Then, we will discuss how the shared folder can be accessed from Linux using CIFS. We will also discuss how a folder shared from Linux can be accessed on Windows using samba. Finally, we will see how shell scripting can mount a folder from Linux.

Note: While mounting the Windows folder from Linux, Linux doesn’t honor the access control list that NTFS maintains, so permissions are ignored. If you are really concerned, Windows have the option to encrypt your hard disk.

How to Mount Windows Folders from Linux Using CIFS

The easiest and safest way to mount Windows folders on Linux is via using the CIFS-utils package. Then, you will be able to mount the folder on Linux. The following paragraphs discuss setting up the CIFS-utils package to mount Windows files.

Sharing file system from Windows

Before proceeding with the setup on Linux, ensure you have shared the file correctly in Windows. Follow the steps below:

  • First, open the “Network Sharing and Internet Settings”. For Windows 10 users, it is located at Settings > Network & Internet > Status > Network and Sharing Center. In Windows 11, you can find the network sharing option in Control Panel > Network and Internet > Network and Sharing Center. From the status category, select “Sharing Options”. 
Sharing options
  • In the Windows Sharing option, ensure that “Turn on network discovery” and “Turn on file and printer sharing” are enabled. Click save changes to save your changes.
Advanced sharing setting
  • Now locate the folder you want to share. Right-click on the folder and select the properties.
  • Click the sharing tab and then Advanced sharing.
Share folder
  • Enable the “Share this folder” checkbox.
  • Provide the desired permissions.
  • Click OK to close the dialog box.

Now, we will move towards the steps to be applied to Linux.

Install the CIFS-utils

The very first step is to install the CIFS-utils. For this purpose, open your terminal and then type the following command first to update your system and then install the cifs-utils package:

$sudo apt update
$sudo apt install cifs-utils


The above command will work for Ubuntu and Debian. The arch users may try the following command:

$pacman -S cifs-utils


For CentOS and Fedora, you should try the following command:

$sudo dnf install cifs-utils


After the installation, you can mount the Windows shared folder on Linux.

Create a mount directory

First, you will create a directory where Linux will mirror the shared folder’s contents. Open your Terminal and type the following command:

$sudo mkdir /mnt/share


Mount the folder

Now, you can mount the folder with the help of the following command:

$sudo mount.CIFS //Windows/SharedFolder /mnt/share -o user=account


Here, replace the Windows with the name or internet protocol (IP) address. Also, replace the SharedFolder with the name of your shared folder. For the user name, replace the account with your Windows user name or Microsoft account email. You will be prompted for the password. Upon success, no output will be produced. You can also provide the password on the command line as follows:

$sudo mount.cifs //Windows/SharedFolder /mnt/share -o user=account, password=abc


You can also provide a domain or workgroup as follows:

$sudo mount.CIFS //Windows/SharedFolder /mnt/share -o user=account, domain=domain, password=abc

Note: Now, you can verify that the Windows shared folder is successfully mounted using the commands “mount” or “df –h”.

After the shared files are mounted, the mount folder becomes the root directory of the mounted file system. Even you can work with remote files as they are local files.

Mounting a folder permanently

If you want to mount a windows folder permanently in Linux, edit /etc/fstab file and add the following line:

//servername/sharename  /media/windowsshare  cifs  guest,uid=1000,iocharset=utf8  0  0

Then use the following command:

$sudo mount –a

The above command will mount all the entries listed in /etc/fstab.

Unmount a shared folder

You can also unmount a shared folder by using the following command on Linux:

$sudo umount ~/WindowsShare/


Mounting the Windows shared files from Linux using Samba

We can also use the samba to mount access to Linux files on Windows. Follow the steps below.

Install samba

First, install the samba using the following command on your Terminal:

$dnf install samba


Modify LinuxSE

In case your system is protected by LinuxSE, enable samba to access your home directory using the following command:

$setsebool -P samba_enable_home_dirs on

You can verify if the value is correctly set by using the following command:

getsebool samba_enable_home_dirs


Enable your user

Samba requires specifying the users that can connect. For this purpose, use the following command:

$smbpasswd -a <your-user>


You can check the list of allowed user types using the following command:

$pdbedit -L –v


You can also remove a user using the following command:

$smbpasswd -x <user-name>


Start samba

You can start the samba via the following command:

$systemctl start smb


To enable samba to start automatically on system startup, use the following command:

$systemctl enable smb

Configure the firewall

Now you need to enable the samba to access the network via configuring the firewall. For this purpose, type the following command:

$firewall-cmd --add-service=samba --permanent


Access folder from Windows

Now you can access the Linux folders in Windows. For this purpose, open Windows explorer and type the address of the Linux machine preceded by two backslashes. Provide the username and password. You should now be able to access your home directory.

Using a shell script to mount Windows folder on Linux

You can use the shell script to mount the Windows folder on Linux. Following is the shell script:

 

user=linuxuser

pass=passwd4user

wincp=//win_hostname

winpath=/win_directory

linuxpath=/linux_mntdir 

fstab_line=$wincp$winpath /mnt$linuxpath smbfs

 username=$user,password=$pass 0 0 

/etc/init.d/smb start

echo $fstab_line >> /etc/fstab

mount –a

This article discusses how we can mount a Windows shared folder on Linux using CIFS. We also discussed accessing a Linux-shared file/folder on Windows. We also discussed how shell scripting could be used to mount Windows folders on Linux. Note that mounting a drive may cause performance issues. In these cases, you may want to perform CIFS performance tuning, such as setting CIFSMaxBufSize.

If this guide helped you, please share it.

Leave a Reply
Related Posts