How to change root password of cloud image

There are ways to manipulate cloud images. I’m going to prefer libguestfs to change root password.

Install libguestfs and tools:

yum install guestfs-tools
yum install libguestfs libguestfs-appliance libguestfs-xfs

Change root password,
mymagicpass is clean password,
mydisk.img is primary disk image:

LIBGUESTFS_BACKEND=direct virt-customize --root-password password:mymagicpass -a mydisk.img