Using smbmount

The SMB filesystem (smbfs) allows you to mount SMB shares, and use them as if they were part of the Linux filesystem. For this to work, the kernel must support the smbfs filesystem. Listing 9.12 shows a quick check for kernel support of smbfs.

Listing 9.12: Checking Iproclfilesystems

[root]# modprobe smbfs

[root]# cat /proc/filesystems nodev proc nodev sockfs nodev tmpfs nodev shm nodev pipefs ext2 iso9660 nodev devpts ext3 vfat nodev autofs nodev smbfs

The /proc pseudo filesystem provides a glimpse into the kernel. The pseudo file /proc/filesystems lists the filesystems that are in the kernel, either because they are compiled in or configured as loadable modules. Of course, loadable modules are not loaded unless they are needed, so Listing 9.11 starts with a modprobe command to force smbfs to load. If smbfs does not load, the kernel may need to be reconfigured as described in Chapter 13.

Shares can be mounted using the smbmount command and dismounted using the smbumount command. Listing 9.13 mounts the same share shown in the smbclient example by using smbmount.

Listing 9.13: An smbmount Example

[root]# smbmount //robin/temp /home/robin workgroup=sybex

Password:

/home/robin/alana1_0.jpg /home/robin/alana4_0.jpg /home/robin/alana7_0.jpg /home/robin/alana2_0.jpg /home/robin/alana5_0.jpg /home/robin/alana3_0.jpg /home/robin/alana6_0.jpg

The ls command at the start of Listing 9.13 shows that /home/robin is an empty directory, which we will use as a mount point (the location within the Linux filesystem at which the share is mounted). The smbmount command starts with the name of the share written in Microsoft UNC format. The share name is followed by the name of the Linux mount point. A list of options follows the mount point. In this case, workgroup is the only option required.

After it is mounted, the share has essentially the same look and feel of any Linux directory, and most standard Linux commands can be used to manipulate the files in the share directory. (Listing 9.13 shows an ls of certain files in the directory.) Of course, not everything is the same on Linux systems and Windows systems. Some features of the Linux filesystem are not available from all SMB servers. For example, a Windows 95/98/ME system offering a share does not have file-level security, nor does it understand Linux UIDs and GIDs. smbfs does its best to "fake it." It uses the UID and GID in force when smbmount was started. You can override these defaults with command-line options. For example, the following tells smbfs to use the UID 689, presumably the UID assigned to tyler; and the GID 100, which is the GID of users:

smbmount //crow/user/tyler /home/tyler/crow \

username=tyler password=Wats?Watt? uid=689 gid=100

To dismount an SMB share, use the smbumount command with the path of the mount point:

[root]# smbumount /home/robin

Shares can also be mounted from the fstab file using the mount command with the -a and the -t smbfs arguments. Red Hat uses this technique to mount Samba shares in the netfs startup script. To do this, the Samba share must be defined in the fstab file. For example, to mount the Samba share used in Listing 9.13, the following entry could be added to the fstab file:

//robin/temp /home/robin smbfs workgroup=sybex 0 0

Here, the filesystem name is the UNC-formatted name of the remote share, and the filesystem type is smbfs. When the mount command is invoked with -t smbfs, it transfers control to the program /sbin/mount.smbfs. On a Red Hat system, /sbin/mount.smbfs is just a symbolic link to smbmount. The values in the first four fields of the fstab entry are passed to smbmount for processing.

smbfs makes using SMB shares on a Linux client much easier than accessing those shares through smbclient.

Was this article helpful?

0 0

Post a comment