Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Sep 2022 18:35:26 +0200
From:      Guido Falsi <mad@madpilot.net>
To:        Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Dynamic hostname in rc.conf (for bhyve VMs)
Message-ID:  <c4d1d91d-47ed-860d-fa55-3b89a48977f3@madpilot.net>
In-Reply-To: <20220911022259.a51af1f585f24af6bfb6d4e4@dec.sakura.ne.jp>
References:  <f76151eb-8374-5691-b158-d3c7be9f6169@madpilot.net> <20220911022259.a51af1f585f24af6bfb6d4e4@dec.sakura.ne.jp>

next in thread | previous in thread | raw e-mail | index | archive | help
On 10/09/22 19:22, Tomoaki AOKI wrote:
> On Sat, 10 Sep 2022 10:52:01 +0200
> Guido Falsi <mad@madpilot.net> wrote:
> 
>> Hi,
>>
>> Since rc.conf is just a shell script I'd like to be able to set hostname
>> dynamically.
>>
>> This is bhyve related because what I'd like to do is pass an hostname to
>> VMs via the -e option to bhyveload(8), and then read it in rc.conf,
>> maybe via sysctl to set the hostname accordingly.
>>
>> By the way I'm using vm-bhyve [1] to manage my VMs. its configuration
>> files are also shell scripts, so I was planning to hack some simple
>> logic there, host side, to derive the hostname from filesystem (useful
>> for cloned VMs).
>>
>> Could not find any example or documentation about any step of this.
>>
>> Is this even possible with current tools? I'm open to hacky solutions to
>> start with, then maybe refine them.
>>
>>
>> I'm trying to do this because I'm using a local dnsmasq that exposes DNS
>> with the hostnames provided by VMs, but clones get the same naem as the
>> machien they're cloned from and mask those in this small internal DNS.
>> If each clone could provide it's different name it would be much better.
>>
>>
>> Thanks in advance for any help/suggestions.
>>
>>
>> [1] https://github.com/churchers/vm-bhyve
>>
>> -- 
>> Guido Falsi <mad@madpilot.net>
>>
> 
> IIUC, and if you obtain IP addresses of each VMs via DHCP,
> just keeping hostname on rc.conf would be suffice.
> 
> /etc/rc.d/hostname has a functionality to get hostname by
> hostname=`/bin/kenv dhcp.host-name`, meaning hostname is set using
> what DHCP server supplied, if NOT in a jail.
> 
> See the script for details.
> 

Hi!

Sorry for the delay in replying.

Thanks for your suggestion of using kenv, I completely overlooked that! 
It was the missing piece for me.

In fact my basic idea almost works perfectly once I use kenv to read 
variables passed by bhyveload.

Only problem is that the vm configuration file used bu vm-bhyve is not a 
shell script but treated as a key pair. So i can't do logic in there.

I ended up creating a very simple local patch to vm-bhyve here that does 
what I need:

https://github.com/madpilot78/vm-bhyve/tree/bhyveload_pass_vm_hostname

I think I will propose the patch upstream too, maybe with some cleanup.

So thanks again!

-- 
Guido Falsi <mad@madpilot.net>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?c4d1d91d-47ed-860d-fa55-3b89a48977f3>