Preseed Debian/Ubuntu with a cdrom drive?

Hi,

I’m trying to build i a minimal installation of several Debian and Ubuntu Versions on vmware vsphere using the packer provider “vsphere-iso”. I want to use an upstream installation ISO and provide a preseed file. To do so I found several howtos to provide the preseed file as a floppy disk and also using the built-in http server (e.g. Unattended Debian/Ubuntu Installation | Packer by HashiCorp).

However both variants are not suitable for me:

  • floppy disk variant will fail on newer distributions since floppy drivers were removed from newer linux kernels
  • http server would theoretically work but in practice I want to create a CI/CD pipeline (gitlab-ci), were the build runs inside a docker container

I have successfully built such pipelines for Centos derivates (e.g. Centos 7), were I use govc to build an ISO from kickstart file for Anaconda and upload it to my datastore before doing the packer build. The build VM results in having 2 cdrom drives, one for Installation disk an one for the kickstart ISO.

My packer.json for Centos7 looks like this:

{
  "variables": {
    "vcenter_server":   "{{env `GOVC_URL`}}",
    "vcenter_insecure": "{{env `GOVC_INSECURE`}}",
    "vcenter_user":     "{{env `GOVC_USERNAME`}}",
    "vcenter_password": "{{env `GOVC_PASSWORD`}}",
    "vm_datacenter":    "{{env `GOVC_DATACENTER`}}",
    "vm_datastore":     "{{env `GOVC_DATASTORE`}}",
    "vm_cluster":       "{{env `VM_CLUSTER`}}",
    "vm_resourcepool":  "{{env `VM_RESOURCEPOOL`}}",
    "vm_folder":        "{{env `VM_FOLDER`}}",
    "vm_name":          "{{env `VM_NAME`}}",
    "install_net":      "{{env `INSTALL_NET`}}",
    "iso_kickstart":    "{{env `ISO_KICKSTART`}}",
    "iso_datastore":    "{{env `ISO_DATASTORE`}}",
    "install_dir":      "install",
    "install_iso":      "CentOS/CentOS-7-x86_64-DVD-1908.iso"
  },
  "builders": [
    {
      "type": "vsphere-iso",

      "vcenter_server":      "{{user `vcenter_server`}}",
      "datacenter":          "{{user `vm_datacenter`}}",
      "datastore":           "{{user `vm_datastore`}}",
      "username":            "{{user `vcenter_user`}}",
      "password":            "{{user `vcenter_password`}}",
      "insecure_connection": "{{user `vcenter_insecure`}}",
      "vm_name":             "{{user `vm_name`}}",
      "cluster":             "{{user `vm_cluster`}}",
      "resource_pool":       "{{user `vm_resourcepool`}}",
      "folder":              "{{user `vm_folder`}}",

      "ssh_username": "SomeUser",
      "ssh_password": "SomePassword",

      "CPUs":                  1,
      "RAM":                   1024,
      "RAM_reserve_all":       false,
      "disk_controller_type":  "pvscsi",
      "disk_size":             10240,
      "disk_thin_provisioned": false,
      "network_card":          "vmxnet3",
      "network":               "{{user `install_net`}}",
      "iso_paths": [
        "[{{user `iso_datastore`}}] {{user `install_iso`}}",
        "[{{user `vm_datastore`}}] {{user `iso_kickstart`}}"
      ],
      "boot_wait": "10s",
      "boot_command": [
        "<tab><wait><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>ks=cdrom<enter>"
      ]
    }
  ],
  "provisioners": [
    {
      "type": "file",
      "source": "{{user `install_dir`}}",
      "destination": "/tmp/install"
    },
    {
      "type": "shell",
      "inline": [
        "cd /tmp/install",
        "bash install.sh"
      ]
    }
  ]
}

The Snippet from my .gitlab-ci.yml for upload ISO and build the VM (again Centos7) looks like:

packer_build:
  stage: build
  tags:
    - docker
  only:
    - master
  variables:
    PACKER_LOG: 1
    KICKISO: "${OSBASE}-testsalt_${CI_BUILD_ID}.iso"
    ISO_KICKSTART: "kickstart/${OSBASE}-testsalt_${CI_BUILD_ID}.iso"
  script:
    - export VM_NAME="${OSBASE}-testsalt_$(date '+%Y%m%d_%s')"
    # prepare kickstart ISO and upload it to vCenter
    - mkisofs -V OEMDRV -o "${KICKISO}" ks.cfg
    - govc datastore.upload "${KICKISO}" "${ISO_KICKSTART}"
    # build
    - packer build -timestamp-ui packer.json
    # remove kickstart ISO
    - govc datastore.rm "${ISO_KICKSTART}"
    # remove all cdrom drives (otherwise nodes result in having 2 cdrom drives)
    - govc device.remove -vm "/${GOVC_DATACENTER}/vm/${VM_FOLDER}/${VM_NAME}" cdrom*

My question now is: Is there a way to the same thing (preseed from a secondary cdrom drive) for Debian derivates, too?

Packer has a cd_files option (see docs here) for providing files that it will bundle into a CD and mount for you; I think that ubuntu at least 18.04+ support this using the cloud-init installer if you label the cd “cidata” but I’m not sure for earlier distros.