Mount

"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

Concept

Explanation

/etc/fstab

File to persist mount points across reboots

Read-Only RootFS

Used for recovery, embedded, containers

Remounting

Changing mount options without unmounting

mount -o ro,noload

Read-only without journal replay (useful for XFS/ext4 corruption)

Loop Device

Mount ISO or img files read-only using -o ro,loop

Bind Mounts

Can mount directory elsewhere with different options


✅ 5. Edge Cases and Considerations

Scenario

Behavior

Mounting already mounted FS as ro

Requires remount option

If mounted ro, cannot run fsck with write

Use umount and fsck, then mount rw

Live systems (e.g., /) remount ro

Must be done in single-user mode or recovery

Some FS types (e.g., NTFS, exFAT)

Might not support ro fully via default kernel modules


✅ 6. FAANG-Level 20 Interview Questions & Answers


🔸 Conceptual and Practical

  1. Q: Which option in the mount command mounts a filesystem read-only?
    A: -o ro

  2. Q: How do you remount / read-only without rebooting?
    A: mount -o remount,ro /

  3. Q: What is the effect of mount -o ro,noload on an ext4 filesystem?
    A: Prevents journaling (safe read-only of corrupt fs).

  4. Q: What’s the purpose of mounting root FS as read-only?
    A: For troubleshooting, forensic investigation, or initrd boot stages.

  5. Q: How do you verify a mount is read-only?
    A: mount | grep /mount/point or findmnt -o TARGET,OPTIONS


🔸 System Recovery and Debugging

  1. Q: Why would you mount a FS read-only during recovery?
    A: To prevent further corruption or accidental changes.

  2. Q: How do you mount an ISO file read-only?
    A: mount -o ro,loop image.iso /mnt/iso

  3. Q: Can bind mounts be made read-only?
    A: Yes: mount --bind /real /bind && mount -o remount,ro /bind

  4. Q: What happens if you try to touch a file in a ro mount?
    A: You get a Read-only file system error.

  5. 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

  1. Q: Which field in /etc/fstab controls mount options like ro?
    A: The 4th field (mount options): /dev/sda1 / ext4 ro 0 1

  2. Q: What kernel system call is used to mount filesystems?
    A: mount(2) syscall

  3. Q: Can overlay filesystems (like Docker layers) have read-only mounts?
    A: Yes, lower layers are read-only in overlayfs.

  4. Q: What does noload do when combined with ro?
    A: Skips journal replay, useful for data recovery.

  5. Q: What mount options can help protect a FS besides ro?
    A: nodev, noexec, nosuid, relatime


🔸 Troubleshooting & SRE Scenarios

  1. 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.

  2. Q: How do you remount /boot partition read-only?
    A: mount -o remount,ro /boot

  3. Q: How to automate read-only mount of a device at boot?
    A: Add ro in /etc/fstab.

  4. Q: What will df -h show if filesystem is read-only?
    A: Normal usage stats; it doesn’t show ro status.

  5. Q: Can you run Docker with read-only root filesystem?
    A: Yes, using --read-only in container spec.


✅ Summary Table

Task

Command

Mount as read-only

mount -o ro /dev/sda1 /mnt/readonly

Remount existing mount as read-only

mount -o remount,ro /mnt/point

Mount ISO as read-only

mount -o loop,ro image.iso /mnt/iso

Bind mount read-only

mount --bind /src /dst && mount -o remount,ro /dst

Persistent in fstab

/dev/sda1 /mnt ext4 ro 0 0


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?


 

Distributed by Gooyaabi Templates | Designed by OddThemes