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

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
User avatar
eiver
Level 5
Level 5
Posts: 566
Joined: Fri Jan 23, 2009 5:51 am

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

Post 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: http://www.networkupstools.org/docs/use ... 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


User avatar
xenopeek
Level 24
Level 24
Posts: 24281
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

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

Post 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
Image

User avatar
eiver
Level 5
Level 5
Posts: 566
Joined: Fri Jan 23, 2009 5:51 am

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

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

Post Reply

Return to “Software & Applications”