# nanobsd, saving files in /etc/local?



## adam2104 (Mar 8, 2012)

I'm working on setting up my first FreeBSD router. I'm using an alix 2D13 board with FreeBSD 9.0. I've built a nice little nanobsd image with a custom kernel and all that. Now I'm onto the configuration aspect of things. One thing I'm configuring is dnsmasq for DHCP and DNS resolution. By default dnsmasq keeps its configuration in /etc/local/dnsmasq.conf. I can't for the life of me figure out how to get "save_cfg" to save this file into /cfg. Is there some basic trick I'm missing? Surely this should work...right? This is what I'm seeing:


```
alix# sh save_cfg local/dnsmasq.conf
find: *: No such file or directory
cp: /cfg/local/dnsmasq.conf: No such file or directory
```

I've also tried it with just the name:

```
alix# sh save_cfg dnsmasq.conf
find: *: No such file or directory
cp: /etc/dnsmasq.conf: No such file or directory
```

Based on this it looks like "save_cfg" automatically adds "/etc" to the front of the names. So, technically, "local/dnsmasq.conf" should work, the file does exist:


```
alix# ls -l /etc/local/dnsmasq.conf
-r--r--r--  1 root  wheel  2777 Mar  8 05:21 /etc/local/dnsmasq.conf
```

Any hints?


----------



## SirDice (Mar 8, 2012)

adam2104 said:
			
		

> By default dnsmasq keeps its configuration in /etc/local/dnsmasq.conf. I can't for the life of me figure out how to get "save_cfg" to save this file into /cfg.


All ports use /usr/local/etc/, not /etc/.


----------



## adam2104 (Mar 8, 2012)

Yes, I realize this. However in nanobsd that is symlinked to /etc.


----------



## SirDice (Mar 8, 2012)

The port installs the sample config to /usr/local/etc/dnsmasq.conf.example.


----------



## adam2104 (Mar 8, 2012)

Yes, I know, I've found it, that isn't my question. I've created my own dnsmasq.conf and now its sitting there, configured. However, with nanobsd's read-only file system the changes will be lost if I reboot the system. There is a script with nanobsd, save_cfg, that is used to sync files from /etc to the /cfg partition that is read on bootup. However, the script doesn't appear to be able to handle anything outside of the /etc base directory. Anything deeper doesn't seem to sync, and that is my question. Am I missing something on how to sync something deep that /etc with save_cfg?


----------



## SirDice (Mar 8, 2012)

I think I'm actually missing something :e

Never played with NanoBSD before, that's probably where my confusion comes from.

Is /usr/local/etc/ symlinked to /etc/local/?

What happens if you try 
`# save_cfg /usr/local/etc/dnsmasq.conf`


----------



## zennybsd (Mar 8, 2012)

adam2104: As far as I can guess, when nanobsd boots, it copies everything from /cfg to /etc. So you may see /etc/local/dnsmasq.conf after you booted. However, for permanent configuration change, the file needs to be appended to /cfg. I guess there lies this confusion, but not sure. ;-)

It was true until F*ree*BSD 8.3, with F*ree*BSD 9, I cannot say because I am finding difficulty even to compile a nanobsd image (http://forums.freebsd.org/showthread.php?t=30331) :-(


----------



## adam2104 (Mar 8, 2012)

SirDice said:
			
		

> I think I'm actually missing something :e
> 
> Never played with NanoBSD before, that's probably where my confusion comes from.
> 
> ...



Exactly,  /usr/local/etc/ is symlinked to /etc/local/. I tried the command you suggest, but it does this:

`# save_cfg /etc//usr/local/etc/dnsmasq.conf`

Which isn't quite right. I've done some more digging and it looks like save_cfg doesn't recurse into any directories, so if I want to save that file I need to just use /etc/dnsmasq.conf, manually copy it to /cfg, or embed it directly in my nanobsd image.


----------



## zennybsd (Mar 8, 2012)

adam2104 said:
			
		

> so if I want to save that file I need to just use /etc/dnsmasq.conf, manually copy it to /cfg, or embed it directly in my nanobsd image.



That is exactly what I stated in my previous post. Whatever changes one makes in nanobsd, it should be appended to /cfg to make it permanent, because /etc is memory device which gets appended from /cfg when booting.


----------



## SirDice (Mar 9, 2012)

Ok, did I understood correctly the contents of /cfg/ gets copied to /etc/ when NanoBSD boots?

If that's the case just save the file in /cfg/local/. Then it'll probably get copied to the correct place.

The reason save_cfg might be failing is because /cfg/local/ doesn't exist.


----------



## zennybsd (Mar 9, 2012)

Also, the /cfg should be mounted in rw (read-write) mode before trying to append. /cfg/local may be there already, but it is only in ro (read-only) mode.


----------



## imrozx (Apr 22, 2012)

I found this script which works better than save_cfg: http://www.psconsult.nl/talks/NLLGG-BSDdag-Servers/cfgsync
*M*aybe you can check this out.


----------

