Packer Ubuntu 20.04 autoinstall via CD drive

I configured my Ubuntu 20.04.1 Packer Template Deployment with user-data and meta-data mounted over CD, but I don’t know how to configure the autoinstall bootcommand to get the subiquity part working:

ubuntu-20.04.json

"cd_files": ["{{template_dir}}/ubuntu-20.04/meta-data", "{{template_dir}}/ubuntu-20.04/user-data"],
    "cd_label": "cidata",
    
    "iso_paths": [
      "[ColoNord-ISOs] ISOs/ubuntu-20.04.1-live-server-amd64.iso"
    ],
    "boot_wait": "5s",
    "floppy_files": ["{{template_dir}}/preseed.cfg"],
    "boot_command": [
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<wait><esc><wait><f6><wait><esc><wait>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
      "<bs><bs><bs>",
      "/casper/vmlinuz ",
      "initrd=/casper/initrd ",
      " ipv6.disable=1 autoinstall ",
      "ds=nocloud-net;s=/cidata/",
      "<enter>"
    ]

user-data

#cloud-config
autoinstall:
	version: 1
	early-commands:
		#Stop SSH to prevent Packer from connecting too early
		- sudo systemctl stop ssh
	apt:
	geoip: true
	preserve_sources_list: false
	primary:
	- arches: [amd64, i386]
		uri: http://gb.archive.ubuntu.com/ubuntu
	- arches: [default]
		uri: http://ports.ubuntu.com/ubuntu-ports
	identity:
	hostname: ubuntu2004
	username: username
	password: password
	ssh:
	allow-pw: true
	install-server: true
	locale: de_CH
	keyboard: 
	layout: gb
	network:
		network:
			version: 2
			ethernets:
			ens160:
				addresses:
				- 10.0.249.75/24
				gateway4: 10.0.249.1
				nameservers:
				addresses:
				- 10.10.10.10
				- 10.10.10.11
				- 10.10.10.12
				- 10.10.10.13
				search:
				- domain.local

	storage:
	layout:
		name: direct
	config:
		- type: disk
		id: disk0
		match:
			size: largest
		- type: partition
		id: boot-partition
		device: disk0
		size: 500M
		- type: partition
		id: root-partition
		device: disk0
		size: -1
	late-commands:
	- "echo 'Defaults:username !requiretty' > /target/etc/sudoers.d/username"
	- "echo 'username ALL=(ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/username"
	- "chmod 440 /target/etc/sudoers.d/username"

Would be awesome to get this working, so I can finally deploy some basic installed vSphere Ubuntu VM Templates.
I don’t find that much documentation about this stuff, so if you can handle me sth to get this solved would also be great.

Greez.

1 Like

Maybe this could help you out:

saw this before, but there he specifies the seedfrom with the http server, but i want to specify the seedfrom from the cd i mounted with the user-data and meta-data file in it

My understanding has been that Packer process starts an HTTP server, which can be then used to server files. Based on the example here:

Also:

… and the bit about: "http_directory": "./http",

I have never used the http option, so I could be totally wrong here! :innocent:

1 Like

True, but he want’s to use a mounted cd drive instead. :slight_smile: But you are totally right.

1 Like

Hi

What makes you think that your cdrom with user-data and meta-data on it is mounted to /cidata/? In my case the ubuntu installer did not mount anything.

According to the documentation here https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html the statement you have in the boot_command is wrong.
IS: “ds=nocloud-net;s=/cidata/”,
SHOULD: “ds=nocloud;s=/cidata/”,

After you have fixed this, most probably it still does not work. I think the gui installer still pop’s up asking for the installation language. If this is the case you can start a shell from the [ HELP ] menu to check where your cdrom is mounted. In my case the cdrom is attached to /dev/sr1 but not mounted anywhere into the installer. To check if this is the same for you do: mount /dev/sr1 /mnt ; ls /mnt. You should see your user- and meta-data.
In my case I did not find a mountpoint /cidata/ ( the place where you configured cloud- init to find user-data and meta-data) or any other mountpoint for my cdrom with user- meta-data.
If I’m wrong and it works for you please post your solution and the versions of packer and vsphere you use because I fight exactly the same problem like you. I use packer 1.6.6 and vsphere 7.0

Thanks and best
Roland

1 Like

yeah but the problem is, that my packer instance running in a gitlab runner container. so the port doesn’t gets exposed and also the IP is wrong, because it uses the docker internal IP address.

After a long odyssee with try and error I finally found a solution that works for me.

For packer v1.6.6 / vsphere 7.0 / ubuntu-20.04.1-live-server-amd64.iso the boot_command does not need a datasource (ds=) and not seedfrom (s=). The following is enough:

  cd_files = [
    "./ubuntu-20.04/meta-data",
    "./ubuntu-20.04/user-data"]
  cd_label = "cidata"

  boot_wait = "2s"

  boot_command = [
    "<esc><esc><esc>",
    "<enter><wait>",
    "/casper/vmlinuz ",
    "initrd=/casper/initrd ",
    "autoinstall ",
    "<enter>"
  ]

