Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One time boot into Read Only?

Tags:

linux

grub

I'm trying to boot into read only mode to test some software. I don't want to remount a drive after booting as that would not meet the requirements to test the software which checks the file system at boot.

Is there a way to do this without editing grub.conf? Preferably adding something via the grub UI when interrupting boot?

If I do edit the grub.conf to boot in read only, how am I supposed to edit it back?


I understand that the kernel mounts root as RO but it's remounted as RW later in the boot process.

like image 308
neuroelectronic Avatar asked Nov 03 '11 00:11

neuroelectronic


People also ask

How do I fix a read only file in Linux?

Run the command mount . If you see ro in the results, the file system is read-only. Remounting the drive should fix the error. To do so, use mount -o remount,rw mount point . You can then delete the file.

How do I know if my mount point is read only?

Command mount will list all mounted partitions and will indicate whether they are mounted read only (ro) or read-write (rw). There is no way to tell whether a filesystem is "healty" while mounted in a normal read-write mode.

How do I create a filesystem readonly?

Making it read-only is easy: replace rw with ro on the kernel command line or use an inherently read-only filesystem such as squashfs . However, you will find that there are a few files and directories that are traditionally writable: /etc/resolv.

Can Linux run read only?

You can use the chmod command to set read-only permission for all files on a Linux / Unix / macOS / Apple OS X / *BSD operating systems. This page explains how to setup read only file permission on Linux or Unix web server such as Nginx, Lighttpd, Apache and more.


2 Answers

When grub is running, you typically have some ability to edit the kernel command line before grub loads the kernel and continues booting. Perhaps your distribution has hidden the grub interface at boot -- holding down the left shift may bring it up and let you edit the kernel command line.

The Linux kernel Documentation/kernel-parameters.txt documents the ro kernel command parameter to mount your root filesystem read-only. If you add-in init=/bin/sh, then you'll be in charge of mounting whatever filesystems you want. You may need to mount /proc before mount(8) will show any mounted filesystems: mount -t proc none /proc.

Just be sure to give the -o ro or -o rw option to mount(8) as your mount each filesystem as you desire.

But I have to think there are better ways of testing software. What are you really trying to do?

like image 123
sarnold Avatar answered Oct 04 '22 22:10

sarnold


This could also be done by adding

GRUB_DEFAULT=saved

to your grub.cfg . Then you can create 2 different GRUB entries to the bootloader (eg. "RedHat" and "RedHat RO". The set the default entry like this in your terminal

grub-set-default "RedHat"

To run the other grub entry only for the next reboot issue in your terminal

grub-reboot "RedHat RO"

This works essentially, by adding a flag in the grub configuration (grubenv) and removing it after reboot. So basically your /boot/ partition has to be writeable. You can also remount the boot partition writeable if necessary. In any case you need the /boot/ directory on a separate partition.

Another alternative would be to put the boot partition on a USB stick and boot the "RedHat RO" from there every time you need it.

Otherwise: As sarnold already said: The changes you do in the GRUB command line or GRUB editing are only temporary.

like image 34
Kenyakorn Ketsombut Avatar answered Oct 04 '22 22:10

Kenyakorn Ketsombut