Mount Windows共享文件夹到Linux目录

时间:2023-01-26 21:25:10

Check which shares are available for mount

Now before you mount you can also check which shares (folders/drives) are available on your Windows machine that you can mount by giving the following command:
# smbclient -L infohighway -U kushal
where
infohighway = Name (NetBIOS Name) of my computer
kushal = Username on my Windows Machine

Password:

You will get an output similar to this:
Domain=[HOME] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
Sharename Type Comment
--------- ---- -------
myshare Disk
IPC$ IPC Remote IPC
mydownloads Disk
ADMIN$ Disk Remote Admin
C$ Disk Default share
Domain=[HOME] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
Server Comment
--------- -------
Workgroup Master
--------- -------

From the above output you can see that I have shared folders called “myshare” and “mydownloads” on my Windows XP machine as highlighted in bold letters. This means that I can mount these folders on my Linux machine.

Mount the Windows Share

Now the real thing. There are two ways to mount: The traditional SMBFS or the newer CIFS. It seems that CIFS is going to replace SMBFS which will soon become obsolete. I will show you both the methods:

SMBFS Method Command (Old/Deprecated/Not Recommended):
# mount -t smbfs -o username=kushal,password=******** //infohighway/drivers /mnt/
where
kushal = Username on my Windows Machine
******* = Password for the user 'kushal'
infohighway = Name (NetBIOS Name) of my computer
drivers = Windows folder shared on my Windows XP machine
/mnt = Target mount directory on my Linux Machine

CIFS Method Command:
# mount -t cifs //infohighway/drivers /mnt/ -o username=home/kushal,password=*********
where
home = DomainName/Workgroup of your LAN network
Rest of the parameters are same as in SMBFS

Note:If you get any error messages after you give the mount command refer to the “Some typical errors” section below.

Now you can access the contents of the Windows share now by giving the command:
# ls /mnt/drivers
# ls /mnt/
audio INFCACHE.1 network Security storage video
#

Some typical errors:

You might see some typical error messages as follow in case if you missed any steps above:

Error 1:CIFS VFS: cifs_mount failed w/return code = -22

Solution:apt-get install smbfs

Error 2: smbfs: mount_data version 1919251317 is not supported

Solution:apt-get install smbfs

You can see the above error messages (if they do occur) by giving the following command just after you issue the mount command as mentioned in Step 5 above:

# dmesg | tail

Error 3: mount error 13 = Permission denied

Solution:Give the name of your Domain/Workgroup as shown in bold letter in Step 5 when mounting with CIFS method otherwise you will likely get this error message