How set hostname on cloned VM?


I want to create, clone and run clearlinux guests on clearlinux host using QEMU/KVM.

I can create and start the VMs via virsh and virt-clone. However, all the cloned VMs have the same host name. In other distros virt-sysprep or virt-builder can be used for the task (hostname set). However, none of those tools are available in clearlinux.

How can I do that?

Thanks, Sakari

Use hostnamectl

hostnamectl set-hostname <yourhostname here>

hostnamectl status to check it worked.

You can also overwrite /etc/hostname but I think that would require a reboot.

I know that but I don’t want log in to the vm. Let’s say I will create 100 VMs. I don’t want to do that manually.

delete /etc/machine-id and /etc/hostname before your clone it. Then a random name will be assigned.

I don’t want random name. I want to set it so I have names like vm-0,vm-1, etc.

If any tool is mising you can open an issue for Package Request

You can also do this in the qemu-start command by adding hostname=name in the -netdev line. See:

You could then modify your start_qemu,sh script the use a positional (${2}) command-line parameter for setting a custom hostname on VM launch

EDIT: Oops, missed that you’re using virsh. Maybe virt-sysprep but I don’t think it’s packaged in CL.

I created a request:


Related to topic question :slight_smile:
virt-sysprep - is not available on Clear Linux, right ?

But how to setup passwords for .qcow2 images if virt-sysprep not available ?

sudo virt-sysprep -a Centos-7-x86_64-GenericCloud.qcow2 --root-password password:super

I have to run this command.

is there any alternatives on Clear Linux ?