在之前的教程中,我们介绍了如何在家庭网络上的(home network)Ubuntu 和 Windows(Ubuntu and Windows) 7 计算机之间共享文件。本教程将补充以前的教程,并展示如何让Ubuntu从Windows 7自动挂载(Ubuntu auto-mount)分区或文件夹(partition or folder),以便您从登录Ubuntu的那一刻起就可以随时访问它。这个过程有些复杂,但一旦你第一次做,第二次或第三次做起来会更容易。
注意:(NOTE:)本教程已更新为适用于Ubuntu v10.10和 11.04。
第 1 步(Step 1):在同一工作组(Same Workgroup)中配置计算机(Computers)
为了让Ubuntu 和 Windows(Ubuntu and Windows) 7 轻松共享文件,必须将它们配置为位于同一个Workgroup中。
要更改您的Windows 7工作组,请参阅:如何更改Windows 7中的工作组(Workgroup)。
要更改您的Ubuntu 工作组(Ubuntu workgroup),请参阅:如何在Ubuntu Linux中启用(Ubuntu Linux)文件共享和更改(File Sharing & Change)工作组(Workgroup)。
一旦工作组(Workgroup)在两台计算机上设置为相同,请继续本教程的下一部分。
第 2 步(Step 2):在 Windows PC 上配置共享文件夹和共享选项(Configure Shared Folders and Sharing Options)
如果您尚未在Windows PC上设置共享文件夹,您现在需要这样做。这涉及两个子步骤,我们为此编写了单独的教程:
- 1)修改网络(Modify network)共享设置,启用网络发现和文件共享(network discovery and file sharing);
- 2) 配置您的共享文件夹(另请参阅:使用(See)高级共享(Advanced Sharing)共享库或文件夹)。
第 3 步(Step 3):设置Ubuntu以从Windows 7 PC自动挂载文件夹或分区(folder or partition)
首先,您必须打开一个终端(Terminal)窗口。从顶部菜单栏中(menu bar),单击应用程序(Applications),然后单击终端(Terminal)。

在终端窗口(Terminal window)中写入以下内容sudo mkdir /media/mountname,然后按Enter。将mountname替换为要挂载的文件夹或分区(folder or partition)的名称。在下面的示例中,我安装了我的 Windows 7音乐(Music)文件夹,所以我输入:sudo mkdir /media/music.

接下来将要求您输入密码,输入密码并按Enter。然后,在终端(Terminal)窗口中写入以下内容:sudo gedit /etc/fstab并按Enter。

fstab文件(文件系统(s)表文件)将在gedit(f)窗口中(gedit)打开(tab)。Gedit相当于Ubuntu中的记事本(Notepad)。在fstab文件的末尾,您必须写下这一行://servername/sharename /media/mountname cifs username=myusername,password=mypassword 0 0。
替换以下内容:
- servername与共享文件夹或分区的(folder or partition)Windows 7 PC 的名称。在我们的示例中,这是george-pc 。
- sharename是(sharename)Windows 7中(Windows 7)文件夹或分区(folder or partition)的原始名称。在我们的例子中是音乐(music)。
- mountname将是您之前在终端窗口(Terminal window)中写入的文件夹的名称。
- myusername是Windows 7 用户帐户(user account)的名称,mypassword是与(mypassword)Windows 7中定义的用户帐户(user account)对应的密码。在我们的例子中,用户帐户(user account)是george,密码是 pass。
在我们的示例中,整行代码将如下所示//george-pc/music /media/music cifs username=george,password=pass 0 0:

注意:(Note:)注意不要在用户名、逗号和密码之间留下任何空格。如果这样做,文件夹或分区(folder or partition)的自动挂载将不起作用。
完成后关闭gedit窗口。
现在在终端(Terminal)窗口中输入sudo mount -a并按Enter。这将使安装的分区文件夹出现在您的Ubuntu 桌面(Ubuntu Desktop)上。

