Customizing RHEL8.1 qcow2 image
Need following packages:
yum -y install libguestfs-tools
export VMDISK="registry.qcow2"
cp /root/rhel-8.1-x86_64-kvm.qcow2 /var/lib/libvirt/images/pool/${VMDISK}
chmod 644 /var/lib/libvirt/images/pool/${VMDISK}
chown qemu.qemu /var/lib/libvirt/images/pool/${VMDISK}
Run virt-sysprep with customiztions
export VMDISK="registry.qcow2"
export ROOTPASS="changeme"
export SUDOUSER="william"
export SSHKEYFILE="/root/.ssh/id_rsa.pub"
sudo virt-sysprep -a ${VMDISK} \
--root-password password:changeme \
--run-command 'useradd ${SUDOUSER}' \
--ssh-inject william:file:${SSHKEYFILE} \
--run-command 'sed -i s/cloud-user/${SUDOUSER}/g /etc/sudoers' \
--uninstall cloud-init \
--selinux-relabel
Expanding a Guest XFS File System
Need the following packages:
yum -y install libguestfs-tools guestfish
Shutdown the VM
Create new empty disk with desired size
export VMDISK="registry.qcow2"
# Create new empty disk weith desired size
qemu-img create -f qcow2 new-${VMDISK} 150G
# list existing partitions
virt-filesystems --long --parts --blkdevs -h -a new-${VMDISK}
Name Type MBR Size Parent
/dev/sda1 partition 83 7.8G /dev/sda
# use virt-reside expand the desired partition
virt-resize --expand /dev/sda1 ${VMDISK} new-${VMDISK}
# extending the xfs partition
guestfish --rw -a new-${VMDISK}
><fs> run
><fs> list-filesystems
/dev/sda1: xfs
><fs> mount /dev/sda1 /
><fs> xfs-growfs /
><fs> exit
# validate changes
virt-df -h registry-new.qcow2
Filesystem Size Used Available Use%
registry-new.qcow2:/dev/sda1 200G 5.6G 194G 3%
replace new disk by old disk
export VMDISK="registry.qcow2"
mv ${VMDISK} ${VMDISK}-bak
mv new-${VMDISK} to ${VMDISK}