I don’t know why there are blog post around using a datasource and the seedfrom in the boot_command stanza if it does more harm than good for ubuntu-20.04.1-live-server-amd64.iso

Hope this works for you too. Let us know
Best Roland

5 Likes

Hi, I’m having a hard time making the packer work for me, I followed what you said it works, but for me it wasn’t, you get stuck in the installation asking to insert language settings, could you share all your settings please.

Hi, below my .pkr.hcl file.

Remember that it is tested only for this:
For packer v1.6.6 / vsphere 7.0 / ubuntu-20.04.1-live-server-amd64.iso / packer vsphere-iso builder.

What I did to find a working configuration was to create a VM in the vCenter Server without packer. I attached two cd rom drives. One with the ubuntu installer iso and a second cd rom drive with user-data and meta-data on it.
In my case the ubuntu installer was able to read the user-data but later during installation it complained that the command ‘autoinstall’ was missing. After this it was easy to craft the below boot_command.
To create an iso image with user-data and meta-data on it you can simply start packer with the -debug flag. Proceed to the point where packer has created the iso and stored it in the datastore. Then go to the datastore and download the iso and use it in the above scenario. To validate your iso just mount it somewhere and check if user-data and meta-data are there.

Hope this helps
Best Roland

source "vsphere-iso" "bastionserver" {
  vcenter_server = "*****"
  username = *****
  password = var.vsphere_password
  insecure_connection = "true"
  host = "****"
  datastore = "******"
  vm_name = "bastionserver-template"
  CPUs = 2
  RAM = 2000
  guest_os_type = "ubuntu64Guest"

  network_adapters {
    network = "VM Network"
    network_card = "vmxnet3"
    mac_address = "00:50:56:00:00:01"
  }

  storage {
    disk_size = 20000
    disk_thin_provisioned = true
  }

  boot_order = "disk,cdrom"
  convert_to_template = true

  iso_paths = [
    "[qnap-vm-datastore-1] /iso-images/ubuntu-20.04.1-live-server-amd64.iso"
  ]

  cd_files = [
    "./cloud-init/meta-data",
    "./cloud-init/user-data"]
  cd_label = "cidata"

  boot_wait = "2s"

  boot_command = [
    "<esc><esc><esc>",
    "<enter><wait>",
    "/casper/vmlinuz ",
    "initrd=/casper/initrd ",
    "autoinstall ",
    "<enter>"
  ]

  ssh_username = "******"
  ssh_password = var.ssh_password
  ssh_pty = true
  ssh_timeout = "20m"
  ssh_handshake_attempts = "20"
}

build {
  sources = [
    "source.vsphere-iso.bastionserver"]

  provisioner "shell" {
...
...
1 Like

I also had some problems with the autoinstall from a cd drive for ubuntu 20.04 on vmware with efi boot .
Its now working with this code, which creates an iso at deployment using cd_files:

"boot_command": [
        "<esc><wait>",
        "<esc><wait>",
        "linux /casper/vmlinuz --- autoinstall ds=nocloud;seedfrom=/cidata/",
        "<enter><wait>",
        "initrd /casper/initrd<enter><wait>",
        "boot<enter>"
      ],
      "cd_files": [
      "{{template_dir}}/http/meta-data",
      "{{template_dir}}/http/user-data"
      ],
      "cd_label": "cidata",
      "boot_wait": "3s",

I seem to be having the same problem. I’m running 20.04 desktops. When I use CDROM I get the following error.

   cd_files = [
    "./http/meta-data",
    "./http/user-data"
    ]
  cd_label = "cidata"

==> Some builds didn’t complete successfully and had errors:
→ vsphere-iso.this: could not find a supported CD ISO creation command (the supported commands are: xorriso, mkisofs, hdiutil, oscdimg)

so I’ve used

  floppy_label = "cidata"
  floppy_content = {
    "meta-data" = "./http/meta-data"
    "user-data" = "./http/user-data"
}

its hitting cloud-init but not setting the local.

Used the following
“linux /casper/vmlinuz — autoinstall ds=nocloud;seedfrom=/cidata/”
“linux /casper/vmlinuz — autoinstall ds=s=/cidata/”

does not set language. What am I missing ?

Over the CD hurdle. I found that i needed to install xorriso tools on my instance of ubuntu where I was running packer from.

  cd_files = [
    "./http/meta-data",
    "./http/user-data"
    ]
  cd_label = "cidata"
  boot_wait = "2s"

and in the boot section as bladnor said I didn’t need to specify where seeded from. Autoinstall was enough.

  boot_command = [
    "<enter><wait><f6><wait><esc><wait>",
    "linux /casper/vmlinuz",
    "<wait><enter>",
    "initrd /casper/initrd",
    "<wait><enter>",
    "autoinstall ",
    "<wait><enter>",
    "boot"
  ]

Did you manage to sort this out. The starting point is that preseed.cfg has been deprecated. Been through your pain so if you need any guidance. reply