# Cannot edit /etc/rc.conf



## IIjkII (Jul 29, 2009)

Hello everyone.  I'm new to freebsd and just got my box running and started installing stuff on it.  I messed up rc.conf and now when I boot it tells me this.


```
Loading configuration files.
apache22_enable: not found
/etc/rc.conf: 17: Syntax error: Unterminated quoted string
Enter full pathname of shell or RETURN for /bin/sh:
```

I assume that is because I wrote this in rc.conf 


```
apache22_enable = "YES"
```

instead of this


```
apache22_enable="YES"
```

or maybe because I forgot a quote on


```
webmin_enable="yes
```

Either way I need to go and edit /etc/rc.conf.  I login as root and try to use vim to edit it and I get these errors.


```
W10: Warning: Changing a readonly file
E303: Unable to open swap file for "etc/rc.conf", recovery impossible
Press ENTER or type command to continue.
```


```
"/etc/rc.conf" E212: Can't open file for writing
Press ENTER or type command to continue.
```

How can I edit /etc/rc.conf?  Thanks in advance.


----------



## Voltar (Jul 29, 2009)

IIjkII said:
			
		

> ```
> W10: Warning: Changing a readonly file
> E303: Unable to open swap file for "etc/rc.conf", recovery impossible
> Press ENTER or type command to continue.
> ...



Is your root filesystem mounted read-only? I believe that can/does happen when you have an error in rc.conf. I also remember seeing a similar thread to this not too long ago.


----------



## IIjkII (Jul 29, 2009)

Thanks for the quick reply.  It might be, it's all in grey txt now and I don't know what that meant.  I assumed it was some sort of emergency shell.  I also tried mounting the disk to /mnt and I got the same errors.


----------



## SirDice (Jul 29, 2009)

Boot to single user mode then:

```
# fsck
# mount -u /
# mount -a -t ufs
```

Now you should be able to edit /etc/rc.conf.


----------



## IIjkII (Jul 29, 2009)

Thank you very much.  That worked great.  Just out of curosity though, what did that do?


----------



## lme@ (Jul 29, 2009)

With `# fsck` you check the filesystems, `# mount -u /` mounts the root partition read/write, `# mount -a -t ufs` mounts all UFS partitions, so you can use vi and other tools in /usr.


----------



## IIjkII (Jul 29, 2009)

Oh, I see.  So the problem was that the drive was in read-only mode?


----------



## lme@ (Jul 29, 2009)

The / partition, yes.


----------



## pe3sos (Aug 12, 2009)

Thanks again SirDice


----------



## soamz (Feb 29, 2016)

```
# fsck
# mount -u /
# mount -a -t ups
```

Ran this but it still doesn't let me edit the file.


----------



## wblock@ (Feb 29, 2016)

That is probably because you don't have any filesystems of type ups.  FreeBSD uses UFS.


----------



## Seven Hong (Aug 21, 2016)

Newbie here, might be a stupid question but..

What caused / partition to be mounted read only in this case? I resolved similar issue by doing what SirDice said but I still don't know what's really going on.

FYI, my issue was that I needed to comment out some lines in loader.conf that causes kernel panic on boot, so I entered single user mode, then I could only edit loader.conf by following SirDice's suggestion.


----------



## Maxnix (Aug 21, 2016)

Seven Hong said:


> Newbie here, might be a stupid question but..
> 
> What caused / partition to be mounted read only in this case? I resolved similar issue by doing what SirDice said but I still don't know what's really going on.
> 
> FYI, my issue was that I needed to comment out some lines in loader.conf that causes kernel panic on boot, so I entered single user mode, then I could only edit loader.conf by following SirDice's suggestion.


When the OS detect problems during the boot sequence (i.e. a mispelled rc.conf entry) or when you boot in single-user mode, your partitions are always in read-only mode. This prevents possible damages to your data.


----------



## Murph (Aug 21, 2016)

Seven Hong, it's a standard Unix feature that booting into single user mode starts with just the root filesystem mounted, and the filesystem will be mounted read only.  That behaviour is needed to allow some maintenance tasks on the root filesystem which would not be possible if it defaulted to read+write.

It should never normally be mounted read only on a system which has fully booted to multi user mode.


----------



## scottro (Aug 21, 2016)

soamz , if you leave off the -t ufs, does it work?  Seems to me that I've run into something on a ZFS install, and just ran mount -a without the -t option and all was well.  My memory could be off.

Heh, and just saw that this thread started in the mid double oughts, but the fix (generally speaking) should still work.


----------



## Maxnix (Aug 21, 2016)

scottro said:


> soamz , if you leave off the -t ufs, does it work?  (Seems to me that I've run into something on a ZFS install, and just ran mount -a without the -t option and all was well.  My memory could be off.
> 
> Heh, and just saw that this thread started in the mid double oughts, but the fix (generally speaking) should still work.


`mount -a` will mount all the filesystems described in /etc/fstab, with the exception of those already mounted or with late and noauto options. Specifing the filesystem type too, only those of that type (always of the ones defined in /etc/fstab) will be mounted.


----------



## Alita (May 7, 2020)

IIjkII said:


> Thank you very much.  That worked great.  Just out of curosity though, what did that do?



well before doing the mount -a i did the fix errors on drive then
when i looked at rc.conf it had a mess of double "" after the commands
so after i cleaned it up it ran fine.

UPDATE: Ignore below LMA Error please

The LMA Error went away soon as i unplugged some usb drives before boot

But now i run into a new problem when booting up i got boot loader error and it may have to do with just installing mate i am not sure if it went into the .xinitrc i have to check but it is a LUA error


----------



## madwebness (Feb 10, 2022)

For those who have zfs, don't worry, just had the same problem. The command is the same except for the argument value for `-t`:


```
# mount -u /
# mount -a -t zfs
```

I must say, this is quite bizarre - such a small error in a config file should not prompt people to remount filesystems. I wonder why it happens and what is the reasoning behind loading the filesystem in read-only mode due to a mistake in a config file that actually caused it.


----------



## SirDice (Feb 10, 2022)

madwebness said:


> I must say, this is quite bizarre - such a small error in a config file should not prompt people to remount filesystems. I wonder why it happens and what is the reasoning behind loading the filesystem in read-only mode due to a mistake in a config file that actually caused it.


When the system boots it starts off in single user mode. Only the root filesystem is mounted, and is read-only. If there are any issues with any of the boot configuration files the system cannot do anything else but stop, and you're then stuck in that single user mode. With a read-only filesystem. Not bizarre, it's all very much explainable if you know how UNIX, and in particular FreeBSD, boots.


----------



## grahamperrin@ (Feb 10, 2022)

madwebness said:


> For those who have zfs, …



Alternatively, in single user mode, with a modern system such as FreeBSD 13.0-RELEASE:

`mount -uw /`
`service zfs start` or `service zfs onestart`


----------



## SirDice (Feb 15, 2022)

grahamperrin said:


> mount -uw /


`zfs set readonly=off zroot/ROOT/default` (assuming a default installation with zroot pool and the default BE). 



grahamperrin said:


> `service zfs start` or `service zfs onestart`


`zfs mount -a`


----------



## grahamperrin@ (Feb 15, 2022)

Thanks, what does `zfs mount -a` do that `service zfs start` does not?


----------



## SirDice (Feb 15, 2022)

Nothing, except it doesn't run `zfs share -a` (/etc/rc.d/zfs does). Which you may not want to do in single user mode.


----------

