One time boot into Read Only?
Asked Answered
E

2

6

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.

Engadine answered 3/11, 2011 at 0:34 Comment(0)
P
6

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?

Perla answered 3/11, 2011 at 0:55 Comment(5)
I don't want to fake this in software. I want the software to detect booting into read only. So I tried this (init=/bin/sh) and it looks like several things were mounted automatically anyway, including /dev/sda1 as /.Engadine
Btw, I'm running Red Hat, and I do have access to mid-boot grub modification. Perhaps that wasn't correct/clear when I said "Is there a way to do this without editing grub.conf? Preferably adding something via the grub UI when interrupting boot?Engadine
You can edit the kernel command line at grub to your heart's content without ever once modifying the grub.conf file. All your edits from within the grub menu / command line interface only effect that single boot. If you want to add ro to a new grub.conf entry to make it easily selectable, that's fine too. Up to you. :)Perla
@neuroelectronic: can you add some context to that spreadsheet?Perla
it was a copy/paste from the wrong buffer. you can ignore it.Engadine
A
1

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.

Ackack answered 16/9, 2014 at 7:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.