Skip to content

Instantly share code, notes, and snippets.

@displague
Last active September 2, 2021 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save displague/11b6fc926d8d697e28c7a5cbe17d16ff to your computer and use it in GitHub Desktop.
Save displague/11b6fc926d8d697e28c7a5cbe17d16ff to your computer and use it in GitHub Desktop.
#cloud-config
phone_home:
url: "http://tinkerbell.ewr1.packet.net/phone-home"
post:
- instance_id
tries: 5
autoinstall:
version: 1
# use interactive-sections to avoid an automatic reboot
#interactive-sections:
# - locale
apt:
# even set to no/false, geoip lookup still happens
#geoip: no
preserve_sources_list: false
primary:
- arches: [amd64, i386]
uri: http://us.archive.ubuntu.com/ubuntu
- arches: [default]
uri: http://ports.ubuntu.com/ubuntu-ports
# r00tme
identity:
hostname: focal-autoinstall
password: $6$.c38i4RIqZeF4RtR$hRu2RFep/.6DziHLnRqGOEImb15JT2i.K/F9ojBkK/79zqY30Ll2/xx6QClQfdelLe.ZjpeVYfE8xBBcyLspa/
username: ubuntu
keyboard: {layout: us, variant: ''}
locale: en_US.UTF-8
network:
network:
version: 2
renderer: networkd
ethernets:
switchports:
match:
name: en*
#mtu: 1280
dhcp4: no
bonds:
bond0:
interfaces:
- switchports
parameters:
mode: 802.3ad
mii-monitor-interval: 100
down-delay: 200
up-delay: 200
transmit-hash-policy: layer3+4
lacp-rate: fast
critical: true
dhcp4: yes
# vlans:
# bond0.${VLAN_ID_1}:
# addresses: [169.254.254.${LAST_DIGIT}/24]
# id: ${VLAN_ID_1}
# link: bond0
# bond0.${VLAN_ID_0}:
# link-local: [ ipv4, ipv6 ]
# addresses: [192.168.100.${LAST_DIGIT}/24]
# id: ${VLAN_ID_0}
# link: bond0
# routes:
# - to: 0.0.0.0/0
# via: 192.168.100.1
ssh:
#allow-pw: true
#authorized-keys: []
install-server: true
# this creates an bios_grub partition, /boot partition, and root(/) lvm volume
storage:
config:
- {ptable: gpt, path: /dev/sda, wipe: superblock, preserve: false, name: '', grub_device: true,
type: disk, id: disk-sda}
- {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false,
type: partition, id: partition-0}
- {device: disk-sda, size: 1073741824, wipe: superblock, flag: '', number: 2,
preserve: false, type: partition, id: partition-1}
- {fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-0}
- {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 3,
preserve: false, type: partition, id: partition-2}
- name: ubuntu-vg
devices: [partition-2]
preserve: false
type: lvm_volgroup
id: lvm_volgroup-0
- {name: ubuntu-lv, volgroup: lvm_volgroup-0, size: 100%, preserve: false,
type: lvm_partition, id: lvm_partition-0}
- {fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-1}
- {device: format-1, path: /, type: mount, id: mount-1}
- {device: format-0, path: /boot, type: mount, id: mount-0}
write_files:
# override the kernel package. Why?
- path: /run/kernel-meta-package
content: |
linux-generic
owner: root:root
permissions: "0644"
# attempt to also use an answers file by providing a file at the default path. It did not seem to have any effect
#- path: /subiquity_config/answers.yaml
# content: |
# InstallProgress:
# reboot: no
# owner: root:root
# permissions: "0644"
runcmd:
- echo Marty > /root/it-worked
#!/usr/bin/env bash
METAL_PLAN=${METAL_PLAN:-t1.small.x86}
#GIST_URL="https://gist.githubusercontent.com/displague/11b6fc926d8d697e28c7a5cbe17d16ff/raw/f11c247e87290cb1248a2223588daf5cfd3ab1b3/ubuntu.ipxe"
END="$(TZ=UTC date -v+2H +"%Y-%m-%dT%H:%M:%SZ")"
CC=$(cat cloud-config.cfg | python3 -c "import urllib.parse, sys; print(urllib.parse.quote_plus(sys.stdin.read()))")
IPXE=$(cat ubuntu.ipxe | envsubst '${CC}')
echo -e "#!ipxe\n$IPXE\n" > ipxe.tmp
metal device create \
--userdata-file cloud-config.cfg \
--plan $METAL_PLAN \
--hostname "ipxe-test" \
--tags "ipxe,testing,ubuntu" \
--operating-system custom_ipxe \
--facility ewr1 \
--userdata-file ipxe.tmp \
--termination-time "$END"
# --ipxe-script-url "$GIST_URL" \
#!ipxe
dhcp net0
set base-url http://archive.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/current/legacy-images/netboot/ubuntu-installer/amd64/
kernel ${base-url}/linux console=ttyS1,115200n8 ci.ds=ec2;metadata_urls=https://metadata.platformequinix.com/metadata,http://metadata.packet.net/ cc: ${CC} end_cc
initrd ${base-url}/initrd.gz
boot
@displague
Copy link
Author

displague commented Dec 14, 2020

This is similar to https://gist.github.com/displague/5282172449a83c7b83821f8f8333a072 (Equinix Metal iPXE booting RHCOS)

TODO

  • Find the appropriate raw cloud-image from https://cloud-images.ubuntu.com/
  • Find the right set of cloud-init kernel command line parameters to set options similar to https://github.com/tinkerbell/osie/blob/71da59e10bf66cc352366615060171939412d397/docker/scripts/osie.sh#L360-L379
       	datasource_list: [Ec2]
       	datasource:
       	  Ec2:
       	    timeout: 60
       	    max_wait: 120
       	    metadata_urls: [ 'https://metadata.platformequinix.com', 'https://metadata.packet.net' ]
       	    dsmode: net
       	phone_home:
       	  url: ${tinkerbell}/phone-home
       	  post:
       	    - instance_id
       	  tries: 5
    
  • Phone home URL is facility-specific and resides, it can be known in advance but also can be found in the metadata service. It may have to be supplied as another kernel arg.
  • The iPXE support here may not understand variables, we may have to flatten those strings first (as was done in the RHCOS example)

@displague
Copy link
Author

https://github.com/canonical/cloud-init/blob/master/doc/sources/kernel-cmdline.txt

ci.ds=<platform> cloud-config-url=<url to cloud-config>

Does cloud-config-url support non-cloud-config cloud-init scripts? multi-part mime? shebang scripts?

@displague
Copy link
Author

ci.ds=ec2;metadata_urls=https://metadata.platformequinix.com/metadata,http://metadata.packet.net/ ? (comma for multiple?)

nocloud and nocloud-net explain ; use: https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
ec2 has metadata_urls: https://cloudinit.readthedocs.io/en/latest/topics/datasources/ec2.html#configuration

@displague
Copy link
Author

displague commented Sep 2, 2021

via @thebsdbox

This limit depends on the architecture and is between 256 and 4096 characters. 
It is defined in the file ./include/asm/setup.h as COMMAND_LINE_SIZE.

the URL encoded cc: block will need to be kept small.

The current length may explain the black screen I received when attempting to boot this.

@thebsdbox
Copy link

Hook is set to 2048, so tons of room for gzip/base64!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment