josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
540 stars 154 forks source link

Failed to grow boot disk on Windows Ova #137

Closed alby97 closed 3 years ago

alby97 commented 3 years ago

Hi everyone, I'm trying to deploy with this provider some ova that I built with Packer. It appears that with Ubuntu/Linux based ova I have no problem on changing the boot_disk_size (for example if I build the ova with Packer with disk_size = 20 GB and in the main.tf the boot_disk_size is 40 GB it gives me no errors). Otherwise trying with Windows I encounter the following error after about 5 minutes: Error: Failed to grow boot disk: Process exited with status 255. I don't know what is the problem (it could be is a specific Windows problem or it could be the Autounattend.xml that I use to build it but it's just an assumption). So I would ask if anyone encountered this problem and if there is a way to solve it. Thanks in advance.

josenk commented 3 years ago

You might want to enable Terraform debugging...

https://www.terraform.io/docs/internals/debugging.html

The only reason I know that the boot disk cannot be extended is that it's busy (the VM is running). The grow boot disk code should happen when the VM is powered off. Maybe the debugging information might give us a clue what's going on...

alby97 commented 3 years ago

Hi, I enabled debugging and I post here the lines that are related to the error:

2021-03-06T03:59:47.373-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-guest-create.go:298: [guestCREATE] ovftool output: "Opening OVA source: /home/user/Desktop/app/Base Boxes/Windows Server 2019/packer-vmware-iso.ova\nThe manifest validates\nOpening VI target: vi://root@10.0.0.41:443//\nDeploying to VI: vi://root@10.0.0.41:443//\n\rDisk progress: 1%\rDisk progress: 2%\rDisk progress: 3%\rDisk progress: 4%\rDisk progress: 5%\rDisk progress: 6%\rDisk progress: 7%\rDisk progress: 8%\rDisk progress: 9%\rDisk progress: 10%\rDisk progress: 11%\rDisk progress: 12%\rDisk progress: 13%\rDisk progress: 14%\rDisk progress: 15%\rDisk progress: 16%\rDisk progress: 17%\rDisk progress: 18%\rDisk progress: 19%\rDisk progress: 20%\rDisk progress: 21%\rDisk progress: 22%\rDisk progress: 23%\rDisk progress: 24%\rDisk progress: 25%\rDisk progress: 26%\rDisk progress: 27%\rDisk progress: 28%\rDisk progress: 29%\rDisk progress: 30%\rDisk progress: 31%\rDisk progress: 32%\rDisk progress: 33%\rDisk progress: 34%\rDisk progress: 35%\rDisk progress: 36%\rDisk progress: 37%\rDisk progress: 38%\rDisk progress: 39%\rDisk progress: 40%\rDisk progress: 41%\rDisk progress: 42%\rDisk progress: 43%\rDisk progress: 44%\rDisk progress: 45%\rDisk progress: 46%\rDisk progress: 47%\rDisk progress: 48%\rDisk progress: 49%\rDisk progress: 50%\rDisk progress: 51%\rDisk progress: 52%\rDisk progress: 53%\rDisk progress: 54%\rDisk progress: 55%\rDisk progress: 56%\rDisk progress: 57%\rDisk progress: 58%\rDisk progress: 59%\rDisk progress: 60%\rDisk progress: 61%\rDisk progress: 62%\rDisk progress: 63%\rDisk progress: 64%\rDisk progress: 65%\rDisk progress: 66%\rDisk progress: 67%\rDisk progress: 68%\rDisk progress: 69%\rDisk progress: 70%\rDisk progress: 71%\rDisk progress: 72%\rDisk progress: 73%\rDisk progress: 74%\rDisk progress: 75%\rDisk progress: 76%\rDisk progress: 77%\rDisk progress: 78%\rDisk progress: 79%\rDisk progress: 80%\rDisk progress: 81%\rDisk progress: 82%\rDisk progress: 83%\rDisk progress: 84%\rDisk progress: 85%\rDisk progress: 86%\rDisk progress: 87%\rDisk progress: 88%\rDisk progress: 89%\rDisk progress: 90%\rDisk progress: 91%\rDisk progress: 92%\rDisk progress: 93%\rDisk progress: 94%\rDisk progress: 95%\rDisk progress: 96%\rDisk progress: 97%\rDisk progress: 98%\rDisk progress: 99%\rTransfer Completed \nCompleted successfully\n" 2021-03-06T03:59:47.373-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-guest_functions.go:14: [guestGetVMID] 2021-03-06T03:59:47.373-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-esxi_remote_cmds.go:61: [runRemoteSshCommand] :get vmid 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-esxi_remote_cmds.go:78: [runRemoteSshCommand] cmd:/vim-cmd vmsvc/getallvms 2>/dev/null |sort -n | grep -m 1 "[0-9] * Windows_Server_2019_2 .*Windows_Server_2019_2" |awk '{print $1}' / 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: stdout:/284/ 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: stderr:/%!s(<nil>)/ 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-guest_functions.go:23: [guestGetVMID] result: 284 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-guest_functions.go:54: [getBootDiskPath] 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-esxi_remote_cmds.go:61: [runRemoteSshCommand] :get boot disk 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-esxi_remote_cmds.go:78: [runRemoteSshCommand] cmd:/vim-cmd vmsvc/device.getdevices 284 | grep -A10 'key = 2000'|grep -m 1 fileName/ 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: stdout:// 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: stderr:/Process exited with status 1/ 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-guest_functions.go:62: [getBootDiskPath] Failed get boot disk path: 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-virtual-disk_functions.go:110: [growVirtualDisk] 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-virtual-disk_functions.go:136: [virtualDiskREAD] Begin 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-virtual-disk_functions.go:146: [virtualDiskREAD] len=1 cap=1 [Failed get boot disk path:] 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-virtual-disk_functions.go:118: [growVirtualDisk] currentDiskSize:0 new_size:45 fullPATH: Failed get boot disk path: 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-esxi_remote_cmds.go:61: [runRemoteSshCommand] :grow disk 2021-03-06T03:59:48.165-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: pid-1754129-esxi_remote_cmds.go:78: [runRemoteSshCommand] cmd://bin/vmkfstools -X 45G "Failed get boot disk path:"/ 2021-03-06T03:59:48.165-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: stdout:/Failed to extend disk : The system cannot find the file specified (25)./ 2021-03-06T03:59:48.165-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: stderr:/Process exited with status 255/ 2021/03/06 03:59:48 [DEBUG] esxi_guest.Windows_Server_2019_2: apply errored, but we're indicating that via the Error pointer rather than returning it: Failed to grow boot disk: Process exited with status 255

It seems like it didn't find the disk, it says "Failed to extend disk : The system cannot find the file specified". Thanks for the answer @josenk . Ps. Sorry if the layout of my reply isn't pretty.

josenk commented 3 years ago
pid-1754129-guest_functions.go:54: [getBootDiskPath] 2021-03-06T03:59:47.732-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: 
pid-1754129-esxi_remote_cmds.go:61: [runRemoteSshCommand] :get boot disk 2021-03-06T03:59:48.052-0800 [DEBUG] plugin.terraform-provider-esxi_v1.8.1: 
pid-1754129-esxi_remote_cmds.go:78: [runRemoteSshCommand] cmd:/vim-cmd vmsvc/device.getdevices 284 | grep -A10 'key = 2000'|grep -m 1 fileName/ 
  stdout://
  stderr:/Process exited with status 1/ 

I cleaned it up a bit... As you can see, the following command (which is run on your esxi box) produced no output and exited with exit code 1.

vim-cmd vmsvc/device.getdevices 284 | grep -A10 'key = 2000'|grep -m 1 fileName

This command should get the fileName of the boot disk.... Is there anything special you are setting for the boot disk?

Probably an easy work-around is to simply not extend the boot disk from Terraform (You can do it manually later). Or if you want to continue debugging this, you will need to send me your Terraform tf files and the output of vim-cmd vmsvc/device.getdevices XXX (Replace XXX with the VM id). (You can replace any private data/text if required....)

alby97 commented 3 years ago

I'm not setting nothing in particular, I simply specify the disk size already in the Packer template but with Ubuntu I didn't have this problem so maybe the only problem could be the Autounattend.xml file because it's the only difference, however, my Autounattend.xml file is similar to other template that I found on the web. Here is a sample main.tf that gives me the error:

terraform {
  required_version = ">= 0.12"
   required_providers {
    esxi = {
      source = "registry.terraform.io/josenk/esxi"
      #
      # For more information, see the provider source documentation:
      # https://github.com/josenk/terraform-provider-esxi
      # https://registry.terraform.io/providers/josenk/esxi
    }
  }
}

provider "esxi" {
  esxi_hostname = my_hostname
  esxi_hostport = my_port
  esxi_username = my_username
  esxi_password = my_password
}

resource "esxi_guest" "Windows_Server_2019_2"{
    disk_store = "datastore1"
    numvcpus = "2"
    memsize = "2048"
    boot_disk_size = "45"
    boot_disk_type = "thin"
    network_interfaces {
        virtual_network = "VM Network"
    }
    power = "on"
    ovf_source = "/path/to/my/windows/server/ova"
    guest_name = "Windows_Server_2019_2"
}

For example, the size that I specified when I built the ova is 35GB, here in this sample I specify 45GB and as I said it gives me the error. The output of the command is in the txt file attached. Thanks for the reply @josenk .

output_vim_cmd.txt

josenk commented 3 years ago

Looks like you are using SATA or IDE controller for your boot disk. Those controller types should be reserved for CD/DVD roms only. Technically you can use it for disks, but it's very poor performance.

https://www.packer.io/docs/builders/vmware/vmx#disk_adapter_type https://www.vmware.com/pdf/VirtualDiskManager.pdf

Page 9 of VirtualDiskManager.pdf.
ide – an IDE adapter, for compatibility with old software.

I highly recommend that you change your adapter type for best performance and to avoid this problem completely. I probably won't fix this issue because there is no modern need to use IDE with any current OS and there are easy work-arounds.

Work-arounds:

alby97 commented 3 years ago

Thank you I will try with nvme or scsi and let you know the results. Thanks a lot for the help @josenk. Ps. Do you know a way to grow the boot disk of a vm from esxi cli?

josenk commented 3 years ago

vmkfstools.

https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.storage.doc/GUID-97FED1EC-35A5-4EF2-80BA-7131F8455702.html