Virt-customize
From Leo's Notes
Last edited on 30 December 2021, at 01:12.
virt-customize is a tool that can customize virtual machine disk images in both raw and qcow2 formats.
Installation
On CentOS/RHEL or Ubuntu, install the libguestfs-tools package.
Usage
To modify images directly, set LIBGUESTFS_BACKEND=direct.
Cheat sheet
Run: export LIBGUESTFS_BACKEND=direct then one of the commands below.
| Task | Command |
|---|---|
| Set the root password | virt-customize -a vm_image.qcow2 --root-password password:new-password
|
| Install packages | virt-customize -a vm_image.qcow2 --install [vim,bash-completion,wget,curl,telnet,unzip]
|
| Update packages | virt-customize -a vm_image.qcow2 --update
|
| Upload a file into the VM | virt-customize -a vm_image.qcow2 --upload dhcp.conf:/etc/dhcp.conf
|
| Set timezone | virt-customize -a vm_image.qcow2 --timezone "America/Edmonton"
|
| Add an authorized key to root or some other user | virt-customize -a vm_image.qcow2 --ssh-inject root:./id_rsa.pub
|