Page 1 of 1

Howto modify linux hostname after clone and before startup

Posted: 3. Feb 2017, 17:55
by cesarjorgemartinez
Hi,

I have Linux template VM, and with VBoxManage and scripts from host, I can clone to other VM, start...
But, exist any thing, software, for modify linux hostname for best configure, before statup the VM?
When clone and start a VM, the hostname is the original hostname.

Regards

Re: Howto modify linux hostname after clone and before startup

Posted: 3. Feb 2017, 17:58
by scottgus1
How would you modify a physical PC's OS before the PC starts? That's how you'd modify a virtual PC's OS before the OS starts.

Virtualbox doesn't have anything special to do this other than what's in the guest Settings (different MAC address, perhaps). See what you can come up with on the above thought and present what you develop. We'll see if it works.

Re: Howto modify linux hostname after clone and before startup

Posted: 6. Feb 2017, 11:01
by cesarjorgemartinez
Hi,

I'm looking something like other VMs, as a package that exists named cloud-init.
Cloud-init changes the hostname when system start, and when the network is online (Ex network or NetworManager for Fedora/Centos) the cloned VM is ready.

In VirtualBox not exists nothing else (I think).
When I try with script to clone a template (with reinitializing Macs), and then start it, the machine is started with the old name.
Another problem with this, is if use DNS for machines. When start with a new Mac, and old hostname, the DNS not working.
Then, I need to enter to console VM, and manually change hostname and restart the network, or reboot.
I need to find anything that automate this without this.

Regards

Re: Howto modify linux hostname after clone and before startup

Posted: 6. Feb 2017, 14:15
by scottgus1
Allow me to reiterate:
scottgus1 wrote:How would you modify a physical PC's OS before the PC starts? That's how you'd modify a virtual PC's OS before the OS starts.
Don't just repeatedly ask someone for something. Also, try to solve the problem yourself. What have you come up with?

Have you googled for how to change a host name while the PC is booting? Some other search as that?

As both you and I have stated, there isn't anything in Virtualbox to cause a guest OS host name change when the guest is cloned. Your question is not a Virtualbox problem, and therefore not fitting for the Virtualbox forums.

But I can tell you that changing anything in an OS requires a script in the OS that runs on boot. The script could look at some data in a shared folder or some other data on another disk. Or it could keep a running list of all MAC addresses it has seen on its virtual NIC and change the host name when it sees a new MAC address. Or with Guest Additions installed, the script can look at an "guestproperty get/set" string then change things according to that data.