Last active
March 14, 2024 02:10
-
-
Save danktec/7a12990bc61bf7f918d2d08bb4f18044 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref: https://www.theurbanpenguin.com/using-cloud-images-in-kvm/ | |
# Install KVM Deps | |
sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm virt-manager cloud-image-utils | |
kvm-ok | |
# Install an OS from an ISO file interactively | |
# sudo virt-install --name ubuntu-guest --os-variant ubuntu20.04 --vcpus 2 --ram 2048 --location http://ftp.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/ --network bridge=virbr0,model=virtio --graphics none --extra-args='console=ttyS0,115200n8 serial' | |
# Get a cloud image | |
wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img | |
qemu-img info noble-server-cloudimg-amd64.img | |
# Resize cloud image | |
qemu-img resize thing.img 10G | |
sudo qemu-img convert -f qcow2 noble-server-cloudimg-amd64.img /var/lib/libvirt/images/noble.img | |
(from inside the VM: lsblk /dev/vda) | |
# Create a cloud-config file named cloud.txt | |
echo " | |
#cloud-config | |
password: password1 | |
chpasswd: { expire: False } | |
ssh_pwauth: True | |
hostname: test1 | |
" > cloud.txt | |
# Convert the cloud config file to a bootable iso image | |
sudo cloud-localds /var/lib/libvirt/images/test1.iso cloud.txt | |
# Start up the System | |
sudo virt-install --name test1 --memory 2096 --disk /var/lib/libvirt/images/noble.img,device=disk,bus=virtio --disk /var/lib/libvirt/images/test1.iso,device=cdrom --os-variant=ubuntu16.04 --virt-type=kvm --graphics=none --network network=default,model=virtio --import | |
# View volumes in the default pool | |
virsh list --all | |
vol-list --pool default | |
# Destroy the vm | |
virsh destroy _domain_id | |
virsh underfine _domain_id | |
virsh vol-delete --pool default /var/lib/libvirt/images/noble.img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment