"Which command is used to mount the file system read-only?"
We’ll break this down into core concepts, Linux internals, related commands, FAANG-level edge cases, and finally 20 deep interview Q&A.
✅ 1. Fundamentals: Mounting in Linux
🔹 What Is Mounting?
Mounting is the process of attaching a filesystem (like /dev/sda1, USB drive, ISO, etc.) to a specific directory in the Linux filesystem hierarchy so you can access its files.
📌 Think of it like plugging in a USB stick and being able to access it via /mnt/usb.
🔹 Syntax of mount
mount <device> <mount_point> [-o options]
🔹 Basic Example:
mount /dev/sdb1 /mnt/mydrive
✅ 2. Mounting Filesystem as Read-Only
🔹 Command to Mount Read-Only
mount -o ro <device> <mount_point>
Here, -o ro means “read-only”.
📌 Example:
sudo mount -o ro /dev/sda1 /mnt/readonly
You can browse the contents
You cannot modify, delete or create files
✅ 3. Alternate Way (Remount Existing Mount Point Read-Only)
sudo mount -o remount,ro /mount/point
This is useful for:
Live systems (e.g., remount root filesystem before fsck)
Maintenance or forensic analysis
✅ 4. Related Concepts and Commands
✅ 5. Edge Cases and Considerations
✅ 6. FAANG-Level 20 Interview Questions & Answers
🔸 Conceptual and Practical
Q: Which option in the mount command mounts a filesystem read-only?
A: -o roQ: How do you remount / read-only without rebooting?
A: mount -o remount,ro /Q: What is the effect of mount -o ro,noload on an ext4 filesystem?
A: Prevents journaling (safe read-only of corrupt fs).Q: What’s the purpose of mounting root FS as read-only?
A: For troubleshooting, forensic investigation, or initrd boot stages.Q: How do you verify a mount is read-only?
A: mount | grep /mount/point or findmnt -o TARGET,OPTIONS
🔸 System Recovery and Debugging
Q: Why would you mount a FS read-only during recovery?
A: To prevent further corruption or accidental changes.Q: How do you mount an ISO file read-only?
A: mount -o ro,loop image.iso /mnt/isoQ: Can bind mounts be made read-only?
A: Yes: mount --bind /real /bind && mount -o remount,ro /bindQ: What happens if you try to touch a file in a ro mount?
A: You get a Read-only file system error.Q: How do you test if a directory is on a ro filesystem?
A: Try touch file, or check with mount | grep <dir>.
🔸 Advanced & FS Internals
Q: Which field in /etc/fstab controls mount options like ro?
A: The 4th field (mount options): /dev/sda1 / ext4 ro 0 1Q: What kernel system call is used to mount filesystems?
A: mount(2) syscallQ: Can overlay filesystems (like Docker layers) have read-only mounts?
A: Yes, lower layers are read-only in overlayfs.Q: What does noload do when combined with ro?
A: Skips journal replay, useful for data recovery.Q: What mount options can help protect a FS besides ro?
A: nodev, noexec, nosuid, relatime
🔸 Troubleshooting & SRE Scenarios
Q: If /etc/fstab has ro and system won’t boot into writable mode, what to do?
A: Boot into recovery, remount as rw, and edit /etc/fstab.Q: How do you remount /boot partition read-only?
A: mount -o remount,ro /bootQ: How to automate read-only mount of a device at boot?
A: Add ro in /etc/fstab.Q: What will df -h show if filesystem is read-only?
A: Normal usage stats; it doesn’t show ro status.Q: Can you run Docker with read-only root filesystem?
A: Yes, using --read-only in container spec.
✅ Summary Table
Would you like a hands-on step-by-step lab to practice remounting / or /boot as read-only, or a Bash script to audit and convert all mounts to read-only during maintenance windows?