3

Update: As it turns out, this was due to a bug in libmount, now fixed upstream. https://github.com/karelzak/util-linux/issues/1235

Original question follows

When I run mount -r /media/sdd1 the device is mounted read-write, with no warning or sign that the -r option failed.

$ egrep sdd1 /etc/fstab
/dev/sdd1   /media/sdd1 auto    user,noauto,exec,nodev  0   0
$ umount /media/sdd1
umount: /media/sdd1: not mounted
$ mount -r /media/sdd1
$ touch /media/sdd1/file.tmp
$ umount /media/sdd1
$ mount -r /media/sdd1
$ ls /media/sdd1/file.tmp
/media/sdd1/file.tmp
$ rm -f /media/sdd1/file.tmp
$ umount /media/sdd1
$ mount -r /media/sdd1
$ ls /media/sdd1/file.tmp
ls: cannot access '/media/sdd1/file.tmp': No such file or directory

This is potentially destructive, e.g. if I forget that I shouldn't write to the filesystem. The filesystem type I've tried it with is FAT16, if that matters.

Is there anything I can do to make mount honour the -r flag, besides removing the user flag to force myself to use sudo always?

7
  • What distro is this? I've recreated your situation and mount -r works fine.
    – kevlinux
    Commented Jan 14, 2020 at 4:26
  • @kevlinux Debian Stretch, mount 2.29.2-1+deb9u1 Commented Jan 14, 2020 at 9:24
  • sorry, worked for me on Stretch, too. Are you sure there's no overlapping mounts?
    – kevlinux
    Commented Jan 15, 2020 at 7:47
  • @kevlinux Pretty sure there's none. Just to be sure, I ran mount|grep sdd and it reports nothing. If it matters, /media/sdd1 permissions prior to mounting are drwxr-xr-x 2 root root and same for /media. Commented Jan 15, 2020 at 13:08
  • What type of media?
    – kevlinux
    Commented Jan 15, 2020 at 22:27

2 Answers 2

3

Running mount as a normal user doesn't allow specifying custom mount options (running mount -r is equivalent to adding the ro mount option), all custom mount options are removed in this case and only default options + options from fstab are used.

Result when running sudo mount -r /mnt/test:

/dev/sdb /mnt/test vfat ro,nosuid,nodev,noexec,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro 0 0

Same as normal user, you can see the ro option was ignored:

/dev/sdb /mnt/test vfat rw,nosuid,nodev,noexec,relatime,uid=1000,gid=1000,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro 0 0

It's not possible to change this, so you either need to specify the ro option in fstab or run the mount command as root.

"Unprivileged" mount with mount and fstab is very restrictive in general and it makes sense -- you don't want to allow non-root users to change options specified in fstab. In this case it might be "safe", because you are "lowering" your privileges when switching from rw to ro but it still is changing something you are not allowed to change.

2
  • 2
    Thanks, I've accepted your answer because it addresses my question. In light of this, my complaint is that mount -o ro fails with an error message, but mount -r succeeds, silently removing the read-only flag without giving any information to the user. I guess that can be seen as a bug, but I'm not sure where. Commented Jan 22, 2021 at 17:34
  • 1
    I've submitted this problem to Debian as bugs.debian.org/cgi-bin/bugreport.cgi?bug=980828. The behaviour in Wheezy is that the read-only flag is honoured, which is what I expected; it was broken somewhere between Wheezy and Jessie. Commented Jan 22, 2021 at 22:11
-2

This happens when you have dual booted your system where one of the OS is Windows. Windows OS doesn't unmount the disks properly because there is configuration in Windows OS which helps windows to boot up faster.

First Solution: You can boot into your windows OS and then follow the following steps: (for Windows 10)

  • Right Click on Windows Button on taskbar and click 'Power Options'.
  • Click 'Additional Power Settings' from the right pane of the window.
  • Click 'Choose what the power buttons do' from the left pane of control panel.
  • Click 'Change settings that are currently Unavailable'.
  • Accept UAC dialog if prompted and then uncheck the 'Turn on Fast Start-up'.
  • Save Changes and boot into your linux distro.

Now automatic mounting will be having read-write access on the drive.

Second Solution: The second way to solve this problem is to use following commands in the terminal:

sudo apt-get install ntfs-3g -y
sudo ntfsfix /dev/drive-name

After the execution of above commands, try remounting again.

Third Solution: This one works but you need to do it every time you boot into your linux distro.

Solution by Nevena Pavlicic

2
  • The question is the opposite: Pedro is trying to mount the filesystem read-only but it gets mounted read-write anyway. It's also FAT16, not NTFS.
    – Oskar Skog
    Commented Jan 21, 2021 at 11:56
  • I don't have Windows installed, or dual boot, and the partition I'm trying to mount is a USB drive that I plug in with the system running. It's also not the first time I have similar issues. Commented Jan 21, 2021 at 15:38

You must log in to answer this question.

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