Skip to content

Instantly share code, notes, and snippets.

@danpawlik
Last active December 10, 2024 08:08
Show Gist options
  • Save danpawlik/855729e58f6b6f343384dbc9de90a26f to your computer and use it in GitHub Desktop.
Save danpawlik/855729e58f6b6f343384dbc9de90a26f to your computer and use it in GitHub Desktop.
Inject user and key to the qcow2 image
# check file system which should be extended
virt-filesystems --long -h --all -a CentOS-Stream-GenericCloud-x86_64-10-20241204.0.x86_64.qcow2
# create new empty disk with desired size
qemu-img create -f qcow2 centos-stream-10.qcow2 100G ## Optionally add: -o preallocation=metadata
# expand root partition
virt-resize --expand /dev/sda3 CentOS-Stream-GenericCloud-x86_64-10-20241204.0.x86_64.qcow2 centos-stream-10.qcow2
# Modify image
virt-customize --run-command "groupadd -g 1000 centos" --run-command "useradd -u 1000 -g 1000 --home-dir /home/centos centos" -m 2048 -a centos-stream-10.qcow2
virt-customize --password 'centos:password:centos' --password-crypto sha512 -m 2048 -a centos-stream-10.qcow2
virt-customize --ssh-inject centos:file:/home/dpawlik/.ssh/id_rsa.pub -m 2048 -a centos-stream-10.qcow2
virt-customize --run-command "echo 'centos ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers" -m 2048 -a centos-stream-10.qcow2
virt-customize --root-password password:centos -m 2048 -a centos-stream-10.qcow2
virt-customize --ssh-inject root:file:/home/dpawlik/.ssh/id_rsa.pub -m 2048 -a centos-stream-10.qcow2
virt-customize -m 2048 -a centos-stream-10.qcow2 --update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment