Saul note: Although this post idea, writings and its final formatting are my own work, I am disclosing having used generative AI (Claude 3.5) to aid with some of the text/code generation for it. The AI output has been used as a writing aid and it does not constitute the final or main form of the article.
Command Syntax
The primary command to create a read-only mount is:
sudo mount --bind -o ro /folder/folder2 /location/location2
Steps:
- Preparation
- Ensure the destination directory exists:
sudo mkdir -p /location/location2
- Bind Mount with Read-Only Option
- Use the
mount --bind
command - The
-o ro
flag specifically sets the mount as read-only - Replace
/folder/folder2
with your source directory - Replace
/location/location2
with your destination mount point
- Use the
Permanent Mount (Optional)
To make this mount persistent across reboots, add an entry to /etc/fstab
:
/folder/folder2 /location/location2 none bind,ro 0
.
To verify:
To confirm the read-only status:
mount | grep /location/location2
Important Considerations
- Root privileges are required
- Destination directory must exist before mounting
- Read-only mounts prevent any write operations
Unmounting
To remove the mount:
sudo umount /location/location2
Read-Only mount permissions considerations:
The read-only mount is enforced at the filesystem level, which means:
- Permissions changes are blocked by the mount’s read-only attribute
- The
chmod
command cannot override the mount’s fundamental read-only state
Details
Mount Options Take Precedence
- The
-o ro
(read-only) flag creates an immutable mount point - This flag overrides local filesystem permissions
- Even if you’re root, you cannot modify permissions on a read-only mount
How to Change Permissions
If you need to modify permissions:
- Unmount the read-only volume first
- Change permissions on the original source directory
- Remount with desired configuration
Alternative Approaches
- Use
mount -o remount,rw
to temporarily make it writable - Modify source directory permissions before binding
- Use more granular permission controls like ACLs
How to get the complete and exact list of mounted filesystems, though?
You can see ALL virtual and physical mounted filesystems in /proc/mounts
, but sometimes this output will not show actions performed using mount
or unmount
, which we just have. If you check inside /etc/mtab
, you will see your manual mounts, though.
Although you could just use findmnt
which will give you a way more human-readable format. Please see this source for more information on using findmnt and some –parsing –examples for an even cleaner output.