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.

Hi,

Sorry to bump a year old thread but i’m trying to achieve the same thing as OP with cd_files options.

It seems that this option does not auto-mount the second disk containing the preseed for debian.

So when I start packer it goes well until it need the preseed file located in /dev/sr1 (that need to be mounted)

Here is my conf

cd_files = ["./http/debian/preseed.cfg"]
cd_label = "cidata"
boot_wait = "10s"
boot_command = ["<esc><wait>install <wait>auto=true priority=critical file=dev/sr1:preseed.cfg preseed-md5=66069c1660a6af70fb2010e5413>

I tried to go directly on /dev/sr1 because “cidata” is not mounted on startup

I’m 100% sure I’m getting it wrong but I don’t know where, if you have any guidance on this…

EDIT: For more info here’s the debug of packer

==> vsphere-iso.debian: Uploading packer605400015.iso to packer_cache/packer605400015.iso
==> vsphere-iso.debian: Creating VM...
==> vsphere-iso.debian: Customizing hardware...
==> vsphere-iso.debian: Mounting ISO images...
2022/01/25 10:31:56 packer-builder-vsphere-iso plugin: Check if ISO path is a Content Library path
2022/01/25 10:31:58 packer-builder-vsphere-iso plugin: ISO path not identified as a Content Library path
2022/01/25 10:31:58 packer-builder-vsphere-iso plugin: Using [datastore-packer] packer_cache//b0bda6bf8607e4ebd1f65e31782e6f7ad61b2e36.iso as the datastore path
2022/01/25 10:31:58 packer-builder-vsphere-iso plugin: Creating CD-ROM on controller '&{{{} 200 0xc000e2b980 <nil> <nil> <nil> 0 <nil>} 0 []}' with iso '[datastore-packer] packer_cache//b0bda6bf8607e4ebd1f65e31782e6f7ad61b2e36.iso'
2022/01/25 10:31:58 packer-builder-vsphere-iso plugin: Check if ISO path is a Content Library path
2022/01/25 10:31:59 packer-builder-vsphere-iso plugin: ISO path not identified as a Content Library path
2022/01/25 10:31:59 packer-builder-vsphere-iso plugin: Using [datastore-packer] packer_cache//packer605400015.iso as the datastore path
2022/01/25 10:31:59 packer-builder-vsphere-iso plugin: Creating CD-ROM on controller '&{{{} 200 0xc000d69e20 <nil> <nil> <nil> 0 <nil>} 0 [3000]}' with iso '[datastore-packer] packer_cache//packer605400015.iso'

packer605400015.iso is the preseed file.

Regards

Did you manage to find a solution?

I write out the kickstart/text file and save it as /data/ks.pkrtpl.hcl .

Packer runs packages up my ks.pkrtpl.hcl as an iso and will build a VM. Packer then add in 2 disks (install and ks data). With the boot command point the installation to use the ks file in the cdrom drive.

boot_command = [
"<up>", "e", "<down>", "<down>",  "<end>",  "<wait>",  "text inst.ks=cdrom:ks.cfg", "<enter>", 
]

Is that what you are all looking for?