Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Boot in recovery mode an ubuntu server KVM virtual machine from a remote pc

Digital Innovation Partner

Boot in recovery mode an ubuntu server KVM virtual machine from a remote pc

Why you should need to restart a VM ubuntu 12.04 server on your KVM remote server?

Simple: just miss an apparently innocuous command (in my case I needed to add a user to a group).

Then I typed the command:

sudo usermod -G mygroup myuser

Unfortunately I forgot the “-a” option thus erasing all user groups including the group “sudo” that makes my user “sudoer”.

What to do when the only user having the login permission (unfortunately for root the login was not enabled…) cannot execute sudo commands???

the only chance that I found was to start the server in recovery mode…
So below a short guide to do the trick connecting through virt-viewer from a Desktop ubuntu pc to the remote KVM server.

1) @client: install virt-viewer if not already installed.

sudo apt-get install virt-viewer

2) @client: generate ssh key in order to log in to the KVM server without typing the password (!!!)

ssh-keygen -t rsa

3) @client: s-copy the generate key on the KVM server

scp .ssh/id_rsa.pub USER@KVM_SERVER_IP:KVM_SERVER_PORT:my_id_rsa.pub

4) @server: authorize the rsa key

cat my_id_rsa.pub >> .ssh/authorized_keys

5) @server: shutdown the guest VM to restore (virsh list for getting the correct VM_DOMAIN)

virsh shudown VM_DOMAIN

6) @client: connect virt-viewer with the “–wait” option to the KVM server asking for VM_DOMAIN

virt-viewer --wait -c qemu+ssh://USER@KVM_SERVER_IP:KVM_SERVER_PORT/system VM_DOMAIN

7) @server: start the VM to restore

virsh start VM_DOMAIN

At this point, the client will launch automatically virt-viewer showing the bootloader menu of the remote VM through which start the server in recovery mode
In my case it was essential in order to log in as root and restore the groups (basically the group “sudo”) of the user.

In addition, entering as root, I encountered problems launching the command “usermod” beacuse the main disk was not correctly mounted.
Then:

mount -o remount /dev/mapper/ubuntu1204-root
usermod -a -G sudo myuser
reboot

Lascia un commento