55

I know there are similar questions but I get some specific problem I can't overcome.

I have:

  • HDD split into two partitions. /dev/sdb1 and /dev/sdb2. sdb1 is NTFS and I don't need it. I need sdb2 which is fat32.
  • Ubuntu 12.04.1 LTS (server)

I want:

Ultimately I need a perma-mount /dev/sdb2 to /home/storage with access right (rw) for the user media.

Problems I'm facing:

Using manual mount from command line.

If I just use

server# sudo mount /dev/sdb2 /home/storage

It mounts but the /home/storage receives root as owner and group and doesn't allow media user to write there.

If I use mount command without sudo as the user media - i'm not allowed. Says only root can use mount.

If I use mount with options: server# sudo mount /dev/sdb2 /home/storage -o umask=000 I get what I need. A bit overdone of course, since the storage folder becomes writable for everyone. BUT - that is manually mounted - now i need it to remount on every reboot.

Remounting on reboot - using fstab**

So I thought I'll be fine if I use fstab to mount this partition (/dev/sdb2) every time i reboot. The fstab line I added:

UUID=8C52-C1CD /home/storage auto   user,umask=000,utf8,noauto  0   0

Got uuid with blkid. The fs type auto I changed a few times... I tried vfat too, but always on the reboot Ubuntu stops when processing fstab (I think) with the message (took from the log):

fsck from util-linux 2.20.1
/dev/sda5: clean, 120559/10969088 files, 19960144/43861504 blocks
mount: unknown filesystem type 'static'
mountall: mount /etc/fstab: [772] terminated with status 32
mountall: Filesystem could not be mounted: /etc/fstab:
Skipping /etc/fstab: at user request

And also - sudo mount -a never really does anything.

What am I doing wrong? I do suspect I messed up something:)

It seems fstab should hold only mounts for static drives, not any sort of usb stuff. I'm puzzled how then this works with all the people posting on the net their success stories...

However... if this is not possible - I would like to know how to remount my USB after every reboot... if not with fstab - then how? :)

5
  • I think you should post all of fstab for review, and not just one line. As for the right permissions, run id media and use uid= and gid= and umask=027options. Feb 4, 2013 at 15:35
  • 1
    Is there some reason you need to use FAT ? If not, I would back up the data and use a linux native file system. You can then set ownership and permissions.
    – Panther
    Feb 4, 2013 at 18:27
  • @mikewhatever thanks but it's working strangely actually... well..not really:) Feb 4, 2013 at 22:28
  • @bodhi.zazen did more reading... seams like on ubuntu 12 fstab should have only mounts for static drives. not any usb... Feb 4, 2013 at 22:29
  • 1
    run the id cmd and use the mount options of your id and group thus allowing your $USER account to read/write the drive. use -o uid=[UID],gid=[GID] the UID and GID can be gathered from the running the id cmd.
    – ipatch
    Aug 7, 2022 at 20:53

5 Answers 5

58

Your problem seems to be about the permissions you have set. FAT / FAT32 formatted drives don't support file permissions. The permissions for everything are determined by how the drive is mounted. When you set the permission open it worked when you

server# sudo mount /dev/sdb2 /home/storage -o umask=000

As for it not auto mounting on reboot

UUID=8C52-C1CD /home/storage auto user,umask=000,utf8, -->noauto<-- 0 0

The "noauto" makes this NOT automatically mount when the system starts and parses the /etc/fstab file. Remove that option and it will mount on startup. You can set the permissions on the mount point once it's mounted with chmod or specify them in /etc/fstab.

If you need the media user to access it, you can set the permissions to 764, and add them to the security group. Root always has access to everything.

see http://www.linux.org/threads/file-permissions-chmod.4094/ for some examples of propper file permissions

On a side note, bodhi.zazen made a good point Is there some reason you need to use FAT ? If not, I would back up the data and use a linux native file system. You can then set ownership and permissions.

3
  • 9
    -o umask=000 is it!! Thank you!
    – Antony
    Aug 7, 2015 at 1:52
  • 1
    I already have tried many ways on internet to create a writable unit... '-o umask=000' this help. Very thanks Mar 30, 2021 at 16:01
  • only answer that worked for me
    – Matt
    Apr 8, 2023 at 17:50
5

Note: as mentioned in the comments below, be careful using 0777 permissions: it means anyone, or any script, on the machine can write to the drive. With that caveat in mind, this can sometimes be a useful fix in a pinch:

You can also run

sudo chmod 0777 /home/storage

Since FAT drives don't have permissions, linux applies the permission of the mount point to the entire drive.

7
  • 4
    Never apply R+W+X permissions for every user.. This would allow anyone or anything to access,execute,delete,modify storage and its contents....
    – Angry 84
    Sep 23, 2016 at 4:10
  • 2
    On most operating systems, USB drives are mounted so any user can modify the contents. If you are a server admin in a situation where this could be an issue, I wouldn't have to tell you what 0777 means.
    – Zane
    Sep 26, 2016 at 4:18
  • 1
    Drives are never mounted by default to allow all users, This is why they have groups and permissions. Either way its always safer to show a better security mod as people will simply copy and paste without knowing better
    – Angry 84
    Sep 26, 2016 at 5:25
  • Works like a charm. @Angry84 Anyone, like a malicious script?
    – Quidam
    Jun 7, 2020 at 4:17
  • while i would not use 0777, the idea went into the correct direction and is therefore a helpful answer for some.
    – kaiya
    Nov 12, 2020 at 11:08
4

Unless overridden by mount options GID= or UID= the owner and permissions of the mount point upon mounting become those of the filesystem tree being mounted.

So if /dev/sdb1 contains an ext4 filesystem (say a backup) owned by user then user will become the owner of the mount point upon successful mount.

Starting off we have an empty folder 'backup' to serve as the mount point, and is owned by root.

# ls -alR /mnt
/mnt/:
drwxr-x---  5 root root 4096 May 30 20:59 ./
drwxr-xr-x  3 root root 4096 Dec  5  2015 ../
drwx------  2 root root 4096 Jan  1 07:45 backup/

/mnt/backup:
drwx------  2 root root 4096 Jan  1 07:45 .
drwxr-x---  5 root root 4096 May 30 20:59 ..

now we mount /dev/sdb1 (read-only)

# mount -o ro /dev/sdb1 /mnt/backup

and lets see...

# ls -alR
/mnt/:
drwxr-x---  5 root root 4096 May 30 20:59 ./
drwxr-xr-x  3 root root 4096 Dec  5  2015 ../
drwx------  2 user user 4096 Jan  1 07:45 backup/

/mnt/backup:
drwx------  2 user user 4096 Jan  1 07:45 .
drwxr-x---  5 root root 4096 May 30 20:59 ..
-rw-------  1 user user 252076021760 Jun  9 21:11 backup.tar

Now if you've got an empty drive and you want to mount it for 'user' as an extension of 'user's disk space, mount the drive as root, chown the root of the mount to 'user' and unmount.

The next time the filesystem is mounted (by root or anyone as per fstab) the owner of the mount will be 'user'.

0

Without mounting to /home/storage (very fast):

$ pcmanfm  
$ df -h  
... /dev/sdb2 ...  
$ chown -hR user:group /media/user/a13*  
-1

If you do have external storage device connected to your Linux box with NTFS, make sure that the filesystem is clean.

Before you mount the storage to your Linux box:

  1. Run the below command

    ntfsfix /dev/storagedevice ( like sdb1 or sdc1 )  
    
  2. Reboot your Linux box

  3. Mount the external storage by running the command:

    mount -o rw /dev/storagedevice /media/ 
    

    or

    mount -o rw /dev/storagedevice /mnt/ 
    

    or mount the storagedevice via GUI.

1
  • 2
    What is your reasoning behind each of these steps?
    – Ken Ingram
    May 4, 2020 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .