How to auto mount FAT32-formatted drives in Samba

You might have a FAT32-formatted drive that needs to be shared out to users. To do that with write permissions, you must make use of fstab. Jack Wallen shows you how.

Image: Jack Wallen

If you use Samba, chances are you have shares up and down your drives that work seamlessly on your network. Many of those drives are probably formatted as ext3, ext4, or btrfs. But what happens when you have a drive that is formatted as a FAT32? You might find automounting that particular drive a bit problematic. Why? Permissions.

Every time you mount that drive, you'll probably find that users are unable to access either the drive or the data on said drive. What do you do? The answer is actually quite simple.

Let's find out how this is done.

SEE: Securing Linux policy (Tech Pro Research)

What's going on

By default, a FAT32 partition will mount as owner=group=root with permissions of 755 (drwxr-xr-x). As you can see, the permissions only allow for read access to group and other, which means only the owner is given write access. In most cases, that will not do. Getting around this involves the fstab file.

Configuring FSTAB

Let's say you have drive /dev/sdc1 which is formatted as FAT32, and you want to mount that in the directory /mnt/data, such that users receive write access. In order to do that, you must edit the fstab file. Issue the command:

sudo nano /etc/fstab

In that file, add the following to the bottom (adjusting to fit your needs):

/dev/sdc1 /mnt/data vfat dmask=000,fmask=111 0 0

Save and close that file. Issue the command sudo mount -a to mount all drives found in fstab. You shouldn't see any errors returned. At this point, anyone that mounts the shared drive should have read and write access to the data it contains.

One caveat

Because drive names can change, it's better to mount in fstab with the UUID instead of the drive name. To find the UUID of a drive, issue the command (assuming we're still working with /dev/sdc1):

blkid /dev/sdc1

You should see output similar to that in Figure A.

Figure A

Figure A

The UUID of a drive mounted in Linux.

With the UUID known, the fstab entry would then be:

UUID=XXX /mnt/data vfat dmask=000,fmask=111 0 0

where XXX is the UUID of the drive in question.

Save and close the file. Mount the drives listed in /etc/fstab with the command:

mount -a

Your users should now be able to access the data found in the FAT32-formatted, Samba-mounted drive.

Also see