Skip to content

Instantly share code, notes, and snippets.

@danktec
Last active March 14, 2024 02:10

Revisions

  1. danktec revised this gist Mar 14, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kvm.sh
    Original file line number Diff line number Diff line change
    @@ -17,13 +17,13 @@ sudo qemu-img convert -f qcow2 noble-server-cloudimg-amd64.img /var/lib/libvirt/
    (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
  2. danktec revised this gist Mar 14, 2024. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions kvm.sh
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,13 @@ sudo qemu-img convert -f qcow2 noble-server-cloudimg-amd64.img /var/lib/libvirt/
    (from inside the VM: lsblk /dev/vda)

    # Create a cloud-config file named cloud.txt
    ```
    #cloud-config
    password: password1
    chpasswd: { expire: False }
    ssh_pwauth: True
    hostname: test1
    ```
    # Convert the cloud config file to a bootable iso image
    sudo cloud-localds /var/lib/libvirt/images/test1.iso cloud.txt
  3. danktec revised this gist Mar 14, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kvm.sh
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ ref: https://www.theurbanpenguin.com/using-cloud-images-in-kvm/
    sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm virt-manager cloud-image-utils
    kvm-ok

    # Install OS from iso
    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'
    # 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
  4. danktec revised this gist Mar 14, 2024. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions kvm.sh
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,10 @@ ref: https://www.theurbanpenguin.com/using-cloud-images-in-kvm/
    sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm virt-manager cloud-image-utils
    kvm-ok


    # Install OS from iso
    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 cloud image

    # 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

  5. danktec revised this gist Mar 14, 2024. 1 changed file with 8 additions and 18 deletions.
    26 changes: 8 additions & 18 deletions kvm.sh
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,31 @@
    ref: https://www.theurbanpenguin.com/using-cloud-images-in-kvm/

    Install KVM Deps:

    # 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 OS from iso
    ```bash
    # Install OS from iso
    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 cloud image
    ```bash
    # Get 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
    ```bash
    # 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
    # Create a cloud-config file named cloud.txt

    Convert the cloud config file to a bootable iso image
    ```bash
    # 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
    ```bash
    # 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
  6. danktec created this gist Mar 14, 2024.
    46 changes: 46 additions & 0 deletions kvm.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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 OS from iso
    ```bash
    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 cloud image
    ```bash
    wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
    qemu-img info noble-server-cloudimg-amd64.img
    ```

    Resize cloud image
    ```bash
    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

    Convert the cloud config file to a bootable iso image
    ```bash
    sudo cloud-localds /var/lib/libvirt/images/test1.iso cloud.txt
    ```

    Start up the System
    ```bash
    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