外部介质设为只读挂载是否无需弹出?如何全局配置该设置?
Short answer: Yes, absolutely.
When you mount a device in read-only mode, your operating system never performs write operations to it—no data is cached in memory waiting to be saved, and no changes are made to the filesystem. Ejecting is only necessary to ensure pending writes are flushed to the device (to avoid corruption). Since you’re only reading from SD cards/cameras and never writing, you can safely unplug them at any time without running the eject step first. No risk of data loss or filesystem damage here.
Both your Raspberry Pi (Raspbian) and Ubuntu server are Debian-based, so the same methods work for both systems. We’ll focus on the simplest, most reliable approach using udisks2—the default service that handles automounting of removable media on modern Linux distros.
Method 1: Configure Udisks2 (Easiest for Global Control)
- Create a configuration directory for udisks2 if it doesn’t exist:
sudo mkdir -p /etc/udisks2.conf.d - Create a new config file to enforce read-only mounts for removable devices:
sudo nano /etc/udisks2.conf.d/90-removable-readonly.conf - Paste the following content into the file:
[Removable] MountOptions=ro - Save and exit the editor (in nano, press
Ctrl+O, hit Enter, thenCtrl+X). - Restart the udisks2 service to apply changes:
sudo systemctl restart udisks2
Method 2: Udev Rules (For Finer-Grained Control)
If you need to exclude specific devices (e.g., non-removable storage) or have more customizations, use udev rules:
- Create a new udev rule file:
sudo nano /etc/udev/rules.d/99-removable-readonly.rules - Add this rule, which targets all removable block devices and sets their mount options to read-only:
ACTION=="add", SUBSYSTEM=="block", ENV{ID_REMOVABLE}=="1", ENV{UDISKS_MOUNT_OPTIONS}="ro" - Save and exit, then reload udev rules:
sudo udevadm control --reload-rules sudo udevadm trigger
Verify the Setup
Plug in an SD card or camera, then run this command to check the mount options:
mount | grep /media
Look for the ro flag in the output—this confirms the device is mounted read-only.
Temporary Read-Write Access (If Needed)
If you ever need to write to a device (even though you said you don’t), you can remount it manually:
sudo mount -o remount,rw /path/to/mount/point
Just remember to remount as read-only or eject properly before unplugging if you’ve made changes.
Content of the question来源于stack exchange,提问作者Willem de Groot

