Richie Lai
Richie Lai

Reputation: 502

How to persist hostname change on Azure Ubuntu

I've created a base image in azure that i named "LinuxBase" .. I've deployed this image about 10 times now with names "Linux1" -> "Linux10". However, every time the machine is rebooted, the name reverts back to "LinuxBase".

I have

but none of these things persist across reboots.

Upvotes: 10

Views: 8539

Answers (2)

jalike
jalike

Reputation: 41

Gooler's fix works, but the root cause of this issue is creating an image without running 'sudo waagent -deprovision' first - see https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-linux-capture-image/

'sudo waagent -deprovision' should only be run on a machine that was purpose built to create an image from; as it will be deprovisioned after the image is captured.

Upvotes: 4

Javi Romero
Javi Romero

Reputation: 337

As stated in the docs, one should be able to change the hostname if desired. To make this change persist there's one more step tough.

You need to install the Azure Linux Agent http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-agent-user-guide/ and modify the configuration to monitor hostname changes and update the network. This can be done editing /etc/waagent.conf and setting the entry:

Provisioning.MonitorHostName=y

Once done, install the service with

sudo waagent -install

and then change the hostname and everything will be updated, both locally an on the network.

You can check how to change the hostname here in the docs http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-introduction/#hostnamechanges where it states that simply running

sudo hostname <newname>

Will do the trick.

Edit: Also you may need to edit the file /var/lib/waagent/ovf-env.xml and change the hostname there too

Upvotes: 8

Related Questions