Howto modify linux hostname after clone and before startup

This is for discussing general topics about how to use VirtualBox.
Post Reply
cesarjorgemartinez
Posts: 17
Joined: 7. Jul 2016, 11:53

Howto modify linux hostname after clone and before startup

Post 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
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Howto modify linux hostname after clone and before startup

Post 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.
cesarjorgemartinez
Posts: 17
Joined: 7. Jul 2016, 11:53

Re: Howto modify linux hostname after clone and before startup

Post 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
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: Howto modify linux hostname after clone and before startup

Post 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.
Post Reply