get cloud-init working consistently
All checks were successful
Podman DDNS Image / build-and-push-ddns (push) Successful in 54s
All checks were successful
Podman DDNS Image / build-and-push-ddns (push) Successful in 54s
This commit is contained in:
@@ -1 +1 @@
|
|||||||
local-hostname: al-2023
|
local-hostname: cloud-init-vm
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
users:
|
users:
|
||||||
- default
|
- default
|
||||||
- name: ec2-user
|
- name: ducoterra
|
||||||
lock_passwd: false
|
lock_passwd: false
|
||||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ Virtual Machine Management
|
|||||||
|
|
||||||
- [Virsh](#virsh)
|
- [Virsh](#virsh)
|
||||||
- [Before you Begin](#before-you-begin)
|
- [Before you Begin](#before-you-begin)
|
||||||
|
- [Connecting to External Servers via SSH](#connecting-to-external-servers-via-ssh)
|
||||||
|
- [Configuring Aliases](#configuring-aliases)
|
||||||
|
- [One-off Connections](#one-off-connections)
|
||||||
- [Useful Virsh Commands](#useful-virsh-commands)
|
- [Useful Virsh Commands](#useful-virsh-commands)
|
||||||
- [Virsh Networking](#virsh-networking)
|
- [Virsh Networking](#virsh-networking)
|
||||||
- [Create a Virtual Network](#create-a-virtual-network)
|
- [Create a Virtual Network](#create-a-virtual-network)
|
||||||
@@ -13,10 +16,11 @@ Virtual Machine Management
|
|||||||
- [Set a Static IP](#set-a-static-ip)
|
- [Set a Static IP](#set-a-static-ip)
|
||||||
- [Creating VMs](#creating-vms)
|
- [Creating VMs](#creating-vms)
|
||||||
- [Create VM with No Graphics and use an Existing QCOW2 Disk](#create-vm-with-no-graphics-and-use-an-existing-qcow2-disk)
|
- [Create VM with No Graphics and use an Existing QCOW2 Disk](#create-vm-with-no-graphics-and-use-an-existing-qcow2-disk)
|
||||||
- [Cloud Init Compatible VMs](#cloud-init-compatible-vms)
|
- [Create a Cloud Init Compatible VM](#create-a-cloud-init-compatible-vm)
|
||||||
- [Create VM with Graphics using an ISO Installation Disk](#create-vm-with-graphics-using-an-iso-installation-disk)
|
- [Create VM with Graphics using an ISO Installation Disk](#create-vm-with-graphics-using-an-iso-installation-disk)
|
||||||
- [Create VM using Host Device as Disk](#create-vm-using-host-device-as-disk)
|
- [Create VM using Host Device as Disk](#create-vm-using-host-device-as-disk)
|
||||||
- [Snapshots](#snapshots)
|
- [Snapshots](#snapshots)
|
||||||
|
- [Virt Builder](#virt-builder)
|
||||||
|
|
||||||
## Before you Begin
|
## Before you Begin
|
||||||
|
|
||||||
@@ -28,6 +32,29 @@ Virtual Machine Management
|
|||||||
6. Tell virsh to connect to your root system rather than your user: `export LIBVIRT_DEFAULT_URI='qemu:///system'`
|
6. Tell virsh to connect to your root system rather than your user: `export LIBVIRT_DEFAULT_URI='qemu:///system'`
|
||||||
7. Export your editor so virsh knows what to use: `export EDITOR=vim`
|
7. Export your editor so virsh knows what to use: `export EDITOR=vim`
|
||||||
|
|
||||||
|
## Connecting to External Servers via SSH
|
||||||
|
|
||||||
|
<https://libvirt.org/uri.html#ssh-transport>
|
||||||
|
|
||||||
|
### Configuring Aliases
|
||||||
|
|
||||||
|
1. Edit `~/.config/libvirt/libvirt.conf`
|
||||||
|
2. Add your aliases
|
||||||
|
|
||||||
|
```bash
|
||||||
|
uri_aliases = [
|
||||||
|
"3dserver=qemu+ssh://3dserver/system",
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Export the alias: `export LIBVIRT_DEFAULT_URI=3dserver`
|
||||||
|
|
||||||
|
### One-off Connections
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export LIBVIRT_DEFAULT_URI='qemu+ssh://user@server/system'
|
||||||
|
```
|
||||||
|
|
||||||
## Useful Virsh Commands
|
## Useful Virsh Commands
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -207,10 +234,42 @@ virt-install \
|
|||||||
--import --disk "path=${VM_DISK_PATH},bus=virtio"
|
--import --disk "path=${VM_DISK_PATH},bus=virtio"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Cloud Init Compatible VMs
|
#### Create a Cloud Init Compatible VM
|
||||||
|
|
||||||
|
<https://cloudinit.readthedocs.io/en/latest/reference/examples.html>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
--cloud-init user-data="active/software_virsh/cloud-init/user-data,meta-data=active/software_virsh/cloud-init/meta-data"
|
# Fedora
|
||||||
|
# https://fedoraproject.org/cloud/download
|
||||||
|
export VM_NAME="cloud-init-test-fedora"
|
||||||
|
export VM_DISK_PATH=/var/lib/libvirt/images/Fedora-Cloud-Base-Generic-43-1.6.x86_64.qcow2
|
||||||
|
|
||||||
|
# Rocky
|
||||||
|
# https://rockylinux.org/download
|
||||||
|
export VM_NAME="cloud-init-test-rocky"
|
||||||
|
export VM_DISK_PATH=/var/lib/libvirt/images/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2
|
||||||
|
|
||||||
|
# Ubuntu
|
||||||
|
# https://cloud-images.ubuntu.com/noble/current/
|
||||||
|
export VM_NAME="cloud-init-test-ubuntu"
|
||||||
|
export VM_DISK_PATH=/var/lib/libvirt/images/noble-server-cloudimg-amd64.img
|
||||||
|
|
||||||
|
# Debian
|
||||||
|
# https://cloud.debian.org/images/cloud/trixie/20251117-2299/
|
||||||
|
export VM_NAME="cloud-init-test-debian"
|
||||||
|
export VM_DISK_PATH=/var/lib/libvirt/images/debian-13-generic-amd64-20251117-2299.qcow2
|
||||||
|
|
||||||
|
# Set --cloud-init disable=no to allow cloud-init to run again after first boot
|
||||||
|
virt-install \
|
||||||
|
--name "${VM_NAME}" \
|
||||||
|
--boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
|
||||||
|
--cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \
|
||||||
|
--ram=8192 \
|
||||||
|
--os-variant=fedora41 \
|
||||||
|
--network bridge:virbr0 \
|
||||||
|
--graphics none \
|
||||||
|
--import --disk "path=${VM_DISK_PATH},bus=virtio" \
|
||||||
|
--cloud-init disable=yes,user-data="active/software_virsh/cloud-init/user-data,meta-data=active/software_virsh/cloud-init/meta-data"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create VM with Graphics using an ISO Installation Disk
|
### Create VM with Graphics using an ISO Installation Disk
|
||||||
@@ -222,8 +281,8 @@ virt-install \
|
|||||||
# `--console pty,target.type=virtio` adds a console connection
|
# `--console pty,target.type=virtio` adds a console connection
|
||||||
# For any command, use `virt-install --arg=?` to see all available options
|
# For any command, use `virt-install --arg=?` to see all available options
|
||||||
export VM_NAME="fedora43-kinoite-test"
|
export VM_NAME="fedora43-kinoite-test"
|
||||||
export VM_ISO_PATH=/var/lib/libvirt/iso/
|
export VM_ISO_PATH=/var/lib/libvirt/iso/fedora43.iso
|
||||||
export VM_DISK_PATH=/var/lib/libvirt/images/
|
export VM_DISK_PATH=/var/lib/libvirt/images/fedora43.qcow2
|
||||||
virt-install \
|
virt-install \
|
||||||
--name "${VM_NAME}" \
|
--name "${VM_NAME}" \
|
||||||
--boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
|
--boot uefi,firmware.feature0.name=secure-boot,firmware.feature0.enabled=no \
|
||||||
@@ -262,3 +321,33 @@ virt-install \
|
|||||||
## Snapshots
|
## Snapshots
|
||||||
|
|
||||||
See [qemu qcow2 snapshots](/active/software_qemu/qemu.md#qcow2-snapshots)
|
See [qemu qcow2 snapshots](/active/software_qemu/qemu.md#qcow2-snapshots)
|
||||||
|
|
||||||
|
## Virt Builder
|
||||||
|
|
||||||
|
<https://docs.fedoraproject.org/en-US/fedora-server/virtualization/vm-install-diskimg-virtbuilder/#_minimal_effort_customization>
|
||||||
|
|
||||||
|
You can use virt-builder to build vm images
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export VM_NAME=fedora42-vb
|
||||||
|
export VM_DISK_PATH=/var/lib/libvirt/images/fedora42-vb.qcow2
|
||||||
|
|
||||||
|
# Build the image
|
||||||
|
virt-builder fedora-42 \
|
||||||
|
--format qcow2 --output ${VM_DISK_PATH} \
|
||||||
|
--root-password locked:disabled \
|
||||||
|
--hostname ${VM_NAME} \
|
||||||
|
--selinux-relabel \
|
||||||
|
--firstboot-command 'useradd -m -G wheel -p "" ducoterra ; chage -d 0 ducoterra'
|
||||||
|
|
||||||
|
# Run the built image
|
||||||
|
virt-install \
|
||||||
|
--name "${VM_NAME}" \
|
||||||
|
--cpu host-passthrough --vcpus sockets=1,cores=8,threads=2 \
|
||||||
|
--ram=8192 \
|
||||||
|
--os-variant=fedora41 \
|
||||||
|
--network bridge:virbr0 \
|
||||||
|
--graphics none \
|
||||||
|
--console pty,target.type=virtio \
|
||||||
|
--import --disk "path=${VM_DISK_PATH},bus=virtio"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user