(I also reported this to AWS: awsdocs/amazon-ec2-user-guide#123)
The "Running Amazon Linux 2 as a virtual machine onpremises" page describes a fairly cumbersome way of running Amazon Linux 2 in local virtual machines through using various tools to provision ISO9660 seed.iso
files just to serve the VM instance two small data files.
It would be great it the documentation also pointed out that since the VM provisioning is being done with cloud-init
, and the image has configured a fairly extensive datasource_list: [ NoCloud, AltCloud, ConfigDrive, OVF, None ]
which starts with NoCloud, that NoCloud also allows you to serve these files over HTTP.
There are two easy ways of using network configuration instead of seed.iso
. Either you tell GRUB to add a parameter to the kernel boot configuration, or you tell KVM/VMWare/Virtualbox to set the virtual machine's SMBIOS value to something which cloud-init
's NoCloud
understands.
The documentation page https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html describes the parameters.
If you wish to use Packer, for example, to provision local KVM qcow2
files of AL2, you'd use a configuration which looks a bit like this:
{
"builders": [
{
"vm_name": "alpha",
"type": "qemu",
"accelerator": "kvm",
"qemu_binary": "/usr/local/bin/qemu5.0.0-system-x86_64",
"qemuargs": [
["-display", "none"],
["-smbios", "type=1,serial=ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/"]
],
"format": "qcow2",
"iso_url": "images/amzn2-kvm-2.0.20200602.0-x86_64.xfs.gpt.qcow2",
"iso_checksum": "sha256:1ca3af1df04dd9c46240414be3fbc024cdd1fab5fe9b00a975614f24e682da85",
"disk_image": true,
"ssh_handshake_attempts": "20",
"ssh_username": "ec2-user",
"net_device": "virtio-net",
"disk_interface": "virtio",
"http_directory": "httpserver",
"output_directory": "output"
}
]
}
the sillier way to achieve the same is to tell your VM creator to send keypresses to the virtual terminal which is booting up AL2 for the first time:
"boot_wait": "1s",
"boot_command": [
"<shift><shift><wait><wait>e<down><down><down><down><down><down><down><down><down><down><down><down><left>",
" ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/",
"<leftCtrlOn>x<leftCtrlOff>"
]
With your pointers, got it working on Packer 1.9.1.
amzn2.pkr.hcl
scripts-amzn2-qemu/seedconfig/user-data
scripts-amzn2-qemu/seedconfig/meta-data