cross-posted from: https://lemmy.world/post/31710629

I’m trying to boot some VMs using a script w/ a kickstart file. I’m using the following script that I found online and modified:

#!/usr/bin/env bash
#set -x
## Define variables
MEM_SIZE="8192"      # Memory setting in MiB
VCPUS="2"             # CPU Cores count
#OS_VARIANT="rocky9"   # List with osinfo-query  os
OS_VARIANT="rhel7.9"   # List with osinfo-query  os
ISO_FILE="~/Documents/software/os/RHEL-7.9-20200917.0-Server-x86_64-dvd1.iso" # Path to ISO file

case $OS_VARIANT in
        rhel7.9)
                KS=ks7.cfg;;
        rocky9)
                KS=ks9.cfg;;
esac

echo -en "Enter vm name: "
read VM_NAME
OS_TYPE="linux"
echo -en "Enter virtual disk size : "
read DISK_SIZE

DISK=~/.local/share/libvirt/images/${VM_NAME}.qcow2

echo "Creating disk"
sudo virt-install \
     --name ${VM_NAME} \
     --memory=${MEM_SIZE} \
     --vcpus=${VCPUS} \
     --location ${ISO_FILE} \
     --network network=default \
     --disk path=${DISK},size=${DISK_SIZE} \
     --graphics=none \
     --os-variant=${OS_VARIANT} \
     --console pty,target_type=serial \
     --initrd-inject ~/virt/${KS} --extra-args "inst.ks=file:/${KS} console=tty0 console=ttyS0,115200n8"

I’ve obfuscated the directory paths, but they’re all full paths and the script will build a VM. So basically just setting up a basic system, using the default network. Here’s the config for that:

<network connections='3'>
  <name>default</name>
  <uuid>61afc7f1-9c5e-4cra-8d18-e3cf4f9358e9</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:7c:32:9b'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

Looking at the XML for the VM, I see the following for the network:

<interface type='network'>
      <mac address='52:54:00:07:82:78'/>
      <source network='default' portid='800dfd67-d90a-42te-a0b7-c4c78cdae481' bridge='virbr0'/>
      <target dev='vnet7'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

When this VM is installing, and when it’s booted, it does not have an IP. Meanwhile, if I go through virt-manager and select the default network, it gets an IP just fine. I’ve tried running the virt-install command w/ and w/o sudo (I run virt-manager as me - I’m in the libvirt group). Looking at the virt-manager built VM:

    <interface type='network'>
      <mac address='52:54:00:5e:f5:05'/>
      <source network='default' portid='d57dbc56-759e-40f9-856f-9623f4801a93' bridge='virbr0'/>
      <target dev='vnet8'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

Looking at virbr0:

$ ip link show master virbr0
11: vnet7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master virbr0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:54:00:07:82:78 brd ff:ff:ff:ff:ff:ff
12: vnet8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master virbr0 state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether fe:54:00:5e:f5:05 brd ff:ff:ff:ff:ff:ff

Only difference I can see is one is created using virt-manager and the other using virt-install (which calls to virt-install, no?). I thought there was a way to see the actual virt-install command virt-manager was about to use when creating a VM, but I can’t find it. Also can’t find any logs to give me an idea why the VM isn’t getting an IP. Running ethtool on the VM interface shows a link. I’ve wasted too much time getting this to work, and all the documentation suggests it should “just work!”