This shows you the differences between two versions of the page.
random:ubuntu_9_desktop_installation [2013/01/08 19:00] |
random:ubuntu_9_desktop_installation [2013/01/08 19:00] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== How to mount Windows shares on a Linux box ====== | ||
+ | |||
+ | === Introduction === | ||
+ | |||
+ | This guide will show you how to setup a mount of a remote windows share, and have it always there when you startup. | ||
+ | |||
+ | == Two methods, depending on share host == | ||
+ | |||
+ | * cifs | ||
+ | * smbfs | ||
+ | |||
+ | smbfs is the "original" method. | ||
+ | |||
+ | However, smbfs is not compatible with security signatures, which are enabled by default and not recommended to disable on Windows Server 2003 and later. If a share is served by Windows Server 2003 or later, you should use cifs. | ||
+ | |||
+ | In the following, it is more convenient (even though not recommended) to log in as root. I do this using the following command: | ||
+ | |||
+ | sudo bash | ||
+ | |||
+ | The system will prompt you for the root password. Do not forget to log off when you are done. | ||
+ | |||
+ | == Prerequisites == | ||
+ | |||
+ | You must have a windows machine (or other machine running Samba) with an accessible share. | ||
+ | |||
+ | The 'samba' package itself is not necessary if you only need a smb client. | ||
+ | |||
+ | The "smbfs" package provides the tools needed to mount "smbfs" and "cifs" filesytems. | ||
+ | You may have smbfs installed on your machine. If not, run | ||
+ | |||
+ | apt-get install smbfs | ||
+ | |||
+ | Update the unmount order to prevent CIFS from hanging during shutdown. | ||
+ | |||
+ | update-rc.d -f umountnfs.sh remove | ||
+ | update-rc.d umountnfs.sh stop 15 0 6 . | ||
+ | |||
+ | === Setup === | ||
+ | |||
+ | == Single User == | ||
+ | Note the UID of the single user which is to have access to the share. For a user named $username, the following command outputs the UID | ||
+ | |||
+ | grep $USERNAME /etc/passwd | cut -d: -f3 | ||
+ | |||
+ | == Multiple Users == | ||
+ | If multiple users are to have the same level of access to the share, then create a new user group, presumably named after the share. | ||
+ | |||
+ | Navigate to "System" -> "Administration" -> "Users and Groups" -> "Manage Groups". -> "Add Group" and select a name, Group ID (GID), and group members. Note the GID -- you will need it later. | ||
+ | |||
+ | == Credentials File == | ||
+ | Warning- this method is not completely secure, any user with root access could see your password in plain text. | ||
+ | |||
+ | Create a file called .smbcredentials in the /root directory. In this file put username an equals sign and the windows username (and domain if loging into a domain) on the first line, put password an equals sign and the password for that user account on the second line of the file. The file should look like: | ||
+ | |||
+ | username=MyWindowsUserID | ||
+ | password=MyWindowsPassword | ||
+ | |||
+ | The username and password for the Linux box have been created by Greg in MIS. Check with him to get them. | ||
+ | |||
+ | Then, go to the /root directory and change the permissions for .smbcredentials: | ||
+ | |||
+ | chown root .smbcredentials | ||
+ | chmod 600 .smbcredentials | ||
+ | |||
+ | this will ensure that only root can access this file. | ||
+ | |||
+ | == Editing fstab == | ||
+ | Warning- editing the fstab file can be dangerous, please back it up before continuing. | ||
+ | |||
+ | Note: if servername or sharename has a literal space (i.e. ' '), substitute \040 instead, so that 'server name' becomes 'server\040name' | ||
+ | |||
+ | Add a line at the bottom of your /etc/fstab file that specifies: | ||
+ | |||
+ | //$SERVER/$SHARE $MOUNTPOINT $FS_TYPE ip=$IP_ADDRESS,credentials=$SMB_CREDENTIALS,uid=$UID 0 0 | ||
+ | |||
+ | <code> | ||
+ | SERVER=STCK5 | ||
+ | SHARE=Public | ||
+ | MOUNTPOINT=/mnt/t | ||
+ | FS_TYPE=smbfs | ||
+ | IP_ADDRESS=10.168.1.36 | ||
+ | SMB_CREDENTIALS=/root/.smbcredentials | ||
+ | UID=1000 | ||
+ | </code> | ||
+ | |||
+ | //STCK5/Public /mnt/t smbfs ip=10.168.1.36,iocharset=utf8,credentials=/root/.smbcredentials,uid=1000 0 0 | ||
+ | |||
+ | == Ensure == | ||
+ | |||
+ | * The entire expression MUST all be on one line in your fstab file | ||
+ | * use "//" and "/" instead of "\\" and "\" when specifying the share location | ||
+ | * /path/to/mnt is a directory that exists (and is empty) | ||
+ | |||
+ | == Completing Setup == | ||
+ | Reload fstab: | ||
+ | |||
+ | mount -a | ||
+ | |||
+ | Make sure the shared drive has been mounted: | ||
+ | |||
+ | df | ||
+ | |||
+ | === Troubleshooting === | ||
+ | |||
+ | |||
+ | == Server is down, filesystem is hung == | ||
+ | |||
+ | If the client somehow loses contact with the Samba server, then the filesystem will probably get hung. Basically, it becomes a blackhole, eating things that try to read to/write from it (e.g. '' ls '') and refusing to go away (e.g., '' umount '' says that the "device is busy"). | ||
+ | |||
+ | Sometimes, all you need to do is restart the Samba daemon on the server machine. | ||
+ | |||
+ | /etc/init.d/samba restart | ||
+ | |||
+ | If that doesn't work, or for some reason you can't do anything on the server side, then try | ||
+ | |||
+ | umount -lf /mount/point | ||
+ | |||
+ | The '' -f '' option forces (possibly unclean) unmounting, and the '' -l '' option is for "lazy unmounting", and seems to work around "device is busy" errors that occur with just '' -f ''. | ||
+ | |||
+ | == System Hangs on Shutdown == | ||
+ | |||
+ | Sometimes during shutdown, networking will be turned off before the network share is unmounted. This will cause the computer to display the below code for a few minuets before shutting down (the numbers seem to change after each boot). | ||
+ | |||
+ | CIFS VFS: server not responding | ||
+ | CIFS VFS: no response for cmd ## mid ### | ||
+ | |||
+ | To fix this problem, and allow the computer to shut down smoothly, just change when the network share is unmounted by the file system. This can be done by running the following commands: | ||
+ | |||
+ | update-rc.d -f umountnfs.sh remove | ||
+ | update-rc.d umountnfs.sh stop 15 0 6 . | ||
+ | |||