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

Cannot deploy image after successful build. Is this an issue in windows packer template file. #278

Open
iamtinu opened this issue Nov 25, 2024 · 12 comments

Comments

@iamtinu
Copy link

iamtinu commented Nov 25, 2024

The default template file for windows creates a successful build on an ubuntu 24 VM but the build image gives error that:

tar: This does not look like a tar archive

So I figured the error tar This does not look like a tar archive indicates that the downloaded image is not in the expected format (likely not a valid .tar.gz or .tgz archive).

Broken Pipe: The Cannot write to ‘-’ (Broken pipe) error occurs because tar exited prematurely due to the invalid archive format, breaking the data stream to dd.

Filesystem Not Found:
After the failure, no partitions or filesystems are found on /dev/sda, causing the deployment to fail entirely.

I modified default packer file to make a new image file and successfully deployed on a raid filesystem. Can be deployed on other disk layouts too.

Changes :
Filename Updated:
Changed the output filename to .tar.gz for better compatibility with MAAS.

tar.gz Compression:
Updated the post-processor section to compress the output using tar -czf, which produces a .tar.gz file MAAS can decompress

Dynamic Filesystem Mounting:
The mount command now dynamically attempts to mount common filesystem types (ntfs, ext4, vfat) for adding curtin hooks.

Added Output Sync:
Added explicit sync commands to ensure file operations are flushed before moving to the next step.

below is the changed file for successful image building and successful deployment.

windows.pkr.hcl.txt

uploaded instead of pasting code : rename .txt to windows.pkr.hcl. Recreate the image and reupload using

maas yourprofile boot-resources create
name='windows/windows-server'
title='Windows Server 2016'
architecture='amd64/generic'
filetype='ddtgz'
content@=2016.dd.tar.gz

update : dont change filetype while uploading image from ddtgz to tgz

Thank You

@MggMuggins
Copy link

Hi! Can you open a pull request so that we can more easily see the changes you made here? Thanks!

@nics90
Copy link

nics90 commented Nov 25, 2024

Fixed some typos post which able to build the image:

packer {
  required_version = ">= 1.7.0"
  required_plugins {
    qemu = {
      version = "~> 1.0"
      source  = "github.com/hashicorp/qemu"
    }
  }
}


variable "headless" {
  type        = bool
  default     = false
  description = "Whether VNC viewer should not be launched."
}

variable "disk_size" {
  type    = string
  default = "32G"
}

variable "iso_path" {
  type    = string
  default = ""
}

variable "ovmf_suffix" {
  type    = string
  default = "_4M"
}

variable "filename" {
  type        = string
  default     = "windows.dd.tar.gz"
  description = "The filename of the tarball to produce"
}

variable "is_vhdx" {
  type        = bool
  default     = false
  description = "Whether we are building using a VHDX disk."
}

variable "use_tpm" {
  type        = string
  default     = "false"
  description = "Whether we are building using a virtual TPM device."
}

variable "timeout" {
  type    = string
  default = "1h"
}

locals {
  baseargs = [
    ["-cpu", "host"],
    ["-serial", "stdio"],
    ["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/OVMF/OVMF_CODE${var.ovmf_suffix}.ms.fd"],
    ["-drive", "if=pflash,format=raw,id=ovmf_vars,file=OVMF_VARS.fd"],
    ["-drive", "file=output-windows_builder/packer-windows_builder,format=raw"],
    ["-cdrom", "${var.iso_path}"],
    ["-drive", "file=drivers.iso,media=cdrom,index=3"],
    ["-boot", "d"]
  ]
  tpmargs = [
    ["-chardev", "socket,id=chrtpm,path=/tmp/swtpm/swtpm-sock"],
    ["-tpmdev", "emulator,id=tpm0,chardev=chrtpm"],
    ["-device", "tpm-tis,tpmdev=tpm0"]
  ]
}

source "qemu" "windows_builder" {
  accelerator       = "kvm"
  boot_command      = [""]
  boot_wait         = "2s"
  communicator      = "none"
  disk_interface    = "ide"
  disk_image        = "${var.is_vhdx}"
  disk_size         = "${var.disk_size}"
  floppy_files      = ["./http/Autounattend.xml", "./http/logon.ps1", "./http/rh.cer"]
  floppy_label      = "flop"
  format            = "raw"
  headless          = "${var.headless}"
  http_directory    = "http"
  iso_checksum      = "none"
  iso_url           = "${var.iso_path}"
  machine_type      = "q35"
  memory            = "4096"
  cpus              = "2"
  net_device        = "e1000"
  qemuargs          = concat(local.baseargs, (var.use_tpm == "yes" ? local.tpmargs : []))
  shutdown_timeout  = "${var.timeout}"
  vnc_bind_address  = "0.0.0.0"
}

