dmacvicar / terraform-provider-libvirt

Terraform provider to provision infrastructure with Linux's KVM using libvirt
Apache License 2.0
1.54k stars 457 forks source link

Volume resizing causes kernel panic on first boot #948

Closed markcaudill closed 1 year ago

markcaudill commented 2 years ago

System Information

Linux distribution

Workstation

$ lsb_release -a
No LSB modules are available.
Distributor ID: Pop
Description:    Pop!_OS 22.04 LTS
Release:    22.04
Codename:   jammy

Target Host

$ ssh hermes lsb_release -a
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye
No LSB modules are available.

Terraform version

$ terraform version
Terraform v1.1.9
on linux_amd64
+ provider registry.terraform.io/dmacvicar/libvirt v0.6.14
+ provider registry.terraform.io/hashicorp/template v2.2.0

Provider and libvirt versions

$ cd .terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.6.14/linux_amd64
/home/mark/src/infra/volume_size_test/.terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.6.14/linux_amd64

$ ./terraform-provider-libvirt_v0.6.14 -version
./terraform-provider-libvirt_v0.6.14 0.6.14

Checklist

Description of Issue/Question

Setup

terraform {
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "0.6.14"
    }
  }
}

provider "libvirt" {
  uri = "qemu+ssh://vmmgr@hermes/system"
}

resource "libvirt_volume" "debian11" {
  name   = "debian11"
  pool   = "default"
  source = "https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2"
}

# OS Volume
resource "libvirt_volume" "os_volume" {
  base_volume_id = libvirt_volume.debian11.id
  name           = "os_volume"
  pool           = "default"
  size           = 10737418240 # 10GiB
}

# VM
resource "libvirt_domain" "vm" {
  autostart  = true
  memory     = 2048
  name       = "test-host-01"
  qemu_agent = true
  running    = true
  vcpu       = 2

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

  disk {
    volume_id = libvirt_volume.os_volume.id
  }

  network_interface {
    network_name   = "default"
    hostname       = "test-host-01"
    wait_for_lease = true
  }
}

Steps to Reproduce Issue

  1. Run terraform apply results in a hung VM with a kernel panic.

    image

  2. I can manually reset the VM and it then boots normally and comes online.

  3. If I remove/comment out the size parameter of libvirt_volume.os_volume then the initial terraform apply brings the VM online properly.

    resource "libvirt_volume" "os_volume" {
      base_volume_id = libvirt_volume.debian11.id
      name           = "os_volume"
      pool           = "default"
      #size           = 10737418240 # 10GiB
    }

Additional information:

Do you have SELinux or Apparmor/Firewall enabled? Some special configuration? Have you tried to reproduce the issue without them enabled?

sk4zuzu commented 1 year ago

Hi @markcaudill

This problem is unrelated to the provider itself.

Here's some bug report from Ubuntu https://bugs.launchpad.net/ubuntu/+source/cloud-initramfs-tools/+bug/1123220 which is exactly the same issue. I believe there are two ways to fix it, it's either as suggested in the report (you need to add serial console) or you can remove it from from grub config completely (all stuff containing "ttyS").

markcaudill commented 1 year ago

@sk4zuzu this is very helpful! Thanks!

nova1prime98 commented 1 year ago

works perfectly

resource "libvirt_domain" "machine" {
  console {
    type        = "pty"
    target_port = "0"
    target_type = "serial"
  }
}