# one kernel for multiple hardware



## schmurfy (Oct 6, 2010)

Hello,
I currently use an image disk built by nanobsd to power a custom firewall at work but I have a small problem (more like a nuisance).
We run this image on two hardware and until now I managed to keep one kernel config for both meaning that you just need to write the image on the flash disk and you are ready to go BUT after some tests I had to create two different kernel config because the HZ need to be different for the two hardware (the soekris works better with 400 where the other bigger router prefer the standard 1000) so after all this talk my question is:
is there any way I can adjust the HZ while booting the kernel and adapt to the hardware it runs on ?

A pretty naive version of what I wish could be this:


```
if soekris
  sysctl -w kern.hz=400
else
  sysctl -w kernk.hz=1000
end
```


except that kern.hz is only writable during boot :\
I still hope there is something letting me use the same firmware for both boxes.


----------



## SirDice (Oct 6, 2010)

Set it in /boot/loader.conf.


----------



## expl (Oct 6, 2010)

If you are booting from an image (meaning /boot/loader.conf is read only), you can set the values at boot time (by interrupting the 10sec delay on boot loader and setting values manually). See loader(8).


----------



## schmurfy (Oct 6, 2010)

The idea is more to do it automatically than by hand, I know about /boot/loader.conf but can I put a condition of some sort in there to set the correct value ? If I can put a condition I can surely find how to differentiate the two boxes, they do not have the same processor class, not the same memory amount, not the same network card...


----------



## SirDice (Oct 6, 2010)

schmurfy said:
			
		

> The idea is more to do it automatically than by hand, I know about /boot/loader.conf but can I put a condition of some sort in there to set the correct value ?


This actually might be possible. The only thing you need to watch out for is that it's not a shell script but Forth. 

Have a look at the scripts /boot/loader.4th and /boot/loader.rc. These load /boot/loader.conf and a few other things (like the beastie menu).


----------



## phoenix (Oct 6, 2010)

Do you re-image boxes so often that it has to be automatic?

I mean, we're talking about changing 1 line in 1 text file once.

Image the machine.  Interrupt the first boot to set it manually at the loader prompt.  Continue the boot.  Edit the loader.conf.  Done.

Do you really need to make that automatic?  Just sounds like a lot of work for very little benefit.

Just set the default in the image to the value that will be most often used.


----------



## aragon (Oct 6, 2010)

Write a script for transferring the image to your devices.  Before transferal, mount the image, make the change, unmount the image, write the image.


----------



## schmurfy (Oct 7, 2010)

We will soon have lots of these equipments spread on different remote sites. To guarantee the service we provide we need to be able to send someone to switch the flash card in the event that the automatic remote update fails (even if probabilities are low we cannot have long downtimes). If we have more than one firmware it means we need to have one flash card for each hardware model in stocks.

The people we send on site if it happens do not have the tools nor any qualification to create the right flash (I would not trust them anyway, I may be paranoid but I have reasons for that).

I agree that the problem virtually does not exist when updating remotely since I can update the loader.conf after writing the image on the flash disk.

Thanks for the pointer on loader.4th. I will surely check this out !


----------

