3 Commits

Author SHA1 Message Date
Andre Courchesne
6bb1e025cb - Update changelog, bump to v0.0.1 2025-12-17 11:28:28 -05:00
Andre Courchesne
317ec12332 Merge pull request #2 from Telecominfraproject/1-structure-setup-and-first-code
Fixes #1 - Structure setup and first code commit
2025-12-17 11:26:20 -05:00
Andre Courchesne
46950d9ff1 #1 - Structure setup and first code commit 2025-12-16 10:19:53 -05:00
19 changed files with 6257 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
.vagrant
*.iso
box/
output-*/
manifest.json
files/iso_release
images/efiboot.img
*.swp
kickstart/devops_packages.cfg
*packages.yml
*.zip
.DS_Store
loop
firstboot/firstboot

9
CHANGELOG.md Normal file
View File

@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
NOTE: the project follows [Semantic Versioning](http://semver.org/).
## v0.0.1 - December 17th 2025
- First release

85
README.md Normal file
View File

@@ -0,0 +1,85 @@
# Installer for OpenLAN Gateway
Project aimed at building ISOs for OpenLAN Gateway
## Requirements
- Docker
- Linux or macOS operating system (sorry not sorry Windows)
## Building an ISO
1. Run `script/build`
The result of this will be an ISO in the project working folder.
## Installing OpenLAN Gateway
### Install from ISO and VyOS VM configuration
- Boot on the ISO, once the install is completed the server will power-off
- Power back the server
- Login to the Linux host with username `olgadm` and password `olgadm`
- Edit `/opt/staging_scripts/setup-config` and adgst the network interface names and if required the VyOS VM sizing parameters
- You might need to adjust the VyOS rolling release path. Reference: https://github.com/vyos/vyos-nightly-build/releases
- Run the setup script:
- `sudo /opt/staging_scripts/setup-vyos-bridge.sh` to use the network bridge method
- `sudo /opt/staging_scripts/setup-vyos-hw-passthru.sh` to use the hardware passthru for the network interfaces (WIP)
- Reboot the host
- Connect to the VyOS console with `virsh console vyos`
- Login with username `vyos` and password `vyos`
- Type `install image` and press Enter.
- Follow the prompts (you can use all defaults)
- Once completed, type `reboot` to reboot the VM
- For some reason the VyOS VM does not reboot after this first `reboot` command. You must restart it manually with `virsh start vyos`
### Load the initial factory default configuration
The factory configuration consists of:
- `eth0` as the WAN interface in DHCP
- `eth1` as the LAN interface
- 3 VLANs:
- VLAN 100 for the switches
- VLAN 101 for the APs
- VLAN 1000 for the guest devices
- Each VLAN has it's own DHCP scope
Here is how to load this configuration:
- Open a console to the VyOS console with `virsh console vyos`
- If required login with your credentials
- Mound the ISO containing the configs
```
sudo mkdir /opt/vyos-configs ; sudo mount /dev/sr1 /opt/vyos-configs
```
- Go in config mode with `config`
- Load the factory config with:
```
source /opt/olg-configs/vyos-factory-config
commit
save
exit
```
## Testes platforms
- MinisForum MS-01
## Contributing
- Create an issue
- Create a branch and an assoiated PR
- Code
- Ask for review and get your changes merged
### Protip
Use the Shipit CLI (https://gitlab.com/intello/shipit-cli-go)
This allows you to create the branch and associated PR in one simple command. The branch and PR will use a standardized naming scheme.
![image](docs/shipit-screenshot.png)

BIN
docs/shipit-screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

12
grub.cfg Normal file
View File

@@ -0,0 +1,12 @@
set timeout=30
insmod all_video
insmod png
loadfont unicode
gfxpayload text
ISO_VERSION="v0.0.1"
menuentry "Install Open LAN Gateway (ISO $ISO_VERSION)" {
linux /casper/vmlinuz autoinstall fsck.mode=skip ds=nocloud\;s=/cdrom/nocloud/ ipv6.disable=1 console=ttyS0,115200n8 console=tty0 network-config=disabled ---
initrd /casper/initrd
}

View File

@@ -0,0 +1,6 @@
network:
version: 2
ethernets:
{{ HOST_ADMIN_PORT }}: # Admin port
dhcp4: true
dhcp6: false

View File

@@ -0,0 +1,20 @@
# Add /opt to the path
PATH=$PATH:/opt
export PATH
# Some useful aliases
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias reboot='shutdown -rf now'
alias ip4='ip -c -o -4'
alias ip6='ip -c -o -6'
# Source global definitions
if [ -f /etc/bashrc ]; then
source /etc/bashrc
fi
# Terminal tweaks
export LS_COLORS="no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:"
export TERM=xterm-color

115
iso-files/destroy-vyos-vm.sh Executable file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env bash
set -euo pipefail
VM_NAME="vyos"
IMAGES_DIR="/var/lib/libvirt/images"
ISO_PATH="$IMAGES_DIR/vyos.iso"
DISK_PATH="$IMAGES_DIR/${VM_NAME}.qcow2"
NETPLAN_FILE="/etc/netplan/99-vyos-bridges.yaml"
# ====== Preflight ======
if [[ $EUID -ne 0 ]]; then
echo "Please run as root (sudo $0)"; exit 1
fi
echo "============================================"
echo "VyOS VM Destruction Script"
echo "============================================"
echo ""
echo "This script will:"
echo " 1. Stop and destroy the VyOS VM"
echo " 2. Undefine the VM from libvirt"
echo " 3. Remove VM disk image"
echo " 4. Optionally remove VyOS ISO"
echo " 5. Optionally remove bridge network configuration"
echo ""
# Check if VM exists
if ! virsh dominfo "$VM_NAME" >/dev/null 2>&1; then
echo ">>> VM '$VM_NAME' does not exist or is not defined."
else
# Check if VM is running
if virsh list --state-running | grep -q "$VM_NAME"; then
echo ">>> Stopping VM '$VM_NAME'..."
virsh destroy "$VM_NAME"
echo " VM stopped."
else
echo ">>> VM '$VM_NAME' is not running."
fi
# Undefine the VM
echo ">>> Undefining VM '$VM_NAME'..."
virsh undefine "$VM_NAME" --nvram 2>/dev/null || virsh undefine "$VM_NAME"
echo " VM undefined."
fi
# Remove disk image
if [[ -f "$DISK_PATH" ]]; then
echo ">>> Removing VM disk: $DISK_PATH"
rm -f "$DISK_PATH"
echo " Disk removed."
else
echo ">>> VM disk not found at $DISK_PATH (already removed or never created)."
fi
# Ask about ISO removal
if [[ -f "$ISO_PATH" ]]; then
echo ""
read -p "Remove VyOS ISO at $ISO_PATH? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ">>> Removing VyOS ISO: $ISO_PATH"
rm -f "$ISO_PATH"
echo " ISO removed."
else
echo ">>> Keeping VyOS ISO at $ISO_PATH"
fi
else
echo ">>> VyOS ISO not found at $ISO_PATH (already removed or never downloaded)."
fi
# Ask about bridge network configuration removal
if [[ -f "$NETPLAN_FILE" ]]; then
echo ""
echo "WARNING: Removing the netplan bridge configuration will restore"
echo " the network interfaces to their previous state, but may"
echo " cause network disruption."
echo ""
read -p "Remove bridge network configuration at $NETPLAN_FILE? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ">>> Removing netplan bridge configuration: $NETPLAN_FILE"
rm -f "$NETPLAN_FILE"
echo " Configuration file removed."
echo ""
read -p "Apply netplan changes now? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ">>> Applying netplan..."
netplan apply
echo " Netplan applied."
else
echo ">>> Skipping netplan apply. Run 'netplan apply' manually to restore interfaces."
fi
else
echo ">>> Keeping bridge network configuration at $NETPLAN_FILE"
fi
else
echo ">>> Bridge network configuration not found at $NETPLAN_FILE"
fi
echo ""
echo "============================================"
echo "VyOS VM Cleanup Complete!"
echo "============================================"
echo ""
echo "Summary:"
echo " - VM '$VM_NAME' has been destroyed and undefined"
echo " - VM disk has been removed"
echo ""
echo "Note: If you used PCI passthrough (setup-vyos-hw-passthru.sh),"
echo " the physical network interfaces should automatically return"
echo " to the host when the VM is destroyed. You may need to reload"
echo " the appropriate driver or reboot to fully restore them."
echo ""

60
iso-files/set-hostname Normal file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
echo " * Starting : set_hostname"
if [ ! -e /tmp/previous_install_hostname ]; then
serial=`cat /sys/class/dmi/id/product_serial | tr '[:upper:]' '[:lower:]'`
product_name=`cat /sys/class/dmi/id/product_name`
if [ "$product_name" == "Default string" ] || [ "$product_name" == "" ]; then
product_name=`cat /sys/class/dmi/id/board_name`
fi
if [ "$serial" == "0" ]; then
hostname="olg-vbox-$RANDOM"
elif [ "$product_name" == "FW4A" ] || [ "$product_name" == "FW4B" ] || [ "$product_name" == "Aptio CRB" ]; then
unique_id=`cat /sys/class/net/enp1s0/address | sed 's/://g'`
hostname="olg-$unique_id"
elif [ "$product_name" == "VP2410" ]; then
unique_id=`cat /sys/class/net/enp2s0/address | sed 's/://g'`
hostname="olg-$unique_id"
elif [ "$serial" == "" ] || [ "$serial" == "default string" ]; then
macaddress=`cat /sys/class/net/*/address | grep -v "00:00:00:00:00:00" | sort |head -n 1`
if [ "${macaddress}" != "" ]; then
unique_id=`echo ${macaddress} | sed 's/://g'`
hostname="olg-$unique_id"
else
hostname="olg-unknown-$RANDOM"
fi
elif [ "$product_name" == "VMware Virtual Platform" ]; then
if [ -e /sys/class/net/eth1/address ]; then
unique_id=`cat /sys/class/net/eth1/address | sed 's/://g'`
hostname="olg-vmware-$unique_id"
elif [ -e /sys/class/net/ens33/address ]; then
unique_id=`cat /sys/class/net/ens33/address | sed 's/://g'`
hostname="olg-vmware-$unique_id"
elif [ -e /sys/class/net/ens192/address ]; then
unique_id=`cat /sys/class/net/ens192/address | sed 's/://g'`
hostname="olg-vmware-$unique_id"
else
hostname="olg-vmware-$RANDOM"
fi
else
ipmi_mac=`ipmitool lan print | grep "MAC Address" | awk '{print $4}' | sed 's/://g'`
if [ ! -z ${ipmi_mac} ]; then
hostname="olg-$ipmi_mac"
else
hostname="olg-$serial"
fi
fi
else
hostname=`cat /tmp/previous_install_hostname`
fi
# Remove any spaces
hostname=${hostname//[[:blank:]]/}
hostnamectl set-hostname ${hostname}
echo "Product name : '$product_name'"
echo "DMI Serial : '$serial'"
echo "Got hostname : '$hostname'"
echo "network --hostname='$hostname'"
echo " * Done : set-hostname"

8
iso-files/setup-config Normal file
View File

@@ -0,0 +1,8 @@
VCPUS="4"
RAM_MB="16384"
DISK_GB="50"
WAN_IF="enp2s0f0np0"
LAN_IF="enp2s0f1np1"
ADMIN_IF="enx000ec6f01419"
INTEL_AMT_PORT="enp88s0"
ISO_URL="https://github.com/vyos/vyos-nightly-build/releases/download/2025.12.13-0020-rolling/vyos-2025.12.13-0020-rolling-generic-amd64.iso"

View File

@@ -0,0 +1,132 @@
#!/usr/bin/env bash
set -euo pipefail
# Source our configs
source /opt/staging_scripts/setup-config
# Some statis configs
VM_NAME="vyos"
IMAGES_DIR="/var/lib/libvirt/images"
ISO_PATH="$IMAGES_DIR/vyos.iso"
DISK_PATH="$IMAGES_DIR/${VM_NAME}.qcow2"
BR_WAN="br-wan"
BR_LAN="br-lan"
NETPLAN_FILE="/etc/netplan/99-vyos-bridges.yaml"
# Make sure we are running as root
if [[ $EUID -ne 0 ]]; then
echo "Please run as root (sudo $0)"; exit 1
fi
# Make sure we have netplan available
command -v netplan >/dev/null 2>&1 || { echo "netplan not found. This script targets Ubuntu with netplan."; exit 1; }
# Make sure we have all the minimum required interfaces
for IFACE in "$WAN_IF" "$LAN_IF"; do
if ! ip link show "$IFACE" >/dev/null 2>&1; then
echo "Interface $IFACE not found. Adjust WAN_IF/LAN_IF in the script."; exit 1
fi
done
echo ">>> Set the host hostname"
/opt/staging_scripts/set-hostname
echo ">>> Installing virtualization packages..."
apt-get update -y
apt-get install -y qemu-kvm libvirt-daemon-system libvirt-clients virtinst bridge-utils cloud-image-utils libguestfs-tools xorriso genisoimage syslinux-utils
echo ">>> Ensuring libvirtd is running..."
systemctl enable --now libvirtd
mkdir -p "$IMAGES_DIR"
# Configure host bridges via netplan
echo ">>> Writing netplan to create $BR_WAN (via $WAN_IF) and $BR_LAN (via $LAN_IF): $NETPLAN_FILE"
cat > "$NETPLAN_FILE" <<EOF
network:
version: 2
renderer: networkd
ethernets:
${WAN_IF}:
dhcp4: false
dhcp6: false
${LAN_IF}:
dhcp4: false
dhcp6: false
bridges:
${BR_WAN}:
interfaces: [${WAN_IF}]
dhcp4: false
dhcp6: false
parameters:
stp: false
forward-delay: 0
${BR_LAN}:
interfaces: [${LAN_IF}]
dhcp4: false
dhcp6: false
parameters:
stp: false
forward-delay: 0
EOF
chmod 600 /etc/netplan/*.yaml
echo ">>> Applying netplan (this may momentarily disrupt links on $WAN_IF/$LAN_IF)..."
netplan apply
# System settings
echo br_netfilter | sudo tee /etc/modules-load.d/br_netfilter.conf
sudo modprobe br_netfilter
sudo tee /etc/sysctl.d/99-bridge-nf-off.conf >/dev/null <<'EOF'
net.bridge.bridge-nf-call-iptables=0
net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-arptables=0
EOF
sudo sysctl --system
# Get VyOS ISO
if [[ ! -f "$ISO_PATH" ]]; then
echo ">>> Downloading VyOS ISO to $ISO_PATH"
curl -fL $ISO_URL -o $ISO_PATH
else
echo ">>> VyOS ISO already present at $ISO_PATH"
fi
# Create an ISO with out example config files
mkisofs -joliet -rock -volid "cidata" -output /var/lib/libvirt/boot/vyos-configs.iso /opt/staging_scripts/vyos-configs/vyos-factory-config
# Create VM disk
if [[ ! -f "$DISK_PATH" ]]; then
echo ">>> Creating disk $DISK_PATH (${DISK_GB}G)"
qemu-img create -f qcow2 "$DISK_PATH" "${DISK_GB}G"
else
echo ">>> Disk already exists at $DISK_PATH"
fi
# If a previous domain with the same name exists, define a new one will fail.
if virsh dominfo "$VM_NAME" >/dev/null 2>&1; then
echo ">>> A VM named '$VM_NAME' already exists. Skipping creation."
echo "You can start it with: virsh start $VM_NAME && virsh console $VM_NAME"
exit 0
fi
# Create & start VM
echo ">>> Creating VyOS VM '$VM_NAME'..."
virt-install -n "$VM_NAME" \
--cpu host --ram "$RAM_MB" \
--vcpus "$VCPUS" \
--cdrom "$ISO_PATH" \
--os-variant debian12 \
--network bridge="$BR_WAN",model=virtio \
--network bridge="$BR_LAN",model=virtio \
--graphics vnc \
--hvm \
--virt-type kvm \
--disk path=/var/lib/libvirt/images/vyos.qcow2,bus=virtio,size=8 \
--disk /var/lib/libvirt/boot/vyos-configs.iso,device=cdrom \
--noautoconsole
# Set the VM o autostart on host boot
virsh autostart $VM_NAME

View File

@@ -0,0 +1,240 @@
#!/usr/bin/env bash
set -euo pipefail
# Source our configs
source /opt/staging_scripts/setup-config
# Some statis configs
VM_NAME="vyos"
IMAGES_DIR="/var/lib/libvirt/images"
ISO_PATH="$IMAGES_DIR/vyos.iso"
DISK_PATH="$IMAGES_DIR/${VM_NAME}.qcow2"
# Make sure we are running as root
if [[ $EUID -ne 0 ]]; then
echo "Please run as root (sudo $0)"; exit 1
fi
# Make sure we have all the minimum required interfaces
for IFACE in "$WAN_IF" "$LAN_IF"; do
if ! ip link show "$IFACE" >/dev/null 2>&1; then
echo "Interface $IFACE not found. Adjust WAN_IF/LAN_IF in the script."; exit 1
fi
done
echo ">>> Set the host hostname"
/opt/staging_scripts/set-hostname
echo ">>> Installing virtualization packages..."
apt-get update -y
apt-get install -y qemu-kvm libvirt-daemon-system libvirt-clients virtinst bridge-utils cloud-image-utils libguestfs-tools xorriso genisoimage syslinux-utils
echo ">>> Ensuring libvirtd is running..."
systemctl enable --now libvirtd
mkdir -p "$IMAGES_DIR"
# Get PCI addresses for interfaces
echo ">>> Detecting PCI addresses for network interfaces..."
WAN_PCI=$(basename $(readlink -f /sys/class/net/$WAN_IF/device))
LAN_PCI=$(basename $(readlink -f /sys/class/net/$LAN_IF/device))
if [[ -z "$WAN_PCI" ]] || [[ -z "$LAN_PCI" ]]; then
echo "ERROR: Could not determine PCI addresses for interfaces"
echo "WAN_IF ($WAN_IF): $WAN_PCI"
echo "LAN_IF ($LAN_IF): $LAN_PCI"
exit 1
fi
echo "WAN interface $WAN_IF is at PCI address: $WAN_PCI"
echo "LAN interface $LAN_IF is at PCI address: $LAN_PCI"
# Parse PCI address (format: 0000:04:00.0 -> domain:bus:slot.function)
WAN_DOMAIN=$(echo $WAN_PCI | cut -d: -f1)
WAN_BUS=$(echo $WAN_PCI | cut -d: -f2)
WAN_SLOT=$(echo $WAN_PCI | cut -d: -f3 | cut -d. -f1)
WAN_FUNC=$(echo $WAN_PCI | cut -d. -f2)
LAN_DOMAIN=$(echo $LAN_PCI | cut -d: -f1)
LAN_BUS=$(echo $LAN_PCI | cut -d: -f2)
LAN_SLOT=$(echo $LAN_PCI | cut -d: -f3 | cut -d. -f1)
LAN_FUNC=$(echo $LAN_PCI | cut -d. -f2)
# Enable IOMMU and VFIO
echo ">>> Checking IOMMU support..."
if ! dmesg | grep -q "IOMMU enabled"; then
echo "WARNING: IOMMU may not be enabled. You may need to:"
echo " 1. Enable VT-d/AMD-Vi in BIOS"
echo " 2. Add 'intel_iommu=on' or 'amd_iommu=on' to kernel parameters"
echo " 3. Reboot the system"
echo ""
read -p "Continue anyway? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
echo ">>> Configuring VFIO for PCI passthrough..."
# Load VFIO modules
modprobe vfio
modprobe vfio_pci
modprobe vfio_iommu_type1
# Ensure modules load on boot
cat > /etc/modules-load.d/vfio.conf <<EOF
vfio
vfio_pci
vfio_iommu_type_1
EOF
# Get vendor and device IDs for the interfaces
WAN_VENDOR_DEVICE=$(lspci -n -s $WAN_PCI | awk '{print $3}')
LAN_VENDOR_DEVICE=$(lspci -n -s $LAN_PCI | awk '{print $3}')
echo "WAN device ID: $WAN_VENDOR_DEVICE"
echo "LAN device ID: $LAN_VENDOR_DEVICE"
# Unbind interfaces from current driver and bind to vfio-pci
echo ">>> Unbinding interfaces from host..."
for IFACE in "$WAN_IF" "$LAN_IF"; do
if [[ -e "/sys/class/net/$IFACE" ]]; then
ip link set $IFACE down
DRIVER_PATH=$(readlink -f /sys/class/net/$IFACE/device/driver)
if [[ -n "$DRIVER_PATH" ]]; then
DRIVER_NAME=$(basename $DRIVER_PATH)
PCI_ADDR=$(basename $(readlink -f /sys/class/net/$IFACE/device))
echo "Unbinding $IFACE ($PCI_ADDR) from $DRIVER_NAME"
echo "$PCI_ADDR" > /sys/bus/pci/drivers/$DRIVER_NAME/unbind 2>/dev/null || true
fi
fi
done
# Bind to vfio-pci
echo ">>> Binding interfaces to vfio-pci..."
for PCI_ADDR in "$WAN_PCI" "$LAN_PCI"; do
if [[ ! -e "/sys/bus/pci/drivers/vfio-pci/$PCI_ADDR" ]]; then
echo "$PCI_ADDR" > /sys/bus/pci/drivers/vfio-pci/bind 2>/dev/null || {
# If bind fails, try adding the device ID first
VENDOR_DEVICE=$(lspci -n -s $PCI_ADDR | awk '{print $3}')
echo "$VENDOR_DEVICE" > /sys/bus/pci/drivers/vfio-pci/new_id 2>/dev/null || true
echo "$PCI_ADDR" > /sys/bus/pci/drivers/vfio-pci/bind 2>/dev/null || true
}
fi
echo "Bound $PCI_ADDR to vfio-pci"
done
# Get VyOS ISO
if [[ ! -f "$ISO_PATH" ]]; then
echo ">>> Downloading VyOS ISO to $ISO_PATH"
curl -fL $ISO_URL -o $ISO_PATH
else
echo ">>> VyOS ISO already present at $ISO_PATH"
fi
# Create an ISO with out example config files
mkisofs -joliet -rock -volid "cidata" -output /var/lib/libvirt/boot/vyos-configs.iso /opt/staging_scripts/vyos-configs/vyos-factory-config
# Create VM disk
if [[ ! -f "$DISK_PATH" ]]; then
echo ">>> Creating disk $DISK_PATH (${DISK_GB}G)"
qemu-img create -f qcow2 "$DISK_PATH" "${DISK_GB}G"
else
echo ">>> Disk already exists at $DISK_PATH"
fi
# If a previous domain with the same name exists, define a new one will fail.
if virsh dominfo "$VM_NAME" >/dev/null 2>&1; then
echo ">>> A VM named '$VM_NAME' already exists. Skipping creation."
echo "You can start it with: virsh start $VM_NAME && virsh console $VM_NAME"
exit 0
fi
# Create & start VM with PCI passthrough and host CPU
echo ">>> Creating VyOS VM '$VM_NAME' with host CPU type and PCI passthrough..."
# Create a temporary XML file for the VM
TEMP_XML=$(mktemp)
cat > "$TEMP_XML" <<EOF
<domain type='kvm'>
<name>$VM_NAME</name>
<memory unit='MiB'>$RAM_MB</memory>
<vcpu placement='static'>$VCPUS</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='cdrom'/>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='host-passthrough' check='none'>
<topology sockets='1' cores='$VCPUS' threads='1'/>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='$DISK_PATH'/>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='$ISO_PATH'/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/boot/vyos-configs.iso'/>
<target dev='sdb' bus='sata'/>
<readonly/>
</disk>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x$WAN_DOMAIN' bus='0x$WAN_BUS' slot='0x$WAN_SLOT' function='0x$WAN_FUNC'/>
</source>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x$LAN_DOMAIN' bus='0x$LAN_BUS' slot='0x$LAN_SLOT' function='0x$LAN_FUNC'/>
</source>
</hostdev>
<controller type='usb' index='0' model='ich9-ehci1'/>
<controller type='pci' index='0' model='pci-root'/>
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<video>
<model type='cirrus'/>
</video>
</devices>
</domain>
EOF
echo ">>> Defining VM from XML..."
virsh define "$TEMP_XML"
rm "$TEMP_XML"
# Set the VM o autostart on host boot
virsh autostart $VM_NAME

25
iso-files/user-data.olg Normal file
View File

@@ -0,0 +1,25 @@
#cloud-config
version: 1
identity:
hostname: olg-staging
password: "$y$j9T$Ogm02oaDNP6IIEhxrdLE21$vOQzeg.eQ7PYd0NsBxGhimAQNM6qYo41PIsVratZaV2"
username: olgadm
package_update: false
package_upgrade: false
ssh:
allow-pw: false
authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqf+y26ldt63J9/ZfskTrwy9AU5ZXJkDzWYH5rDisZRc5JZ8Bn9Uj2KV0k7j6XLyQP8N6anoUepxaVuA0eqOSbpSgX5pgg2qCqPy0bbIbpPrEn0XESvds7+0hY2ekPHlL6uawoICkUskLo6MKC/69lFaeIrkC5li4omYUzzZhN5wpdk65UUM12z71HycF7sg2RHBmJSKtjrZGFdIZFVk1zj3OmOwk52GLdv4rJ+DPtrnhlvaJqqSTT4aWRJTpkGwRrzLeDVr2JoQ6QY1PPOtrrl2bxmvlmPbrA/Up4SpnE+0ZlMk7Td5qnfP1JQmRA4yHgwuWra8IUNVPNN+0qKXGaw== andre.courchesne@intello.com
install-server: true
late-commands:
- echo "Open LAN Gateway (Installed using ISO {{ ISO_VERSION }})" >/target/root/olg_release
- mkdir /target/opt/staging_scripts
- cp -r /cdrom/olg_files/* /target/opt/staging_scripts
- chmod -R +x /target/opt/staging_scripts/*
- cat /target/opt/staging_scripts/admin-bashrc-additions >> /target/etc/bash.bashrc
- echo 'olgadm ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/olgadm
- curtin in-target --target /target systemctl disable cloud-init
- curtin in-target --target /target /opt/staging_scripts/set-hostname >>/target/root/set-hostname.log
- cp /target/opt/staging_scripts/01-dhcp-host-admin.yaml /target/etc/netplan/01-dhcp-host-admin.yaml
# shut-down the host to avoid an infinite installer loop
- shutdown -h now

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
set interfaces ethernet eth0 address 'dhcp'
set interfaces ethernet eth0 description 'WAN'
set interfaces ethernet eth0 offload gro
set interfaces ethernet eth0 offload gso
set interfaces ethernet eth0 offload sg
set interfaces ethernet eth0 offload tso
set interfaces ethernet eth1 description 'LAN'
set interfaces ethernet eth1 offload gro
set interfaces ethernet eth1 offload gso
set interfaces ethernet eth1 offload sg
set interfaces ethernet eth1 offload tso
set interfaces ethernet eth1 vif 100 address '192.168.100.1/24'
set interfaces ethernet eth1 vif 100 description 'LAN VLAN 100 (Switches)'
set interfaces ethernet eth1 vif 101 address '192.168.101.1/24'
set interfaces ethernet eth1 vif 101 description 'LAN VLAN 101 (APs)'
set interfaces ethernet eth1 vif 1000 address '172.20.0.1/20'
set interfaces ethernet eth1 vif 1000 description 'LAN VLAN 1000 (Guest devices)'
set interfaces loopback lo
set nat source rule 100 description 'NAT out WAN'
set nat source rule 100 outbound-interface name 'eth0'
set nat source rule 100 source address '172.20.0.0/20'
set nat source rule 100 translation address 'masquerade'
set service dhcp-server shared-network-name VLAN100 authoritative
set service dhcp-server shared-network-name VLAN100 subnet 192.168.100.0/24 option default-router '192.168.100.1'
set service dhcp-server shared-network-name VLAN100 subnet 192.168.100.0/24 option name-server '192.168.100.1'
set service dhcp-server shared-network-name VLAN100 subnet 192.168.100.0/24 range 0 start '192.168.100.50'
set service dhcp-server shared-network-name VLAN100 subnet 192.168.100.0/24 range 0 stop '192.168.100.200'
set service dhcp-server shared-network-name VLAN100 subnet 192.168.100.0/24 subnet-id '100'
set service dhcp-server shared-network-name VLAN101 authoritative
set service dhcp-server shared-network-name VLAN101 subnet 192.168.101.0/24 option default-router '192.168.101.1'
set service dhcp-server shared-network-name VLAN101 subnet 192.168.101.0/24 option domain-name 'lan101.local'
set service dhcp-server shared-network-name VLAN101 subnet 192.168.101.0/24 option name-server '192.168.101.1'
set service dhcp-server shared-network-name VLAN101 subnet 192.168.101.0/24 range 0 start '192.168.101.50'
set service dhcp-server shared-network-name VLAN101 subnet 192.168.101.0/24 range 0 stop '192.168.101.200'
set service dhcp-server shared-network-name VLAN101 subnet 192.168.101.0/24 subnet-id '101'
set service dhcp-server shared-network-name VLAN1000 authoritative
set service dhcp-server shared-network-name VLAN1000 subnet 172.20.0.0/20 option default-router '172.20.0.1'
set service dhcp-server shared-network-name VLAN1000 subnet 172.20.0.0/20 option domain-name 'lan200.local'
set service dhcp-server shared-network-name VLAN1000 subnet 172.20.0.0/20 option name-server '172.20.0.1'
set service dhcp-server shared-network-name VLAN1000 subnet 172.20.0.0/20 range 0 start '172.20.0.50'
set service dhcp-server shared-network-name VLAN1000 subnet 172.20.0.0/20 range 0 stop '172.20.15.200'
set service dhcp-server shared-network-name VLAN1000 subnet 172.20.0.0/20 subnet-id '1000'
set service dns forwarding allow-from '192.168.100.0/24'
set service dns forwarding allow-from '192.168.101.0/24'
set service dns forwarding allow-from '172.20.0.0/20'
set service dns forwarding listen-address '192.168.100.1'
set service dns forwarding listen-address '192.168.101.1'
set service dns forwarding listen-address '172.20.0.1'
set service dns forwarding name-server 1.1.1.1
set service dns forwarding name-server 9.9.9.9
set service ntp allow-client address '127.0.0.0/8'
set service ntp allow-client address '169.254.0.0/16'
set service ntp allow-client address '10.0.0.0/8'
set service ntp allow-client address '172.16.0.0/12'
set service ntp allow-client address '192.168.0.0/16'
set service ntp allow-client address '::1/128'
set service ntp allow-client address 'fe80::/10'
set service ntp allow-client address 'fc00::/7'
set service ntp server time1.vyos.net
set service ntp server time2.vyos.net
set service ntp server time3.vyos.net
set service ssh port 22

4
script/build Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
docker pull ubuntu:jammy
docker run --entrypoint "bash" -it --volume=$PWD:/src --workdir=/src ubuntu:jammy /src/script/make-iso

36
script/make-iso Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
if [ ! -e /.dockerenv ]; then
echo "You must run ./build to make the ISO"
exit 99
fi
sourceISO="ubuntu-24.04.3-live-server-amd64.iso"
sourceISOURL="https://mirror.xenyth.net/ubuntu-releases/24.04.3/${sourceISO}"
isoVersion=`cat grub.cfg| grep "^ISO_VERSION" | cut -f 2 -d '"'`
targetISO="olg-${isoVersion}.iso"
apt update
apt -y install wget xorriso curl gpg fdisk git
# Remove any previous ISO
rm -f ${targetISO}
# If the source ISO is missing get it
if [ ! -e ${sourceISO} ]; then
wget ${sourceISOURL}
if [ ! -e ${sourceISO} ]; then
echo "Missing ${sourceISO}"
exit 1
fi
fi
# Build out custom ISO
script/ubuntu-autoinstall-generator.sh -a -u user-data -d ${targetISO} -s ${sourceISO} --no-verify --all-in-one
chmod 777 ${targetISO}
# Remove artifacts
rm -f iso-files/firstboot
rm -f iso-files/*.deb
rm -f *-efi.img
rm -f *-hybrid.img

View File

@@ -0,0 +1,355 @@
#!/bin/bash
# Based on https://github.com/covertsh/ubuntu-autoinstall-generator
set -Eeuo pipefail
function cleanup() {
trap - SIGINT SIGTERM ERR EXIT
if [ -n "${tmpdir+x}" ]; then
rm -rf "$tmpdir"
log "🚽 Deleted temporary working directory $tmpdir"
fi
}
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
[[ ! -x "$(command -v date)" ]] && echo "💥 date command not found." && exit 1
today=$(date +"%Y-%m-%d")
function log() {
echo >&2 -e "[$(date +"%Y-%m-%d %H:%M:%S")] ${1-}"
}
function die() {
local msg=$1
local code=${2-1} # Bash parameter expansion - default exit status 1. See https://wiki.bash-hackers.org/syntax/pe#use_a_default_value
log "$msg"
exit "$code"
}
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-a] [-e] [-u user-data-file] [-m meta-data-file] [-k] [--focal] [-c] [-r] [-s source-iso-file] [-d destination-iso-file]
💁 This script will create fully-automated Ubuntu Server installation media.
By default, Ubuntu 22.04 images are created, but Ubuntu 20.04 is available as well.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-a, --all-in-one Bake user-data and meta-data into the generated ISO. By default you will
need to boot systems with a CIDATA volume attached containing your
autoinstall user-data and meta-data files.
For more information see: https://ubuntu.com/server/docs/install/autoinstall-quickstart
-e, --use-hwe-kernel Force the generated ISO to boot using the hardware enablement (HWE) kernel. Not supported
by early Ubuntu 20.04 release ISOs.
-u, --user-data Path to user-data file. Required if using -a
-m, --meta-data Path to meta-data file. Will be an empty file if not specified and using -a
-k, --no-verify Disable GPG verification of the source ISO file. By default SHA256SUMS-$today and
SHA256SUMS-$today.gpg in ${script_dir} will be used to verify the authenticity and integrity
of the source ISO file. If they are not present the latest daily SHA256SUMS will be
downloaded and saved in ${script_dir}. The Ubuntu signing key will be downloaded and
saved in a new keyring in ${script_dir}
-c, --no-md5 Disable MD5 checksum on boot
--focal Create installation media for Ubuntu 20.04 Focal Fossa
-r, --use-release-iso Use the current release ISO instead of the daily ISO. The file will be used if it already
exists.
-s, --source Source ISO file. By default the latest daily ISO will be downloaded
and saved as ${script_dir}/ubuntu-original-$today.iso
That file will be used by default if it already exists.
-d, --destination Destination ISO file. By default ${script_dir}/ubuntu-autoinstall-$today.iso will be
created, overwriting any existing file.
EOF
exit
}
function parse_params() {
# default values of variables set from params
user_data_file=''
meta_data_file=''
focal=0
download_url="https://cdimage.ubuntu.com/ubuntu-server/jammy/daily-live/current"
download_iso="jammy-live-server-amd64.iso"
original_iso="ubuntu-jammy-original-$today.iso"
source_iso="${script_dir}/${original_iso}"
destination_iso="${script_dir}/ubuntu-jammy-autoinstall-$today.iso"
sha_suffix="-jammy-${today}"
gpg_verify=1
all_in_one=0
use_hwe_kernel=0
md5_checksum=1
use_release_iso=0
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--focal) focal=1 ;;
-a | --all-in-one) all_in_one=1 ;;
-e | --use-hwe-kernel) use_hwe_kernel=1 ;;
-c | --no-md5) md5_checksum=0 ;;
-k | --no-verify) gpg_verify=0 ;;
-r | --use-release-iso) use_release_iso=1 ;;
-u | --user-data)
user_data_file="${2-}"
shift
;;
-s | --source)
source_iso="${2-}"
shift
;;
-d | --destination)
destination_iso="${2-}"
shift
;;
-m | --meta-data)
meta_data_file="${2-}"
shift
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
log "👶 Starting up..."
# check required params and arguments
if [ ${all_in_one} -ne 0 ]; then
[[ -z "${user_data_file}" ]] && die "💥 user-data file was not specified."
[[ ! -f "$user_data_file" ]] && die "💥 user-data file could not be found."
[[ -n "${meta_data_file}" ]] && [[ ! -f "$meta_data_file" ]] && die "💥 meta-data file could not be found."
fi
if [ "${source_iso}" != "${script_dir}/${original_iso}" ]; then
[[ ! -f "${source_iso}" ]] && die "💥 Source ISO file could not be found."
fi
if [ ${focal} -eq 1 ]; then
download_url="https://cdimage.ubuntu.com/ubuntu-server/focal/daily-live/current"
download_iso="focal-live-server-amd64.iso"
original_iso="ubuntu-focal-original-$today.iso"
source_iso="${script_dir}/${original_iso}"
destination_iso="${script_dir}/ubuntu-focal-autoinstall-$today.iso"
sha_suffix="-focal-${today}"
fi
if [ "${use_release_iso}" -eq 1 ]; then
log "🔎 Checking for current release..."
if [ ${focal} -eq 1 ]; then
download_url="https://releases.ubuntu.com/focal"
download_iso=$(curl -sSL "${download_url}" | grep -oP 'ubuntu-20\.04\.\d*-live-server-amd64\.iso' | head -n 1)
else
download_url="https://releases.ubuntu.com/jammy"
download_iso=$(curl -sSL "${download_url}" | grep -oP 'ubuntu-22\.04(\.\d*)?-live-server-amd64\.iso' | head -n 1)
fi
original_iso="${download_iso}"
source_iso="${script_dir}/${download_iso}"
current_release=$(echo "${download_iso}" | cut -f2 -d-)
sha_suffix="${current_release}"
log "💿 Current release is ${current_release}"
fi
destination_iso=$(realpath "${destination_iso}")
source_iso=$(realpath "${source_iso}")
return 0
}
ubuntu_gpg_key_id="843938DF228D22F7B3742BC0D94AA3F0EFE21092"
parse_params "$@"
tmpdir=$(mktemp -d)
if [[ ! "$tmpdir" || ! -d "$tmpdir" ]]; then
die "💥 Could not create temporary working directory."
else
log "📁 Created temporary working directory $tmpdir"
fi
log "🔎 Checking for required utilities..."
[[ ! -x "$(command -v xorriso)" ]] && die "💥 xorriso is not installed. On Ubuntu, install the 'xorriso' package."
[[ ! -x "$(command -v sed)" ]] && die "💥 sed is not installed. On Ubuntu, install the 'sed' package."
[[ ! -x "$(command -v curl)" ]] && die "💥 curl is not installed. On Ubuntu, install the 'curl' package."
[[ ! -x "$(command -v gpg)" ]] && die "💥 gpg is not installed. On Ubuntu, install the 'gpg' package."
if [ ${focal} -eq 1 ]; then
[[ ! -f "/usr/lib/ISOLINUX/isohdpfx.bin" ]] && die "💥 isolinux is not installed. On Ubuntu, install the 'isolinux' package."
else
[[ ! -x "$(command -v fdisk)" ]] && die "💥 fdisk is not installed. On Ubuntu, install the 'fdisk' package."
fi
log "👍 All required utilities are installed."
if [ ! -f "${source_iso}" ]; then
log "🌎 Downloading ISO image ..."
curl -NsSL "${download_url}/${download_iso}" -o "${source_iso}"
log "👍 Downloaded and saved to ${source_iso}"
else
log "☑️ Using existing ${source_iso} file."
if [ ${gpg_verify} -eq 1 ]; then
if [ "${source_iso}" != "${script_dir}/${original_iso}" ]; then
log "⚠️ Automatic GPG verification is enabled. If the source ISO file is not the latest daily or release image, verification will fail!"
fi
fi
fi
if [ ${gpg_verify} -eq 1 ]; then
if [ ! -f "${script_dir}/SHA256SUMS-${sha_suffix}" ]; then
log "🌎 Downloading SHA256SUMS & SHA256SUMS.gpg files..."
curl -NsSL "${download_url}/SHA256SUMS" -o "${script_dir}/SHA256SUMS-${sha_suffix}"
curl -NsSL "${download_url}/SHA256SUMS.gpg" -o "${script_dir}/SHA256SUMS-${sha_suffix}.gpg"
else
log "☑️ Using existing SHA256SUMS-${sha_suffix} & SHA256SUMS-${sha_suffix}.gpg files."
fi
if [ ! -f "${script_dir}/${ubuntu_gpg_key_id}.keyring" ]; then
log "🌎 Downloading and saving Ubuntu signing key..."
gpg -q --no-default-keyring --keyring "${script_dir}/${ubuntu_gpg_key_id}.keyring" --keyserver "hkp://keyserver.ubuntu.com" --recv-keys "${ubuntu_gpg_key_id}"
log "👍 Downloaded and saved to ${script_dir}/${ubuntu_gpg_key_id}.keyring"
else
log "☑️ Using existing Ubuntu signing key saved in ${script_dir}/${ubuntu_gpg_key_id}.keyring"
fi
log "🔐 Verifying ${source_iso} integrity and authenticity..."
gpg -q --keyring "${script_dir}/${ubuntu_gpg_key_id}.keyring" --verify "${script_dir}/SHA256SUMS-${sha_suffix}.gpg" "${script_dir}/SHA256SUMS-${sha_suffix}" 2>/dev/null
if [ $? -ne 0 ]; then
rm -f "${script_dir}/${ubuntu_gpg_key_id}.keyring~"
die "👿 Verification of SHA256SUMS signature failed."
fi
rm -f "${script_dir}/${ubuntu_gpg_key_id}.keyring~"
digest=$(sha256sum "${source_iso}" | cut -f1 -d ' ')
set +e
grep -Fq "$digest" "${script_dir}/SHA256SUMS-${sha_suffix}"
if [ $? -eq 0 ]; then
log "👍 Verification succeeded."
set -e
else
die "👿 Verification of ISO digest failed."
fi
else
log "🤞 Skipping verification of source ISO."
fi
log "🔧 Extracting ISO image..."
xorriso -osirrox on -indev "${source_iso}" -extract / "$tmpdir" &>/dev/null
chmod -R u+w "$tmpdir"
rm -rf "$tmpdir/"'[BOOT]'
log "👍 Extracted to $tmpdir"
if [ ${focal} -eq 0 ]; then
log "🔧 Extracting EFI images from image..."
efi_start=$(fdisk -o Start,Type -l "${source_iso}" | grep -oP '\d+(?=\s+EFI.System)')
efi_length=$(fdisk -o Sectors,Type -l "${source_iso}" | grep -oP '\d+(?=\s+EFI.System)')
dd if=${source_iso} bs=512 skip=${efi_start} count=${efi_length} of=${source_iso}-efi.img
dd if=${source_iso} bs=1 count=432 of=${source_iso}-hybrid.img
log "👍 Extracted EFI images"
fi
if [ ${use_hwe_kernel} -eq 1 ]; then
if grep -q "hwe-vmlinuz" "$tmpdir/boot/grub/grub.cfg"; then
log "☑️ Destination ISO will use HWE kernel."
if [ ${focal} -eq 1 ]; then
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/isolinux/txt.cfg"
sed -i -e 's|/casper/initrd|/casper/hwe-initrd|g' "$tmpdir/isolinux/txt.cfg"
fi
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/boot/grub/grub.cfg"
sed -i -e 's|/casper/initrd|/casper/hwe-initrd|g' "$tmpdir/boot/grub/grub.cfg"
sed -i -e 's|/casper/vmlinuz|/casper/hwe-vmlinuz|g' "$tmpdir/boot/grub/loopback.cfg"
sed -i -e 's|/casper/initrd|/casper/hwe-initrd|g' "$tmpdir/boot/grub/loopback.cfg"
else
log "⚠️ This source ISO does not support the HWE kernel. Proceeding with the regular kernel."
fi
fi
log "🧩 Adding autoinstall parameter to kernel command line..."
if [ ${focal} -eq 1 ]; then
sed -i -e 's/---/ autoinstall ---/g' "$tmpdir/isolinux/txt.cfg"
fi
sed -i -e 's/---/ autoinstall fsck.mode=skip ---/g' "$tmpdir/boot/grub/grub.cfg"
sed -i -e 's/---/ autoinstall fsck.mode=skip ---/g' "$tmpdir/boot/grub/loopback.cfg"
log "👍 Added parameter to UEFI and BIOS kernel command lines."
if [ ${all_in_one} -eq 1 ]; then
log "🧩 Adding user-data and meta-data files..."
mkdir "$tmpdir/nocloud"
cp "$user_data_file" "$tmpdir/nocloud/user-data"
if [ -n "${meta_data_file}" ]; then
cp "$meta_data_file" "$tmpdir/nocloud/meta-data"
else
touch "$tmpdir/nocloud/meta-data"
fi
if [ ${focal} -eq 1 ]; then
sed -i -e 's,---, ds=nocloud;s=/cdrom/nocloud/ ---,g' "$tmpdir/isolinux/txt.cfg"
fi
sed -i -e 's,---, ds=nocloud\\\;s=/cdrom/nocloud/ ---,g' "$tmpdir/boot/grub/grub.cfg"
sed -i -e 's,---, ds=nocloud\\\;s=/cdrom/nocloud/ ---,g' "$tmpdir/boot/grub/loopback.cfg"
log "👍 Added data and configured kernel command line."
fi
# Copy some files
mkdir $tmpdir/olg_files
cp -r iso-files/* $tmpdir/olg_files/
# Copy our grub
cp grub.cfg $tmpdir/boot/grub/grub.cfg
# Customize some files
source iso-files/setup-config
sed -i -e "s/{{ HOST_ADMIN_PORT }}/${ADMIN_IF}/" "$tmpdir/olg_files/01-dhcp-host-admin.yaml"
ISO_VERSION=`cat grub.cfg | grep "ISO_VERSION=" | cut -f 2 -d '"'`
sed -i -e "s/{{ ISO_VERSION }}/${ISO_VERSION}/" "$tmpdir/olg_files/user-data.olg"
# If we have an Intel AMT port it must be set in DHCP or at least up fo AMT to work
if [ ! -z "${INTEL_AMT_PORT}" ]; then
echo " ${INTEL_AMT_PORT}: # Intel AMT Port" >>$tmpdir/olg_files/01-dhcp-host-admin.yaml
echo " dhcp4: true" >>$tmpdir/olg_files/01-dhcp-host-admin.yaml
echo " dhcp6: false" >>$tmpdir/olg_files/01-dhcp-host-admin.yaml
fi
if [ ${md5_checksum} -eq 1 ]; then
log "👷 Updating $tmpdir/md5sum.txt with hashes of modified files..."
md5=$(md5sum "$tmpdir/boot/grub/grub.cfg" | cut -f1 -d ' ')
sed -i -e 's,^.*[[:space:]] ./boot/grub/grub.cfg,'"$md5"' ./boot/grub/grub.cfg,' "$tmpdir/md5sum.txt"
md5=$(md5sum "$tmpdir/boot/grub/loopback.cfg" | cut -f1 -d ' ')
sed -i -e 's,^.*[[:space:]] ./boot/grub/loopback.cfg,'"$md5"' ./boot/grub/loopback.cfg,' "$tmpdir/md5sum.txt"
log "👍 Updated hashes."
else
log "🗑️ Clearing MD5 hashes..."
echo > "$tmpdir/md5sum.txt"
log "👍 Cleared hashes."
fi
log "📦 Repackaging extracted files into an ISO image..."
cd "$tmpdir"
if [ ${focal} -eq 1 ]; then
xorriso -as mkisofs -r \
-V "ubuntu-auto-focal-$today" \
-J \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -boot-info-table -input-charset utf-8 \
-eltorito-alt-boot \
-e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat \
-o "${destination_iso}" \
. #&>/dev/null
else
xorriso -as mkisofs -r \
-V "ubuntu-auto-jammy-$today" \
--grub2-mbr "${source_iso}-hybrid.img" \
-partition_offset 16 --mbr-force-bootable \
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b "${source_iso}-efi.img" \
-appended_part_as_gpt \
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
-c '/boot.catalog' \
-b '/boot/grub/i386-pc/eltorito.img' \
-no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
-eltorito-alt-boot -e '--interval:appended_partition_2:::' \
-no-emul-boot \
-o "${destination_iso}" \
. #&>/dev/null
fi
cd "$OLDPWD"
log "👍 Repackaged into ${destination_iso}"
die "✅ Completed." 0

7
user-data Normal file
View File

@@ -0,0 +1,7 @@
#cloud-config
autoinstall:
version: 1
refresh-installer:
update: yes
early-commands:
- cp /cdrom/olg_files/user-data.olg /autoinstall.yaml