Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a CDRom with ISO to boot from ? #1076

Open
gabrielmccoll opened this issue Feb 28, 2024 · 2 comments
Open

Create a CDRom with ISO to boot from ? #1076

gabrielmccoll opened this issue Feb 28, 2024 · 2 comments

Comments

@gabrielmccoll
Copy link

I am likely just being ignorant but just am trying to mimic what I've done in virt manager and create a vm with a 20GB disk and a cdrom using the iso I have to boot from.
I can get the vm (domain) to boot and make a 20GB disk (tho slightly different) but I can't seem to make a CDRom to boot from.
Any steer please ?

@rgherta
Copy link

rgherta commented May 11, 2024

Hi @gabrielmccoll

When you provision from virt-manager, you create a VM with a cdrom attached with an install ISO and an extra disk volume where the actual filesystem will be installed. Then virt-manager sets a boot order of disk first, then cdrom. Since the disk is empty, this is how it chooses to boot from cdrom and when you open virt-viewer you see the options "Install or Test OS". Then you make a manual choice and if you chose install - the anakonda installer starts where you need to provide some manual options. To simulate this aspect, please take a look at this main.tf file

terraform {
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "0.7.6"
    }
    tls = {
      source = "hashicorp/tls"
      version = "4.0.5"
    }
  }
}


provider "libvirt" {
  uri = "qemu:///system"
}

resource "libvirt_volume" "root" {
  name  = "root"
  size  = 50 * 1024 * 1024 * 1024 # 50 GB
  pool  = "default"
}

resource "libvirt_domain" "vm" {
  name        = "my_test_vm"
  memory      = 4096
  vcpu        = 2

  network_interface {
    network_name   = "default"
    wait_for_lease = false
  }

  disk {
    file = "/absolute/path/to/fedora40-server.iso"
  }

  disk {
    volume_id = libvirt_volume.root.id
    scsi      = "true"
  }

  boot_device {
    dev = [ "hd", "cdrom"]
  }

  console {
    type        = "pty"
    target_port = "0"
    target_type = "serial"
  }

  console {
    type        = "pty"
    target_type = "virtio"
    target_port = "1"
  }

  graphics {
    type        = "spice"
    listen_type = "address"
    autoport    = true
  }

}

The drawback is that you will have to wait for the installation process that can be quite slow. You could automate this process using kickstart files but to my knowledge there is no way to do it with the current provider configuration. This provider is usually made for cloudinit, ignition, and prebuilt images(virt-installer) that already have the entire filesystem and/or whatever services are requires by cloudinit and ignition. If you are well versed with libvirt, the xml option in this provider gives you the liberty to override and provide direct xml configurations that could help with the kickstart workaround.

@rgherta
Copy link

rgherta commented May 11, 2024

To build an image that has the entire vm filesystem, run this command

sudo virt-install --connect qemu:///system  \
     --name tmpvm \
     --memory=2048 \
     --vcpus=2 \
     --location fedora40-server.iso \
     --disk ./fedora39_disk.qcow2,size=30 \
     --network bridge=virbr0 \
     --graphics=none \
     --transient \
     --os-variant=fedora39 \
     --console pty,target_type=serial \
     --initrd-inject kickstart.ks --extra-args "inst.ks=file:/kickstart.ks console=tty0 console=ttyS0,115200n8"

The kickstart file contains all the options you manually input by hand in the anaconda installer for example in the above step. An example of such kickstart.ks can be the following

# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/performing_an_advanced_rhel_9_installation/kickstart-installation-basics_installing-rhel-as-an-experienced-user

# Generated by Anaconda 39.32.6
# Generated by pykickstart v3.48
#version=DEVEL
# Use graphical install
text --non-interactive

# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# System timezone
timezone Europe/Rome --utc

# Run the Setup Agent on first boot
firstboot --enable

poweroff --eject

%packages
@^server-product-environment

%end

# Use automatic partitioning with custom layout
ignoredisk --only-use=vda
autopart --noswap
# Clear existing partitions
clearpart --none --initlabel

rootpw --plaintext linux

user --name=maintainer --gecos="maintainer" --groups="wheel" --password maintainer --plaintext

%post --erroronfail --nochroot
echo "hello world"
%end

virt-install will successfully run and build fedora39_disk.qcow2 - this is the disk image that you can give to the terraform provisioner and will have a complete installed system with user, packages and whatever kickstart allows to customize...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants