udisks unable to mount NTFS-formatted usb drive properly if block device is set to read only (blockdev --setro /dev/sd??)

Bug #1734280 reported by Michael Tinsay on 2017-11-24
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ntfs-3g (Ubuntu)

Bug Description

In older versions (10.04 and older) we use HAL and UDEV rules to force all USB drives to be automounted read-only by the Desktop Environment. But they don't anymore for the newer versions. After a few days research and expirementations, I'm now able accomplish it using the UDEV rule:

KERNEL=="sd[b-z][0-9]", RUN+="/sbin/blockdev --setro /dev/%k"

In 16.04 and 17.10, the above work for FAT/exFAT, ext3/4, and even ext4 on an encrypted partition. It doesn't work though on NTFS-formatted usb drives -- I get a permission denied error.

To replicate/test this without creating the UDEV rule:

1. Insert FAT or ext3/4-formatted flash drive. Let Nautilus automount it. Note where in the left navigation pane it is.
2. From a terminal session, unmount the partition -- let's say sdb1.
3. Do: sudo blockdev --setro /dev/sdb1
4. In Nautilus' left pane, click on the device name to mount it again.
5. The mount command should show the mounted device as read-only.

Do the same for a NTFS-formated usb drive. By step #4, it will not mount with a permission denied error.

Phillip Susi (psusi) wrote :

We don't want all USB drives to be mounted read-only, and I'm pretty sure this was not the case in 10.04 or older. Your rule simply makes every scsi drive but the first one to be detected ( which may or may not be USB ) read only.

Changed in udisks (Ubuntu):
status: New → Invalid
Michael Tinsay (tinsami1) wrote :

I'm ok with you not wanting all USB drives to be mounted read-only -- such is the default behavior of Ubuntu. But I and the company I work for want it to be that way to comply with out security policies. And since HAL is already deprecated, the workaround I found for recent Ubuntu versions is to use the udev rule I posted above. Your assertion about the rule is correct and it is intended to be that way.

That is not the bug here.

When udisks detects the media to be read-only, it correctly mounts them as read-only for FAT/exFAT and ext2/3/4 filesystems. For NTFS, it is forcing a read-write mount which then results in an mount error because the media is read-only.

Changed in udisks (Ubuntu):
status: Invalid → New
Phillip Susi (psusi) wrote :

I don't think it is udisks that is mounting the other filesystems read/only, but rather that those filesystems automatically fall back to read/only when they see the media is read-only. You should be able to see the errors in dmesg where the fs falls back to read-only mode.

affects: udisks (Ubuntu) → ntfs-3g (Ubuntu)
Jean-Pierre (jean-pierre-andre) wrote :

When a device is read-only (through a hardware switch preventing it to be written to), ntfs-3g falls back to a read-only mount (since ntfs-3g 2012.1.15AR.7).
Actually, ntfs-3g falls back to read-only mount whenever it gets an EROFS from trying to open a device read-write.

Jean-Pierre (jean-pierre-andre) wrote :

Please try the attached patch

The attachment "Check whether the device was forced read-only" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers