diff --git a/cableos/build.json b/cableos/build.json index c865e50..4f2c5ea 100644 --- a/cableos/build.json +++ b/cableos/build.json @@ -1,21 +1,36 @@ + { "builders": [ { "type": "qemu", - "iso_url": "http://releases.ubuntu.com/20.04/ubuntu-20.04-live-server-amd64.iso", - "iso_checksum": "sha256:12345abcdef...", - "disk_size": "10240", - "http_url": "http://{{ .HTTPIP }}:{{ .HTTPPort }}/", - "http_directory": "http", + "iso_url": "http://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-xx.x.x-amd64-netinst.iso", + "iso_checksum": "auto", "boot_command": [ "", - "linux /casper/vmlinuz boot=casper initrd=/casper/initrd quiet -- ", - "initrd /casper/initrd", - "boot" + "install ", + "auto=true ", + "priority=critical ", + "locale=en_US ", + "keyboard-configuration/xkb-keymap=us ", + "netcfg/get_hostname=debian ", + "netcfg/get_domain=vm ", + "fb=false ", + "debconf/frontend=noninteractive ", + "console-setup/ask_detect=false ", + "interface=auto ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg " ], - "ssh_username": "ubuntu", - "ssh_password": "ubuntu", - "ssh_wait_timeout": "10000s" + "http_directory": "http", + "disk_size": 10240, + "http_port_min": 8000, + "http_port_max": 9000, + "ssh_username": "admin", + "ssh_password": "admin", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "echo 'shutdown -P now' > shutdown.sh; chmod +x shutdown.sh; sudo ./shutdown.sh", + "format": "raw", + "vm_name": "debian-minimal" } ], "provisioners": [ @@ -23,8 +38,8 @@ "type": "shell", "inline": [ "sudo apt-get update", - "sudo apt-get upgrade -y", - "sudo apt-get install -y nginx" + "sudo apt-get install -y openssh-server", + "sudo apt-get clean" ] } ] diff --git a/cableos/cableos.pkr.hcl b/cableos/cableos.pkr.hcl index b4742f5..8793e55 100644 --- a/cableos/cableos.pkr.hcl +++ b/cableos/cableos.pkr.hcl @@ -1,41 +1,100 @@ +locals { + qemu_arch = { + "amd64" = "x86_64" + "arm64" = "aarch64" + } + uefi_imp = { + "amd64" = "OVMF" + "arm64" = "AAVMF" + } + qemu_machine = { + "amd64" = "accel=kvm" + "arm64" = "virt" + } + qemu_cpu = { + "amd64" = "host" + "arm64" = "cortex-a57" + } + +} +source "null" "dependencies" { + communicator = "none" +} + +source "qemu" "cableos" { + + vm_name = "debirf-live" + boot_wait = "2s" + cpus = 2 + disk_image = true + format = qcow2 + disk_size = "10G" + type = "qemu" + headless = var.headless + http_directory = var.http_directory + http_url = "http://{{ .HTTPIP }}:{{ .HTTPPort }}/" + iso_checksum = "none" + iso_url = var.image_path/var.debirf_live_bullseye_amd64_iso + memory = 2048 + qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}" + qemuargs = [ + ["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"], + ["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"], + ["-device", "virtio-gpu-pci"] + ] + qemu_img_args = [ + create = ["-F", "qcow2"] + ] + boot_command = [ + [""], + ["linux", "/install.amd/vmlinuz", "initrd=/install.amd/initrd.gz", "debirf.boot=live", "fetch=http://{{ .HTTPIP }}:{{ .HTTPPort }}/debirf.cgz"] + ] + shutdown_command = "sudo -S shutdown -P now" + ssh_handshake_attempts = 50 + ssh_password = "install" + ssh_timeout = var.timeout + ssh_username = "root" + ssh_wait_timeout = var.timeout + use_backing_file = true +} -source "qemu" "debirf" { - boot_command = { - "", - "linux /casper/vmlinuz boot=casper initrd=/casper/initrd quiet -- ", - "initrd /casper/initrd", - "boot" - ], boot_wait = "3s" - communicator = "none" - disk_size = "4G" - headless = var.headless - iso_checksum = "none" - iso_url = "${var.cableos_iso_url}" - memory = 2048 - qemuargs = [["-serial", "stdio"], ["-cpu", "host"]] - shutdown_timeout = var.timeout - ssh_username = "ubuntu" - ssh_password = "ubuntu" - ssh_wait_timeout = "10000s" - http_content = { - "/cableos.ks" = templatefile("${var.http_path}/cableos.ks.pkrtpl.hcl", - { - KS_PROXY = local.ks_proxy - } - ) + + + +build { + name = "cableos.deps" + sources = ["source.null.dependencies"] + + provisioner "shell-local" { + inline = [ + "cp ${var.source_iso_directory}/${var.debirf_live_bullseye_amd64_iso} ${var.image_path}/" + # "sudo mount -o loop ${var.image_path}/${var.debirf_live_bullseye_amd64_iso} ${var.debirf_tmp_path}" + "cp ${var.debirf_tmp_path}/${var.debirf_initrd_filename} ${var.image_path}/" + # "cp ${var.source_iso_directory}/${var.apollo_iso} ${var.http_path}/" + # "sudo umount -lf ${var.debirf_tmp_path}" + ] + inline_shebang = "/bin/bash -e" } } build { - sources = ["source.qemu.cableos"] + name = "debirf.image" + sources = ["source.qemu.debirf"] + + provisioner "shell" { + environment_vars = ["DEBIAN_FRONTEND=noninteractive"] + expect_disconnect = true + scripts = ["${var.scripts_directory}/apollo_install.sh"] + } post-processor "shell-local" { inline = [ - "SOURCE=sles15", - "ROOT_PARTITION=2", + "IMG_FMT=qcow2", + "SOURCE=debirf", + "ROOT_PARTITION=1", "OUTPUT=${var.filename}", "source ../scripts/fuse-nbd", "source ../scripts/fuse-tar-root" @@ -43,4 +102,3 @@ build { inline_shebang = "/bin/bash -e" } } -q diff --git a/cableos/cableosvariables.pkr.hcl b/cableos/cableosvariables.pkr.hcl index 669b1bb..9afae63 100644 --- a/cableos/cableosvariables.pkr.hcl +++ b/cableos/cableosvariables.pkr.hcl @@ -24,14 +24,25 @@ variable "http_directory" { default = "http" description = "HTTP directory accessible to images during build" } - -variable "apollo_iso_src_path" { +variable "scripts_directory" { + type = string + default = "scripts" + description "Build script directory" +} +variable "apollo_iso" { type = string - default = "/opt/APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso" + default = "APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso" description = "Apollo PLatform iso location" } -variable "debirf_build_path" { +variable "source_iso_directory" { + type = string + default = "/opt" + description = "Location of source Debirf and Apollo ISO files" +} + + +variable "debirf_tmp_path" { type = string default = "debirf" description = "Debian LiveImage build directory" @@ -42,14 +53,20 @@ variable "image_path" { default = "images" description = "Boot image directory" } -variable "debirf_live_bullseye_amd64_iso_src_path" { +variable "debirf_live_bullseye_amd64_iso" { type = string - default = "/opt/debirf-live_bullseye_amd64.iso" + default = "debirf-live_bullseye_amd64.iso" description = "Pre-Existing Debirf-Liveimage path" } -variable "debirf_src_filename" { + +variable "deb_netinst_url" { + type = string + default = "https://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/amd64/iso-cd/debian-testing-amd64-netinst.iso" + description = "debian netinstall iso url" +} +variable "debirf_initrd_filename" { type = string - default = "minimal.tgz" + default = "live_bullseye_6.0.0-0.deb11.6-amd64.cgz" description = "Name of the 'debirf' creation sourcefiles" } diff --git a/cableos/debirf.pkr.hcl b/cableos/debirf.pkr.hcl index 5040aa5..f5d8183 100644 --- a/cableos/debirf.pkr.hcl +++ b/cableos/debirf.pkr.hcl @@ -25,36 +25,71 @@ source "null" "dependencies" { source "qemu" "debirf" { + vm_name = "debirf-live" boot_wait = "2s" cpus = 2 disk_image = true - disk_size = "4G" + format = qcow2 + disk_size = "10G" type = "qemu" - format = "qcow2" headless = var.headless http_directory = var.http_directory + http_url = "http://{{ .HTTPIP }}:{{ .HTTPPort }}/" iso_checksum = "none" - iso_url = var.debirf_iso_path + iso_url = var.image_path/var.debirf_live_bullseye_amd64_iso memory = 2048 qemu_binary = "qemu-system-${lookup(local.qemu_arch, var.architecture, "")}" - qemu_img_args { - create = ["-F", "qcow2"] - } qemuargs = [ ["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"], ["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"], ["-device", "virtio-gpu-pci"] ] + qemu_img_args = [ + create = ["-F", "qcow2"] + ] + boot_command = [ + [""], + ["linux", "/install.amd/vmlinuz", "initrd=/install.amd/initrd.gz", "debirf.boot=live", "fetch=http://{{ .HTTPIP }}:{{ .HTTPPort }}/debirf.cgz"] + ] shutdown_command = "sudo -S shutdown -P now" ssh_handshake_attempts = 50 - ssh_password = var.ssh_password + ssh_password = "install" ssh_timeout = var.timeout - ssh_username = var.ssh_username + ssh_username = "root" ssh_wait_timeout = var.timeout use_backing_file = true } - +source "qemu" "cableos" { + iso_url = var.deb_netinst_url + iso_checksum = "auto" + boot_command = [ + "", + "install ", + "auto=true ", + "priority=critical ", + "locale=en_US ", + "keyboard-configuration/xkb-keymap=us ", + "netcfg/get_hostname=debian ", + "netcfg/get_domain=vm ", + "fb=false ", + "debconf/frontend=noninteractive ", + "console-setup/ask_detect=false ", + "interface=auto ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg " + ] + http_directory = "http" + disk_size = 10240 + http_port_min = 8000 + http_port_max = 9000 + ssh_username = "admin" + ssh_password = "admin" + ssh_port = 22 + ssh_wait_timeout = "10000s" + shutdown_command = "echo 'shutdown -P now' > shutdown.sh; chmod +x shutdown.sh; sudo ./shutdown.sh" + format = "raw" + vm_name = "debian-minimal" +} build { @@ -63,12 +98,11 @@ build { provisioner "shell-local" { inline = [ - "cd ${var.debirf_build_path}" - "tar -zxvf ${debirf_src_filename}" - "debirf makeiso minimal" - "cd ${path.root}" - "mv ${var.debirf_livecreator_path} ${var.image_path}/" - "mv ${var.apollo_iso_src_path} ${var.http_path}/" + "cp ${var.source_iso_directory}/${var.debirf_live_bullseye_amd64_iso} ${var.image_path}/" + "sudo mount -o loop ${var.image_path}/${var.debirf_live_bullseye_amd64_iso} ${var.debirf_tmp_path}" + "cp ${var.debirf_tmp_path}/${var.debirf_initrd_filename} ${var.image_path}/" + "cp ${var.source_iso_directory}/${var.apollo_iso} ${var.http_path}/" + "sudo umount -lf ${var.debirf_tmp_path}" ] inline_shebang = "/bin/bash -e" } @@ -82,7 +116,48 @@ build { provisioner "shell" { environment_vars = ["DEBIAN_FRONTEND=noninteractive"] expect_disconnect = true - scripts = ["${path.root}/scripts/apollo_install.sh"] + scripts = ["${var.scripts_directory}/apollo_install.sh"] + } + + post-processor "shell-local" { + inline = [ + "IMG_FMT=qcow2", + "SOURCE=cloudimg", + "ROOT_PARTITION=1", + "OUTPUT=${var.filename}", + "source ../scripts/fuse-nbd", + "source ../scripts/fuse-tar-root" + ] + inline_shebang = "/bin/bash -e" + } +} + + + +build { + sources = [ + "source.qemu.cableos" + ] + + provisioner "shell" { + inline = [ + "sudo apt-get update", + "sudo apt-get install -y openssh-server", + "sudo apt-get clean" + ] + } +} + + + +build { + name = "cableos.image" + sources = ["source.qemu.debirf"] + + provisioner "shell" { + environment_vars = ["DEBIAN_FRONTEND=noninteractive"] + expect_disconnect = true + scripts = ["${var.scripts_directory}/apollo_install.sh"] } post-processor "shell-local" { diff --git a/cableos/debirf/minimal.tgz b/cableos/debirf/minimal.tgz index d535fd5..1e94987 100644 Binary files a/cableos/debirf/minimal.tgz and b/cableos/debirf/minimal.tgz differ diff --git a/cableos/debirf/minimal/debirf.conf b/cableos/debirf/minimal/debirf.conf new file mode 100644 index 0000000..a729923 --- /dev/null +++ b/cableos/debirf/minimal/debirf.conf @@ -0,0 +1,45 @@ +# DEBIRF configuration file: this will be sourced by bash + +# Label for debirf system (for hostname and initrd). "debirf" will be +# used if unspecified. +# +DEBIRF_LABEL="debirf_live" + +# Where shoud debirf build the image? By default, debirf will build +# in the profile directory. +# +# DEBIRF_BUILDD="../images/" + +# What suite should be used? The default is determined by +# lsb_release, and falls back to "sid". +# +DEBIRF_SUITE="trusty" + +# The default distro (eg. "debian" or "ubuntu") is based on the distro +# of the suite specified. If you want to use a suite from a +# non-Debian/Ubuntu distro, specify the distro explicitly here (all +# lowercase). +# +DEBIRF_DISTRO="ubuntu" + +# What mirror should debirf pull the suite from? By default, this is +# based on the DEBIRF_DISTRO +# (eg. "http://mirrors.kernel.org/${DEBIRF_DISTRO}"). +# +#DEBIRF_MIRROR= + +# What keyring should be used to verify the debootstrap for the +# specified suite? This is also based on the DEBIRF_DISTRO by +# default. If you are trying to build a non-Debian/Ubuntu version of +# debirf, then you will need to specify the keyring explicitly here if +# you want to verify the debootstrap. Otherwise, uncomment the +# variable but leave the definition blank to have debirf skip the +# debootstrap verification. +# +#DEBIRF_KEYRING= + +# Use a web proxy for downloading the packages (the "export" in front +# of the variable is necessary to have it recognized by all internal +# functions). +# +#export http_proxy="http://proxy4.spoc.charterlab.com:8080" diff --git a/cableos/debirf/minimal/modules/a0_motd b/cableos/debirf/minimal/modules/a0_motd new file mode 120000 index 0000000..8e3ad2f --- /dev/null +++ b/cableos/debirf/minimal/modules/a0_motd @@ -0,0 +1 @@ +/usr/share/debirf/modules/a0_motd \ No newline at end of file diff --git a/cableos/debirf/minimal/modules/a0_prep-root b/cableos/debirf/minimal/modules/a0_prep-root new file mode 120000 index 0000000..654bc70 --- /dev/null +++ b/cableos/debirf/minimal/modules/a0_prep-root @@ -0,0 +1 @@ +/usr/share/debirf/modules/a0_prep-root \ No newline at end of file diff --git a/cableos/debirf/minimal/modules/install-kernel b/cableos/debirf/minimal/modules/install-kernel new file mode 120000 index 0000000..a1be2bc --- /dev/null +++ b/cableos/debirf/minimal/modules/install-kernel @@ -0,0 +1 @@ +/usr/share/debirf/modules/install-kernel \ No newline at end of file diff --git a/cableos/debirf/minimal/modules/network b/cableos/debirf/minimal/modules/network new file mode 120000 index 0000000..979418d --- /dev/null +++ b/cableos/debirf/minimal/modules/network @@ -0,0 +1 @@ +/usr/share/debirf/modules/network \ No newline at end of file diff --git a/cableos/debirf/minimal/modules/root-bashrc b/cableos/debirf/minimal/modules/root-bashrc new file mode 120000 index 0000000..651d030 --- /dev/null +++ b/cableos/debirf/minimal/modules/root-bashrc @@ -0,0 +1 @@ +/usr/share/debirf/modules/root-bashrc \ No newline at end of file diff --git a/cableos/debirf/minimal/modules/z0_remove-locales b/cableos/debirf/minimal/modules/z0_remove-locales new file mode 120000 index 0000000..80a82fa --- /dev/null +++ b/cableos/debirf/minimal/modules/z0_remove-locales @@ -0,0 +1 @@ +/usr/share/debirf/modules/z0_remove-locales \ No newline at end of file diff --git a/cableos/debirf/minimal/modules/z1_clean-root b/cableos/debirf/minimal/modules/z1_clean-root new file mode 120000 index 0000000..f0d3aad --- /dev/null +++ b/cableos/debirf/minimal/modules/z1_clean-root @@ -0,0 +1 @@ +/usr/share/debirf/modules/z1_clean-root \ No newline at end of file diff --git a/cableos/http/cableos.ks.pkrtpl.hcl b/cableos/http/cableos.ks.pkrtpl.hcl index 2e1aeaa..90500e3 100644 --- a/cableos/http/cableos.ks.pkrtpl.hcl +++ b/cableos/http/cableos.ks.pkrtpl.hcl @@ -1,108 +1,21 @@ -# Turn off after installation -poweroff - -# Do not start the Inital Setup app -firstboot --disable - -# System language, keyboard and timezone -lang en_US.UTF-8 -keyboard us -timezone UTC --utc - -# Set the first NIC to acquire IPv4 address via DHCP -network --device eth0 --bootproto=dhcp -# Enable firewal, let SSH through -firewall --enabled --service=ssh -# Enable SELinux with default enforcing policy -selinux --enforcing - -# Do not set up XX Window System -skipx - -# Initial disk setup -# Use the first paravirtualized disk -ignoredisk --only-use=vda -# Place the bootloader on the Master Boot Record -bootloader --location=mbr --driveorder="vda" --timeout=1 -# Wipe invalid partition tables -zerombr -# Erase all partitions and assign default labels -clearpart --all --initlabel -# Initialize the primary root partition with ext4 filesystem -part / --size=1 --grow --asprimary --fstype=ext4 - -# Set root password -rootpw --plaintext password - -# Add a user named packer -user --groups=wheel --name=rocky --password=rocky --plaintext --gecos="rocky" - -%post --erroronfail -# workaround anaconda requirements and clear root password -passwd -d root -passwd -l root - -# Clean up install config not applicable to deployed environments. -for f in resolv.conf fstab; do - rm -f /etc/$f - touch /etc/$f - chown root:root /etc/$f - chmod 644 /etc/$f -done - -rm -f /etc/sysconfig/network-scripts/ifcfg-[^lo]* - -# Kickstart copies install boot options. Serial is turned on for logging with -# Packer which disables console output. Disable it so console output is shown -# during deployments -sed -i 's/^GRUB_TERMINAL=.*/GRUB_TERMINAL_OUTPUT="console"/g' /etc/default/grub -sed -i '/GRUB_SERIAL_COMMAND="serial"/d' /etc/default/grub -sed -ri 's/(GRUB_CMDLINE_LINUX=".*)\s+console=ttyS0(.*")/\1\2/' /etc/default/grub -sed -i 's/GRUB_ENABLE_BLSCFG=.*/GRUB_ENABLE_BLSCFG=false/g' /etc/default/grub - -yum clean all - -# Passwordless sudo for the user 'rocky' -echo "rocky ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/rocky -chmod 440 /etc/sudoers.d/rocky - -#---- Optional - Install your SSH key ---- -# mkdir -m0700 /home/rocky/.ssh/ -# -# cat </home/rocky/.ssh/authorized_keys -# ssh-rsa you@your.domain -# EOF -# -### set permissions -# chmod 0600 /home/rocky/.ssh/authorized_keys -# -#### fix up selinux context -# restorecon -R /home/rocky/.ssh/ - -%end - -%packages -@Core -bash-completion -cloud-init -cloud-utils-growpart -rsync -tar -patch -yum-utils -grub2-efi-x64 -shim-x64 -grub2-efi-x64-modules -efibootmgr -dosfstools -lvm2 -mdadm -device-mapper-multipath -iscsi-initiator-utils --plymouth -# Remove ALSA firmware --a*-firmware -# Remove Intel wireless firmware --i*-firmware -%end +d-i debian-installer/locale string en_US +d-i keyboard-configuration/xkb-keymap select us +d-i netcfg/choose_interface select auto +d-i mirror/country string manual +d-i mirror/http/hostname string httpredir.debian.org +d-i mirror/http/directory string /debian +d-i mirror/http/proxy string +d-i partman-auto/method string regular +d-i partman-auto/choose_recipe select atomic +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i passwd/user-fullname string MAAS User +d-i passwd/username string maasuser +d-i passwd/user-password password insecure +d-i passwd/user-password-again password insecure +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i finish-install/reboot_in_progress note diff --git a/cableos/http/preseed.cfg b/cableos/http/preseed.cfg index a3e33ea..90500e3 100644 --- a/cableos/http/preseed.cfg +++ b/cableos/http/preseed.cfg @@ -1,3 +1,21 @@ -mkdir http -# Add necessary files like preseed.cfg into this directory +d-i debian-installer/locale string en_US +d-i keyboard-configuration/xkb-keymap select us +d-i netcfg/choose_interface select auto +d-i mirror/country string manual +d-i mirror/http/hostname string httpredir.debian.org +d-i mirror/http/directory string /debian +d-i mirror/http/proxy string +d-i partman-auto/method string regular +d-i partman-auto/choose_recipe select atomic +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i passwd/user-fullname string MAAS User +d-i passwd/username string maasuser +d-i passwd/user-password password insecure +d-i passwd/user-password-again password insecure +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i finish-install/reboot_in_progress note diff --git a/cableos/scripts/apollo_install.sh b/cableos/scripts/apollo_install.sh index 89806a9..719bf9f 100644 --- a/cableos/scripts/apollo_install.sh +++ b/cableos/scripts/apollo_install.sh @@ -1,3 +1,9 @@ #!/bin/bash -ex export DEBIAN_FRONTEND=noninteractive -export APOLLO_PKG=/data/APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso +export APOLLO_PKG=APOLLO_PLATFORM-release-3.21.3.0-7+auto15.iso +mkdir /data +wget -O /data/${APOLLO_PKG} http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}:/${APOLLO_PKG} + +# run ostree-production command + +ostree-production -D /dev/sda from /data/${APOLLO_PKG}