# Permanent Write Mode in Single User



## usakhncit (Dec 26, 2020)

Hi
FreeBSD mounts Root drive as Read-Only in Single User Mode. Can I change this behavior permanently, so that it should always mount the drive as Read-Write?
Thanks


----------



## George (Dec 26, 2020)

The file /sys/kern/vfs_mountroot.c has this comment:

```
[TABLE]
[TR]
[TD]* The environment variable vfs.root.mountfrom.options is a comma delimited[/TD]
[/TR]
[TR]
[TD]* set of string mount options. […]
[/TD][/TR][/TABLE]
```





So my guess is that it is possible.


----------



## usakhncit (Dec 26, 2020)

Elazar said:


> possible


Any idea that how can it be done?


----------



## SirDice (Dec 26, 2020)

zetrotrack000 said:


> Can I change this behavior permanently, so that it should always mount the drive as Read-Write?


Simply question, why?


----------



## usakhncit (Dec 26, 2020)

SirDice said:


> Simply question, why?


In my culture, we sometimes use "can" instead of "how" in order to be more polite.
So, I will rephrase my question:
How can I change this behavior permanently, so that it should always mount the drive as Read-Write?
Thanks


----------



## SirDice (Dec 26, 2020)

zetrotrack000 said:


> How can I change this behavior permanently, so that it should always mount the drive as Read-Write?


Question remains, why do you want to do this? Explain what you're trying to accomplish because I have a feeling we have an XY problem here.

There are a number of reasons why the root filesystem (and only the root filesystem) is mounted read-only in single user mode. The most important one is fsck(8).


----------



## usakhncit (Dec 26, 2020)

SirDice said:


> Question remains, why do you want to do this? Explain what you're trying to accomplish because I have a feeling we have an XY problem here.
> 
> There are a number of reasons why the root filesystem (and only the root filesystem) is mounted read-only in single user mode. The most important one is fsck(8).


Sometimes, I mess up a configuration file like "fstab" or "rc.conf". Then I have to login through Single User Mode to fix it, which requires read-write mode. So, most of the times, I boot Single User Mode is to fix some (messed up) configuration file. I know that I can remount it as read-write, which I am doing... So, if I am doing remounting almost everytime, when why not make it default?


----------



## ShelLuser (Dec 26, 2020)

This is a disaster in the making you know. There's a good reason why it behaves as it does. And really, if it bothers you then I'd suggest adding a simple script to root's search path which simply re-mounts your filesystem(s) read/write. Then you'd only have to use 1 simple command.

See, there will come times when you don't want your system to start writing to your system disk right away. One example could be an attempt to retrieve deleted files, another more drastic example is to recover from a system or storage crash.

Pretty much anything can be changed in FreeBSD, but that doesn't always mean it's a good idea. And as I said: this is a disaster in the making.


----------



## usakhncit (Dec 26, 2020)

Seems like a forbidden knowledge 
OK, I got your point. But, still I want to try it in Virtual Machine, so if you can tell me that how can I change it?


----------



## SirDice (Dec 26, 2020)

zetrotrack000 said:


> So, if I am doing remounting almost everytime, when why not make it default?


Because you can't fix filesystem errors with fsck(8) when the filesystem is mounted read/write for example.


----------



## ralphbsz (Dec 27, 2020)

I don't know. It's such a bad idea, I would never try it.

Here an idea for you, so you can figure out yourself how to do it. Right as the kernel itself is done initializing itself, it starts a process called "init" (executable stored in /sbin/init), which then does all the initialization work that it outside the kernel. In normal operation, the init executable then starts running a whole slew of shell scripts, generally together called the "rc" system. That part is all very well documents (see man init, man rc, and so on), and most experienced Unix or *BSD users understand it reasonoably well, at least well enough to administer the machine. In single user mode ... I have no idea what it does, except knowing that after a very small number of steps, it starts a shell on the console. My suggestion: Read the documentation for init and rc, and find out what it does in single user mode. Somewhere in there MIGHT be a startup script it executes (silly guess: /etc/rc.single, but that's not it, that file does not exist). Modify that startup script, and add the remount command to make root be read-write.

If that doesn't give you anything, then it can't be done by editing scripts or config files. Matter-of-fact, my hunch is that in single user mode, no script is executed at all, because the idea behind single user mode is to be as reliable as possible. And anything init does might fail, so the less the does the better, so just start a shell. Anything a script can do a human admin can do, so having no setup scripts would be safer. In this case, the next step is looking at the source code for init, finding where it mounts root in read-only, modify the source code, recompile and install.

You understand that if you screw this up, you will reinstall, right? Matter-of-fact, given how you are removing all the safety rails on the system, you will reinstall pretty soon anyway, so going on a voyage of discovery is a wonderful justification for reinstalling.


----------