注意:(Note:)为了让Ubuntu从Windows 7 PC自动挂载文件夹或分区(folder or partition),该 PC 需要打开并连接到与Ubuntu 系统(Ubuntu system)相同的网络。
如何从Ubuntu中删除已挂载的(Ubuntu)文件夹或分区(Folder or Partition)
要删除已安装的文件夹或分区(folder or partition),您必须打开终端(Terminal),然后使用以下命令打开geditsudo gedit /etc/fstab:。在gedit 窗口(gedit window)中删除您之前添加的行 ( //servername/sharename /media/mountname cifs username=myusername,password=mypassword 0 0)。默认情况下,它应该是最后一个。
现在关闭gedit和终端(Terminal)。下次打开 Ubuntu 时,文件夹或分区(folder or partition)将不再挂载。
结论
在包含Windows 7和Ubuntu计算机的网络上,您可以将Ubuntu配置为共享文件和文件夹,这些文件和文件夹可从(Ubuntu)Windows PC轻松访问。如果您想了解有关在本地网络上设置其他 PC 的更多信息,或者如何进一步利用Ubuntu Linux 和 Windows(Ubuntu Linux and Windows) 7 之间的网络功能,请查看下面列出的文章。
Mount Windows 7 Shared Partitions & Folders in Ubuntu
In previous tutorials we have cоvered how to share files between Ubuntu and Windowѕ 7 computers on your home netwоrk. This tutorial will complement previous ones and show how to make Ubuntu auto-moυnt a partition or folder from Windowѕ 7 so that you cаn always have access to it from the second you log in to Ubuntu. The procedure has some comрlexity but once you do it the firѕt time, it will be easier to do it a seсond or third time.
NOTE: This tutorial updated to work on Ubuntu v10.10 & 11.04.
Step 1: Configure the Computers on the Same Workgroup
In order for Ubuntu and Windows 7 to easily share files, they have to be configured so that they are on the same Workgroup.
To change your Windows 7 workgroup, see: How to Change the Workgroup in Windows 7.
To change your Ubuntu workgroup, see: How to Enable File Sharing & Change the Workgroup in Ubuntu Linux.
Once the Workgroup is set up to be the same on both computers, proceed to the next section of this tutorial.
Step 2: Configure Shared Folders and Sharing Options on Your Windows PC
If you have not already set up a shared folder on your Windows PC, you'll need to do so now. This involves two sub-steps for which we've written individual tutorials:
Step 3: Setup Ubuntu to auto-mount a folder or partition from a Windows 7 PC
First, you have to open a Terminal window. From the top menu bar, click on Applications and then on Terminal.

In the Terminal window write the following sudo mkdir /media/mountname and press Enter. Substitute mountname with the name of the folder or partition that you want to mount. In the example below, I mounted my Windows 7 Music folder, so I typed: sudo mkdir /media/music.

Next you will be asked for your password, type it in and press Enter. Then, write in the Terminal window the following: sudo gedit /etc/fstab and press Enter.

The fstab file (file system table) will open in a gedit window. Gedit is the equivalent of Notepad in Ubuntu. At the end of the fstab file, you have to write this line: //servername/sharename /media/mountname cifs username=myusername,password=mypassword 0 0.
Replace the following:
- servername with the name of the Windows 7 PC that is sharing the folder or partition. In our example this is george-pc.
- sharename is the original name of the folder or partition in Windows 7. In our case that is music.
- mountname will be the name of folder that you wrote in the Terminal window earlier.
- myusername is the name of the Windows 7 user account and mypassword is the password that corresponds to the user account defined in Windows 7. In our case the user account is george and the password is pass.
The whole line of code will look like this in our example: //george-pc/music /media/music cifs username=george,password=pass 0 0.

Note: Be careful not to leave any spaces between the username, the comma and the password. If you do, the auto-mount of the folder or partition will not work.
Close the gedit window once you have finished.
In the Terminal window now type sudo mount -a and press Enter. This will make the mounted folder of partition appear on your Ubuntu Desktop.

Note: In order for Ubuntu to auto-mount a folder or partition from a Windows 7 PC, that PC needs to be opened and connected to the same network as the Ubuntu system.
How to Remove a Mounted Folder or Partition from Ubuntu
To remove a mounted folder or partition you have to open the Terminal, then open gedit using this command: sudo gedit /etc/fstab. In the gedit window remove the line you previously added (//servername/sharename /media/mountname cifs username=myusername,password=mypassword 0 0). By default, it should be the last one.
Now close gedit and the Terminal. Next time you open Ubuntu the folder or partition will no longer be mounted.
Conclusion
On a network with Windows 7 and Ubuntu computers, you can configure Ubuntu to share files and folders which are easily accessible from a Windows PC. If you want to know more about setting up other PCs on a local network, or how to further utilize the networking features between Ubuntu Linux and Windows 7, check out the articles listed below.