Mounting filesystems readonly
From Crashcourse Wiki
For security reasons and to prevent accidents, you might want to mount some of your filesystems readonly, which means that, even as root, you wouldn't be able to change their contents. Obviously, this is only relevant for filesystems whose contents don't change as the operating system runs, and for which you can temporarily remount them as read/write to make the occasional modifications.
For example, assuming that you have a separate /boot filesystem corresponding to, say, /dev/sda1, and that you don't need to change anything inside it for the time being, you can:
# mount ... /dev/sda1 on /boot type ext3 (rw) ... # umount /boot # mount -o ro /dev/sda1 /boot ... /dev/sda1 on /boot ext3 (ro) ...
Obviously, if you need to make any changes to the contents of that filesystem, you'll need to remount it read/write for as long as it takes to do that.
Why would a filesystem be "busy"?
You won't be able to unmount a filesystem if it is in any way busy -- that is, there are open files or active processes anywhere within the filesystem. You can locate such things with:
# lsof /boot [list open files] # man lsof # fuser -muv /boot [list processes using files or sockets] # man fuser
Remounting a filesystem in a single step
Even if a filesystem is busy, if all of the files in that filesystem are open only for reading, you can still remount it readonly if you do it in a single operation:
# mount ... /dev/sda1 on /boot type ext3 (rw) ... # umount /boot umount: /boot: device is busy umount: /boot: device is busy # lsof /boot COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME bash 13652 root cwd DIR 8,1 1024 122401 /boot/grub # mount -o remount,ro /boot [one-step readonly remount] # mount ... /dev/sda1 on /boot type ext3 (ro) ...
This is how you would mount the /usr filesystem readonly since, on a running system, that filesystem is absolutely guaranteed to be busy, as long as none of that corresponds to files open for writing.
Feedback to rpjday@crashcourse.ca.
Return to Fedora_Cookbook.