build {
  sources = ["source.qemu.windows_builder"]

  post-processor "shell-local" {
    inline = [
      "echo 'Syncing output-windows_builder/packer-windows_builder...'",
      "sync -f output-windows_builder/packer-windows_builder",
      "IMG_FMT=raw",
      "source scripts/setup-nbd",
      "TMP_DIR=$(mktemp -d /tmp/packer-maas-XXXX)",
      "echo 'Adding curtin-hooks to image...'",
      "mount -t ntfs $${nbd}p3 $TMP_DIR || mount -t ext4 $${nbd}p3 $TMP_DIR || mount -t vfat $${nbd}p3 $TMP_DIR",
      "mkdir -p $TMP_DIR/curtin",
      "cp ./curtin/* $TMP_DIR/curtin/",
      "sync -f $TMP_DIR/curtin",
      "umount $TMP_DIR",
      "qemu-nbd -d $nbd",
      "rmdir $TMP_DIR",
      "tar -czf ${var.filename} -C output-windows_builder packer-windows_builder",
      "echo 'Image created: ${var.filename}'"
    ]
    inline_shebang = "/bin/bash -e"
  }

  post-processor "compress" {
    output = "${var.filename}"
  }
}

The installation finished but OS failed to come up with below errors:

image

@alanbach
Copy link
Contributor

Hello Everyone! Please note that Windows images are not tar.gz. They are DD images and need to be imported accordingly in MAAS. Please see the README file for an example also this:

$ maas ${PROFILE} boot-resources create name='windows/windows-11' title='Windows 11' architecture='amd64/generic' filetype=ddgz content@=windows11.dd.gz

@nics90
Copy link

nics90 commented Nov 26, 2024

@alanbach : I created dd image from the template in the repo, still after deploying getting the same error:

'Unable to mount root fs on unknown block'

@iamtinu
Copy link
Author

iamtinu commented Nov 26, 2024

windows.pkr.hcl.txt

I was able to successfully build image and tested successful deployment on a proxmox VM.

Screenshot 2024-11-25 164912

Attaching the modified packer file in txt format as github allow limited file extensions for upload.

But I think there is some issue on baremetal servers. My two dedicated servers wont go past windows logo. probably bios setting but I doubt it. I have uefi boot enabled, secure boot disabled, and disabled TPM on server and everything works fine in VM. but different story on a baremetal.

@iamtinu
Copy link
Author

iamtinu commented Nov 26, 2024

Hello Everyone! Please note that Windows images are not tar.gz. They are DD images and need to be imported accordingly in MAAS. Please see the README file for an example also this:

$ maas ${PROFILE} boot-resources create name='windows/windows-11' title='Windows 11' architecture='amd64/generic' filetype=ddgz content@=windows11.dd.gz

@alanbach You can upload successfully but you will run into error "This does not look like a tar archive" while deployment.

Hence the whole thread.

@iamtinu
Copy link
Author

iamtinu commented Nov 26, 2024

@alanbach : I created dd image from the template in the repo, still after deploying getting the same error:

'Unable to mount root fs on unknown block'

@nics90 try the changes I mentioned in the notepad file from my comments. and use that packer file to generate image for deployment

@iamtinu
Copy link
Author

iamtinu commented Nov 26, 2024

Hi! Can you open a pull request so that we can more easily see the changes you made here? Thanks!

@MggMuggins Updated the main thread with a notepad file. rename it and rebuild the image and try deployment then.

@nics90
Copy link

nics90 commented Nov 26, 2024

@iamtinu : I uploaded the image using below command:

maas admin boot-resources create name='windows/win2k19' title='Windows Server 2019' architecture='amd64/generic' filetype='ddtgz' content@=/home/devops/windows2019.dd.tar.gz

and I'm using KVM with maas latest version to commission the machine, but got same error.

@iamtinu
Copy link
Author

iamtinu commented Nov 27, 2024

I cant test on KVM I am using another proxmox server and two baremetal servers. worked for me.

@nics90
Copy link

nics90 commented Nov 27, 2024

Did it work for you on baremetal ? Since I also tried on baremetal, operating system got installed but failed to come up :

image

dellsrv3.maas-installation-output-2024-11-27.log

@iamtinu
Copy link
Author

iamtinu commented Nov 27, 2024

Did it work for you on baremetal ? Since I also tried on baremetal, operating system got installed but failed to come up :

image

dellsrv3.maas-installation-output-2024-11-27.log

on baremetal my OS installs. that specific error is related to uefi I think. check TPM disabled, CSM disabled, uefi on and correct boot partition is marked as second boot option after setting network boot as first. I think you already installed OS just boot problem.
If that not works. release the server and quick erase disk . commission the machine again, then deploy.

in your previous logs I can also see PERC H755 Front so ensure drivers for the disk controller (PERC H755 Front) are loaded. Check with:
lspci -k | grep -A 2 PERC

If the drivers for PERC H755 are missing, rebuild the initramfs:
chroot /mnt
update-initramfs -u

Missing Bootloader or EFI Files. The EFI partition (/dev/sda1) was wiped and likely not re-populated with GRUB/bootloader files.
Without these files, the system cannot boot.

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

4 participants