Page 1 of 1

How do I remount my filesystems in read-only mode?

Posted: Fri Jul 27, 2012 2:34 pm
by eiver
I am using Mint as a small server and I have successfully connected an UPS to it. I am using nut to control the UPS.
I am following the tutorial for emergency power off in case the UPS runs out of battery power: ... S_shutdown

The tutorial suggests, that I should unmount any file systems and remount only the required file systems in read-only mode, before I do the shutdown.

How to remount a filesystem in the read-only mode and how to unmount all other file systems?

Code: Select all

~ $ cat /etc/fstab
# /etc/fstab: static file system information.
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=d9ca59cc-ae56-45f7-80c0-56f0a06b9ab2 /               xfs     defaults        0       1
# /home was on /dev/sda3 during installation
UUID=f4941b96-067d-4aff-90da-47aac2f92208 /home           xfs     defaults        0       2
# swap was on /dev/sda2 during installation
UUID=5e1845c4-ed48-47d5-be4b-3956d105ea47 none            swap    sw              0       0
# /dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

LABEL="important"  				/mnt/important  xfs  	defaults		0  	0
LABEL="data"  					/mnt/data  	xfs  	defaults		0  	0
LABEL="small"  					/mnt/small  	ext3  	suid,dev,exec  		0  	0
LABEL="big"  					/mnt/big  	xfs  	defaults		0  	0
LABEL="huge"  					/mnt/huge  	xfs  	defaults		0  	0

Re: How do I remount my filesystems in read-only mode?

Posted: Fri Jul 27, 2012 5:18 pm
by xenopeek
Remounting as read-only you can do with the mount command, as for example to remount / as read-only do:

Code: Select all

mount -o remount,ro /
I'm assuming you have the emergency script run as root BTW, so I'm skipping the adding of sudo to each command.

Unmounting filesystems you do with umount command, as for example to unmount /mnt/data do:

Code: Select all

umount /mnt/data

Re: How do I remount my filesystems in read-only mode?

Posted: Sat Jul 28, 2012 3:52 am
by eiver
Thanks. I was not aware of the remount option.
Can I assume, that the bash script located in /bin will continue to work correctly even after the remount as ro? I need to perform some additional commands after remounting. I do not intend to write anything to the FS myself, after it has been remounted as read-only, but I will be running the script with the >> /var/log/ups.log, so something might try to write to the FS. In particular I will try to send a poweroff command to the UPS via nut. I will obviously test, if it works myself, but since the / has been remounted as ro, I won't get any logs from the process at this point, so I want to make sure what might go wrong.