This post share some simple commands for virtualmachines.
During day to day work there is a need to reproduce test scenarios/ bugs inside different environments at your dev working station or test labs.

With many cases, containers could be sufficient, but for other use cases interacts with containers as pods or docker compose, is not enough,

Automated tests with specific Operating Systems can be run locally or against AWS image or any other testing framwerk.

That post uses few commands that could be automated inside bash scripts or ansible playbooks later on.

Prepare cloud centos-stream-9 image for your work

curl --output-dir "/tmp" -O https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2
  • Increase disk size in +10G
qemu-img resize /tmp/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2 +20G
  • Set root password, remove cloud-init option and enable root login
virt-customize --uninstall cloud-init --root-password password:${PASSWORD} \
--edit '/etc/ssh/sshd_config: \
s/#PermitRootLogin.*/PermitRootLogin yes/' -a /tmp/CentOS-Stream-GenericCloud-9-latest.aarch64.qcow2  
  • Run virtual machine with port forwarding:
/usr/bin/qemu-system-x86_64 -smp 12 -enable-kvm -m 2G -machine q35 -cpu host -vnc 0.0.0.0:1 -k en-us -device virtio-net-pci,netdev=n0,mac=FE:30:26:a6:91:2d -netdev user,id=n0,net=10.0.2.0/24,hostfwd=tcp::2222-:22 -drive file=CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2,index=0,media=disk,format=qcow2,if=virtio,snapshot=off&

Verify vm is set

  • Ssh to running machine with new ${PASSWORD}:
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null  root@localhost -p 2222
  • Check your blockdevices:
lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0     11:0    1 1024M  0 rom  
vda    252:0    0   25G  0 disk 
└─vda1 252:1    0  7.8G  0 part /

Incase of xfs file type, use command blkid, use grows command

# Grow / to use the whole partition 
xfs_growfs /  
# Grow / to use the 50% partition 
growpart --free-percent=50 /dev/vda 1

Hits