Reset root password of a virtual machine

From ISPWiki
Jump to: navigation, search
Hierarchy: VMmanager KVM -> VIRTUAL MACHINES

To change the root password of a virtual machine, the corresponding method must be specified in the OS template.

Password change method is an algorithm used by VMmanager for changing the root password of a virtual machine. The method is specified on the OS template in the tag chpass_method

Only the mount.linux method is currently supported


This method can be used only on Linux systems. guestfish must be installed

How it works

1. VMmanager mounts the virtual disk:

guestmount -a <disk_image> -i <path to the mounting point>

2. Makes chroot

mount -t proc proc <path to the mounting point>/proc
mount -o bind /dev <path to the mounting point>/dev mount -o bind /sys <path to the mounting point>/sys chroot <path to the mounting point>

3. Changes the password

usermod -p 'new password' root

4. Make unmount

"Failed to mount VM disks" after password change

This error occurs when trying to change the password of a virtual machine running the XFS file system located on a ext4 host server, kernel version 3.10 and later.

Run guestmount -v -x -a <disk_image> -i <path to mount point>. If you see something like this "mount: wrong fs type, bad option, bad superblock", that virtual machine cannot run with libguestfs.

Cause of the issue: guest xfs is not fully supported by the RHEL/CentOS 6 kernel. For more information, please refer to virt-inspector can't obtain info from rhel7.3 guest image on rhel6.9 host.

Unfortunately, libguestfs developers say that this bug cannot be resolved.