Rename VM under libvirt

Karina
1 min readApr 28, 2020

--

It’s very convenient to manage all VM with libvirt under Linux. And virsh — is a program to make this managing even more convenient. Today I faced with a task of renaming VM under libvirt.

Assume we define some VM in my_favourite_vm.xml and want to rename it from my_favourite_vm to old_fashioned.

sudo virsh shutdown my_favourite_vm
sudo virsh undefine my_favourite_vm

Rename my_favourite_vm.xml to old_fashioned_vm.xml and change <name>my_favourite_vm</name> to <name>old_fashioned_vm</name> inside xml

sudo virsh create old_fashioned_vm.xml
sudo virsh list

Seems, it’s done. But if you could ssh to your vm earlier you may face that now it’s unavailable by new name.

ssh root@old_fashioned_vm

So you need to fix hostname. Use virsh console to connect to vm

user@host: sudo virsh console tcu
Connected to domain tcu
Escape character is ^]

Login, then:

cat old_fashioned_vm > /etc/hostname
vim /etc/hosts #and fix all occurences
reboot

Press escape character to exit console mode. In my case it’s ctrl + ]

Now the task is done and vm is renamed altogether with it’s hostname! :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Karina
Karina

Written by Karina

I’m not a programmer, I’m just pretending https://github.com/keyrnk

No responses yet

Write a response