Re: Dynamic hostname in rc.conf (for bhyve VMs)
- In reply to: John Kennedy : "Re: Dynamic hostname in rc.conf (for bhyve VMs)"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 17 Sep 2022 19:42:07 UTC
On 17/09/22 21:22, John Kennedy wrote:
> On Sat, Sep 10, 2022 at 10:52:01AM +0200, Guido Falsi wrote:
>> Since rc.conf is just a shell script I'd like to be able to set hostname
>> dynamically.
>
> AFAIK, not a shell-script (although variables are set in that syntax).
I'm sure about this, rc.conf is sourced through the shell. So it is a
shell script.
You can verify this by checking the load_rc_config() function in
/etc/rc.subr which runs (beyond a lot of other things):
. /etc/rc.conf
I was wrong about vm-bhyve machine configuration file, which is a simple
key/value pair file.
>
> I wasn't trying to do exactly what you are, but one thing I did was set the
> MAC address as one of the bhyve options:
>
> ...
> -s 5,virtio-net,tap2,mac=00:01:02:03:04:05
> ...
>
> (Changed the MAC address in the example, but pick a safe one for your setup)
>
> Should be able to provide your own rc.d configuration file that does
> something like do a switch on MAC and call the hostname script directly.
>
>
I already succeeded by adding "-e bhyve_vm_name=${_name}" (where _name
contains the name of the vm) to bhyveload arguments, then reading it
with kenv from rc.conf:
hostname="$(/bin/kenv bhyve_vm_name).internal.vms"
Works like a charm.
--
Guido Falsi <mad@madpilot.net>