Sunday, April 12, 2015

Mount external hard drive with write permissions

This post has been created to keep a track of this very usual issue that I encountered recently. There are many discussions around it already but I thought that adding a very simple article with a few explanations couldn't harm. So here it is.

Linux permissions do not apply to VFAT external drives

When auto-mounted, you may see with a simple ls -la that the mounted partition is not accessible with write permission. No matter how many chmod you do, the result will remain the same : no write access. Don't worry, this is a normal behavior as the FAT32 filesystem do not support linux permissions.

Forget auto-mount

To resolve this issue, you should reconsider it. The permissions do not apply to the partition but they do to the mount point. It means that you'll have to tell linux to grant write permissions at mounting time.

Unmount your disk

umount /dev/sda1

Now mount it back with the following options

mkdir /mnt/mydisk
mount -t vfat /dev/sda1 /mnt/mydisk -o umask=0

It should now work as expected. The key option is umask which is the opposite mask to the one you give to chmod. 0 means that all users have all rights (Note: keeping it like this may be dangerous)

Automatically mount the disk at startup

This is done by editing the /etc/fstab file. Simply add the following line to it

UUID="BF12-2F81" /mnt/mydisk vfat  defaults,uid=me,gid=mylinux,umask=0    0    0

The UUID is the unique identifier of your disk (you can get it by running blkid in a console).
As you can see, I have added uid (user) and gid (group) options to allow one specific user to have write access on my disk.

A few reminders

If you're used to have your disk mounted on  /media and you're wondering why /mnt is often used, here is the explanation :

/media is usually used for auto-mounted disks
/mnt is the one that should be used when manually mounted
Read More