Get the App
SLTechnology News&Howtos  ›  Servers  › 

Modify the password of a virtual machine through virsh

Shulou Source: shulou.com Published: 2022-06-02 07:09:52 10月02日 Update

If you want to pass in a password when creating a virtual machine on the openstack platform, install cloud-init.

If you want to change the password of a virtual machine through the virsh command, you need to install qemu-guest-agent

Installation and configuration method

Https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/chap-QEMU_Guest_Agent.html

Upload the image to the openstack cloud platform (I am the N version of Openstack)

Openstack image create centos7.3-disk-format qcow2-container-format bare-file moban.qcow2-property hw_qemu_guest_agent=yes-public

Or

Glance image-create-progress-- name 'centos7.3.raw'-- container-format=bare-- disk-format=raw-- min-ram=1024-- property architecture=x86_64-- property os_distro=linux-- property os_version=7.3-- property vol_size=24-- property hw_qemu_guest_agent=yes-- file centos7.3.raw

Be careful

Be sure to set the hw_qemu_guest_agent=yes for property, otherwise the qemu-ga configuration item will not be generated when libvert starts the virtual machine, which will cause the qemu-ga inside the virtual machine to fail to find the channel because it cannot find the corresponding virtual serial character device.

If you forget the password of the virtual machine after creating the virtual machine, you can modify it directly.

Virsh set-user-password

Here are a few small command operations based on agent.

1. Shut down / restart the virtual machine

# virsh shutdown/reboot domain-the default way for mode=agentvirsh shutdown/reboot is to use ACPI--mode=acpi to omit Linux virtual machines without ACPI and Windows virtual machines that do not respond to virsh shutdown/reboot domain instructions. Use-- mode=agent QEMU guest agent to ensure that the virtual machine completes the shutdown / restart action.

two。 Stable snapshot

# virsh snapshot-create-as domain-disk-only-quiesce

Through the qga virtual machine, the high stability of the disk content is ensured by flush Izuro before creating the snapshot.

3. Freeze / restore / organize the file system

# virsh domfsfreeze/domfsthaw/domfstrim domain

4. Query virtual machine IP

# virsh domifaddr domain-source agent

Note this directive is not supported in qga version 2.1.0

5. Displays the file system mounted by the virtual machine

# virsh domfsinfo domain

Note this directive is not supported in the qga2.1.0 version

TBD

6. Query / set virtual machine system time

# virsh domtime domain-pretty # query virtual machine time # virsh domtime domain-now # set the virtual machine time to the current time of the host

The solution to the problem of setting the virtual machine time is still being explored.

7. Set virtual machine user password

# virsh set-user-password

Copy the code

This directive cannot be run in both qga 2.1.0 and 2.3.0 versions. It is estimated that the qga package version in RedHat 7 is a little newer than the existing centos version.

# # #

Openstack Technology Exchange Group: 580078423

I hope all of you will join the group and communicate more.

Tags: Machine time version password instruction system query command platform snapshot file method method time communication guarantee support configuration code content action Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Docker OPPO Reno Huawei