<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yair Havoynik on Medium]]></title>
        <description><![CDATA[Stories by Yair Havoynik on Medium]]></description>
        <link>https://medium.com/@yairhav?source=rss-cb09f52b83e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-1CZ_-kKgbA9B9HszHY6dA.jpeg</url>
            <title>Stories by Yair Havoynik on Medium</title>
            <link>https://medium.com/@yairhav?source=rss-cb09f52b83e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:53:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yairhav/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a Custom Ubuntu 24.04.2 Desktop Autoinstall ISO with Local Package Repository]]></title>
            <link>https://medium.com/@yairhav/creating-a-custom-ubuntu-24-04-2-desktop-autoinstall-iso-with-local-package-repository-0088165929ff?source=rss-cb09f52b83e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/0088165929ff</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Yair Havoynik]]></dc:creator>
            <pubDate>Tue, 02 Sep 2025 11:19:24 GMT</pubDate>
            <atom:updated>2025-09-02T11:19:24.639Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Written by Yair Havoynik, September 2, 2025</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oaNMWClFSlhF-E1oJsPvxw.png" /></figure><p>Automating Ubuntu desktop installations with <strong>autoinstall</strong> is powerful, but one of the biggest challenges is <strong>offline package installation</strong>. By default, the packages: field in autoinstall.yaml tries to fetch packages from the network using Subiquity. If the target system doesn’t have internet access, the installation fails—a major issue for secure or isolated environments.</p><p>In this article, I walk you through a <strong>tested solution</strong>: building a <strong>custom Ubuntu 24.04.2 Desktop autoinstall ISO with an embedded local package repository</strong>. This approach allows you to install <strong>any requested package fully offline</strong>, reliably, and reproducibly.</p><p>The process has been successfully tested in <strong>VMware 17.6.2</strong> (efi mode) with Ubuntu 24.04.2 Desktop.</p><h3>Key Idea</h3><p>The essence of this solution is <strong>decoupling package installation from network access</strong> while keeping the power of autoinstall intact. It’s <strong>not just about providing a </strong><strong>packages: list</strong>; it’s about creating a <strong>self-contained, signed local repository</strong> that Subiquity can use entirely offline.</p><p>Achieving this required careful orchestration:</p><ol><li><strong>Parse and download packages</strong> — The script reads the packages: list from autoinstall.yaml and downloads all requested packages along with their dependencies.</li><li><strong>Build a local repository</strong> — All packages are organized in localrepo/pool/main/&lt;first-letter&gt;/&lt;package&gt;, with proper package indices generated using dpkg-scanpackages.</li><li><strong>Sign the repository</strong> — A GPG key is created, and the repository’s Release file is signed to ensure trust. Both InRelease and detached signatures are included.</li><li><strong>Remove network-dependent configuration</strong> — The packages: section is removed from the autoinstall YAML to prevent Subiquity from attempting network installation.</li><li><strong>Configure late-commands</strong> — During installation, the repository and GPG key are copied to the target system, default Ubuntu .sources files are removed, and a .sources file pointing to the local repo is created. The system then runs apt-get update and installs all packages from my-packages.txt.</li></ol><p>This ensures the system installs exactly the requested packages <strong>without ever reaching the network</strong>. The effort involved in setting up package indices, signing the repository, and carefully orchestrating late-commands results in a <strong>fully offline-capable, reliable autoinstall ISO</strong>.</p><h3>Environment Notes</h3><ul><li>Build performed on Ubuntu 24.04.2 Desktop (same version as the ISO).</li><li>Requires yq v4.x (installed via snap).</li><li>ISO used: ubuntu-24.04.2-desktop-amd64.iso.</li><li>Script: create-iso-2404-apt.sh.</li><li>Note: The password for the Ubuntu image is <strong>root</strong> if login is needed after installation.</li></ul><h3>Script: create-iso-2404-apt.sh</h3><pre>#!/bin/bash<br># Script to create a custom Ubuntu autoinstall ISO for Ubuntu 24.04.2<br># Assumes ubuntu-24.04.2-desktop-amd64.iso and autoinstall.yaml are in the current directory<br># Exit immediately if a command exits with a non-zero status<br>set -e<br># Variables<br>ISO_NAME=&quot;ubuntu-24.04.2-desktop-amd64.iso&quot;<br>ISO_CUSTOM=&quot;$(pwd)/ubuntu-24.04.2-desktop-autoinstall.iso&quot;<br>WORK_DIR=&quot;$(pwd)/ubuntu-autoinstall&quot;<br>MOUNT_DIR=&quot;$WORK_DIR/mount&quot;<br>ISO_DIR=&quot;$WORK_DIR/iso&quot;<br>AUTOINSTALL_FILE=&quot;autoinstall.yaml&quot;<br>AUTOINSTALL_FILE_FULL=&quot;$(pwd)/$AUTOINSTALL_FILE&quot;<br>KEY_NAME=&quot;LocalISO Signing Key&quot;<br>KEY_EMAIL=&quot;localiso@example.com&quot;<br>KEYRING_DIR=&quot;usr/share/keyrings&quot;<br>GPG_HOME=&quot;$WORK_DIR/gnupg&quot;<br>PUBLIC_KEY_FILE=&quot;$WORK_DIR/public.key&quot;<br>UBUNTU_SOURCES_DIR=&quot;$ISO_DIR/etc/apt/sources.list.d&quot;<br># Check for required files<br>if [[ ! -f &quot;$ISO_NAME&quot; ]]; then<br>    echo &quot;ISO file &#39;$ISO_NAME&#39; not found in the current directory.&quot;<br>    exit 1<br>fi<br>if [[ ! -f &quot;$AUTOINSTALL_FILE&quot; ]]; then<br>    echo &quot;Autoinstall file &#39;$AUTOINSTALL_FILE&#39; not found in the current directory.&quot;<br>    exit 1<br>fi<br># Install required tools<br>echo &quot;Installing required packages...&quot;<br>sudo apt-get update<br>sudo apt-get install -y xorriso grub-pc-bin grub-efi-amd64-bin grub-efi-ia32-bin mtools \<br>    rsync dpkg-dev apt-rdepends snapd gpg apt-utils squashfs-tools<br>    <br># install yq (https://github.com/mikefarah/yq/) version v4.46.1<br>sudo snap install yq<br># ---------------------------<br># Create working directories<br>echo &quot;Creating working directories...&quot;<br>mkdir -p &quot;$MOUNT_DIR&quot; &quot;$ISO_DIR&quot;<br># Mount the original ISO<br>echo &quot;Mounting the original ISO...&quot;<br>sudo mount -o loop &quot;$ISO_NAME&quot; &quot;$MOUNT_DIR&quot;<br># Copy ISO contents<br>echo &quot;Copying ISO contents...&quot;<br>sudo rsync -a &quot;$MOUNT_DIR/&quot; &quot;$ISO_DIR/&quot;<br># Unmount ISO<br>echo &quot;Unmounting ISO...&quot;<br>sudo umount &quot;$MOUNT_DIR&quot;<br># Adjust permissions<br>echo &quot;Adjusting permissions...&quot;<br>sudo chown -R &quot;$(whoami):$(whoami)&quot; &quot;$ISO_DIR/&quot;<br>sudo chmod -R u+w &quot;$ISO_DIR/&quot;<br># Extract package list from YAML<br>PACKAGE_LIST=$(yq &#39;.autoinstall.packages[]&#39; &quot;$AUTOINSTALL_FILE&quot; | tr -d &#39;&quot;&#39;)<br># Prepare temp download directory<br>TMP_PKGS=&quot;$WORK_DIR/debs&quot;<br>mkdir -p &quot;$TMP_PKGS&quot;<br>cd &quot;$TMP_PKGS&quot;<br>##################################################################################################<br># Download packages + dependencies<br>##################################################################################################<br>for pkg in $PACKAGE_LIST; do<br>    DEPS=$(apt-rdepends &quot;$pkg&quot; 2&gt;/dev/null | grep -v &quot;^ &quot; | grep -v &quot;^PreDepends&quot; | sort -u)<br>    for dep in $DEPS; do<br>        apt-get download &quot;$dep&quot; || true<br>    done<br>done<br># Copy .deb files into ISO localrepo/pool/main/&lt;first-letter&gt;/&lt;package&gt;/<br>mkdir -p &quot;$ISO_DIR/localrepo/pool/main&quot;<br>shopt -s nullglob<br>for deb in &quot;$TMP_PKGS&quot;/*.deb; do<br>    base=$(basename &quot;$deb&quot;)<br>    pkgname=&quot;${base%%_*}&quot;<br>    first_letter=$(echo &quot;$pkgname&quot; | cut -c1 | tr &#39;[:upper:]&#39; &#39;[:lower:]&#39;)<br>    target_dir=&quot;$ISO_DIR/localrepo/pool/main/$first_letter/$pkgname&quot;<br>    mkdir -p &quot;$target_dir&quot;<br>    mv &quot;$deb&quot; &quot;$target_dir/&quot;<br>done<br>shopt -u nullglob<br>##################################################################################################<br># Write all packages from PACKAGE_LIST into my-packages.txt inside localrepo<br>printf &quot;%s\n&quot; $PACKAGE_LIST &gt; &quot;$ISO_DIR/localrepo/my-packages.txt&quot;<br>##################################################################################################<br>##################################################################################################<br># Rebuild Packages index<br>##################################################################################################<br>cd &quot;$ISO_DIR&quot;<br># Create directories if missing<br>mkdir -p &quot;$ISO_DIR/dists/localiso/main/binary-amd64&quot;<br># Generate Packages file<br>dpkg-scanpackages localrepo/pool/main /dev/null &gt; &quot;$ISO_DIR/dists/localiso/main/binary-amd64/Packages&quot;<br>gzip -9c &quot;$ISO_DIR/dists/localiso/main/binary-amd64/Packages&quot; &gt; &quot;$ISO_DIR/dists/localiso/main/binary-amd64/Packages.gz&quot;<br>##################################################################################################<br># Generate Release file<br>##################################################################################################<br>cd &quot;$ISO_DIR/dists/localiso&quot;<br># Create minimal header first<br>cat &gt; Release.header &lt;&lt;EOF<br>Origin: Local ISO<br>Label: Local ISO<br>Suite: localiso<br>Codename: localiso<br>Date: $(date -R)<br>Architectures: amd64<br>Components: main<br>Description: Local ISO repository<br>EOF<br># Generate full Release with checksums<br>apt-ftparchive release . &gt;&gt; Release.header<br># Replace Release<br>mv Release.header Release<br># ---------------------------<br># Prepare autoinstall.yaml for ISO<br>cp &quot;$AUTOINSTALL_FILE_FULL&quot; &quot;$ISO_DIR/autoinstall.yaml&quot;<br># Remove packages section in-place inside ISO copy<br>yq -i &#39;del(.autoinstall.packages)&#39; &quot;$ISO_DIR/autoinstall.yaml&quot;<br>##################################################################################################<br># Add local ISO repository for offline installation<br>##################################################################################################<br>mkdir -p &quot;$UBUNTU_SOURCES_DIR&quot;<br># Add local ISO repo as a .sources file (Deb822 format)<br>cat &gt; &quot;$UBUNTU_SOURCES_DIR/localiso.sources&quot; &lt;&lt;EOF<br>Types: deb<br>URIs: file:///cdrom<br>Suites: localiso<br>Architectures: amd64<br>Components: main<br>Signed-By: /usr/share/keyrings/localiso.gpg<br>EOF<br>##################################################################################################<br># Add late-commands<br>##################################################################################################<br>yq -i &#39;<br>  .autoinstall[&quot;late-commands&quot;] |= ( . // [] ) |<br>  .autoinstall[&quot;late-commands&quot;] += [<br>    # copy GPG key into target<br>    &quot;cp /cdrom/usr/share/keyrings/localiso.gpg /target/usr/share/keyrings/localiso.gpg&quot;,<br>    # copy .sources file into target<br>    &quot;cp /cdrom/etc/apt/sources.list.d/localiso.sources /target/etc/apt/sources.list.d/localiso.sources&quot;,<br>    # rewrite .sources file to point to /opt/localrepo<br>    &quot;sed -i s@file:///cdrom@file:///opt/localrepo@ /target/etc/apt/sources.list.d/localiso.sources&quot;,<br>    # create folders dists and localrepo<br>    &quot;mkdir -p /target/opt/localrepo/dists&quot;,<br>    &quot;mkdir -p /target/opt/localrepo/localrepo&quot;,<br>    # Copy both folders and my-packages.txt into target<br>    &quot;cp -r /cdrom/dists/localiso /target/opt/localrepo/dists/&quot;,<br>    &quot;cp -r /cdrom/localrepo/pool /target/opt/localrepo/localrepo/&quot;,<br>    &quot;cp /cdrom/localrepo/my-packages.txt /target/opt/localrepo/my-packages.txt&quot;,<br>    <br>    # remove all other apt sources inside target<br>    &quot;find /target/etc/apt/sources.list.d -type f ! -name localiso.sources -delete&quot;,<br>    &quot;rm -f /target/etc/apt/sources.list&quot;,<br>    <br>    # Bring the packages from the localrepo<br>    &quot;curtin in-target -- apt-get update&quot;,<br>    # install all packages from the local repo inside target<br>    &quot;curtin in-target -- xargs -a /opt/localrepo/my-packages.txt apt-get install -y&quot;<br>  ]<br>&#39; &quot;$ISO_DIR/autoinstall.yaml&quot;<br>##################################################################################################<br># GPG key generation (passwordless, non-interactive)<br>##################################################################################################<br>mkdir -p &quot;$GPG_HOME&quot;<br>chmod 700 &quot;$GPG_HOME&quot;<br>cat &gt; &quot;$WORK_DIR/key_config&quot; &lt;&lt;EOF<br>%no-protection<br>Key-Type: RSA<br>Key-Length: 2048<br>Subkey-Type: RSA<br>Subkey-Length: 2048<br>Name-Real: localiso<br>Name-Email: localiso@example.com<br>Expire-Date: 0<br>%commit<br>EOF<br>gpg --homedir &quot;$GPG_HOME&quot; --batch --gen-key &quot;$WORK_DIR/key_config&quot;<br># Export public key<br>gpg --homedir &quot;$GPG_HOME&quot; --armor --export &quot;$KEY_EMAIL&quot; &gt; &quot;$PUBLIC_KEY_FILE&quot;<br># Prepare keyring directory inside ISO<br>mkdir -p &quot;$ISO_DIR/$KEYRING_DIR&quot;<br>gpg --homedir &quot;$GPG_HOME&quot; --dearmor &lt; &quot;$PUBLIC_KEY_FILE&quot; &gt; &quot;$ISO_DIR/$KEYRING_DIR/localiso.gpg&quot;<br>##################################################################################################<br># SIGN THE RELEASE FILE<br>##################################################################################################<br># Create signed InRelease file (preferred method)<br>gpg --homedir &quot;$GPG_HOME&quot; --default-key &quot;$KEY_EMAIL&quot; --clearsign --output &quot;$ISO_DIR/dists/localiso/InRelease&quot; &quot;$ISO_DIR/dists/localiso/Release&quot;<br># Optional: also create detached signature (some tools expect it)<br>gpg --homedir &quot;$GPG_HOME&quot; --default-key &quot;$KEY_EMAIL&quot; --armor --detach-sign --output &quot;$ISO_DIR/dists/localiso/Release.gpg&quot; &quot;$ISO_DIR/dists/localiso/Release&quot;<br>##################################################################################################<br># Modify GRUB config<br>echo &quot;Modifying GRUB configuration...&quot;<br>GRUB_CFG=&quot;$ISO_DIR/boot/grub/grub.cfg&quot;<br>sudo tee &quot;$GRUB_CFG&quot; &gt; /dev/null &lt;&lt;EOF<br>search --set=root --file /casper/vmlinuz<br>set default=0<br>set timeout=5<br>menuentry &quot;Autoinstall Ubuntu Desktop&quot; {<br>    linux /casper/vmlinuz autoinstall ---<br>    initrd /casper/initrd<br>}<br>EOF<br># Create GRUB EFI image<br>echo &quot;Creating GRUB EFI image...&quot;<br>mkdir -p &quot;$ISO_DIR/EFI/boot&quot;<br>grub-mkstandalone \<br>    --format=x86_64-efi \<br>    --output=&quot;$ISO_DIR/EFI/boot/bootx64.efi&quot; \<br>    --locales=&quot;&quot; \<br>    --fonts=&quot;&quot; \<br>    &quot;boot/grub/grub.cfg=$GRUB_CFG&quot;<br># Create UEFI boot image<br>echo &quot;Creating UEFI boot image...&quot;<br>dd if=/dev/zero of=&quot;$ISO_DIR/boot/grub/efi.img&quot; bs=1M count=10<br>mkfs.vfat &quot;$ISO_DIR/boot/grub/efi.img&quot;<br>mmd -i &quot;$ISO_DIR/boot/grub/efi.img&quot; efi efi/boot<br>mcopy -i &quot;$ISO_DIR/boot/grub/efi.img&quot; &quot;$ISO_DIR/EFI/boot/bootx64.efi&quot; ::efi/boot/<br># Update md5sum.txt<br>echo &quot;Updating MD5 checksums...&quot;<br>cd &quot;$ISO_DIR&quot;<br>rm -f md5sum.txt<br>find . -type f ! -name &#39;md5sum.txt&#39; ! -path &#39;./ubuntu/*&#39; -exec md5sum {} \; | tee md5sum.txt<br># Create new ISO<br>echo &quot;Creating custom ISO...&quot;<br>cd &quot;$WORK_DIR&quot;<br>xorriso -as mkisofs \<br>    -iso-level 3 \<br>    -o &quot;$ISO_CUSTOM&quot; \<br>    -full-iso9660-filenames \<br>    -volid &quot;UBUNTU_24_04_2_DESKTOP_AMD64&quot; \<br>    -eltorito-boot boot/grub/i386-pc/eltorito.img \<br>        -no-emul-boot \<br>        -boot-load-size 4 \<br>        -boot-info-table \<br>    -eltorito-alt-boot \<br>    -e boot/grub/efi.img \<br>        -no-emul-boot \<br>    -isohybrid-gpt-basdat \<br>    &quot;$ISO_DIR&quot;<br># Cleanup<br>echo &quot;Cleaning up...&quot;<br>rm -rf &quot;$WORK_DIR&quot;<br>echo &quot;✅ Custom autoinstall ISO created: $ISO_CUSTOM&quot;</pre><h3>Autoinstall Configuration: autoinstall.yaml</h3><pre># Required configuration<br>autoinstall:<br>  version: 1<br>  identity:<br>    realname: &quot;Yair&quot;<br>    username: yair<br>    password: &quot;$6$waYPVPOxFt8dyvLH$q4fyT7t.SyVomTXbBf.ziU1JxGQrDt/4V6TL2AJqAHf44l7R5HIaj7uJTVVQ7Tn7kTVl36j8HEOSO5OE0H7q8.&quot;<br>    hostname: computer-name<br>  storage:<br>    config:<br>      - {id: disk-sda, type: disk, path: /dev/nvme0n1, ptable: gpt, wipe: superblock, preserve: false, grub_device: false}<br>      - {id: partition-efi, type: partition, device: disk-sda, size: 512MB, wipe: superblock, flag: boot, number: 1, preserve: false, grub_device: true}<br>      - {id: format-efi, type: format, fstype: fat32, volume: partition-efi}<br>      - {id: mount-efi, type: mount, path: /boot/efi, device: format-efi}<br>      - {id: partition-boot, type: partition, device: disk-sda, size: 1GB, number: 2}<br>      - {id: format-boot, type: format, fstype: ext4, volume: partition-boot}<br>      - {id: mount-boot, type: mount, path: /boot, device: format-boot}<br>      - {id: partition-root, type: partition, device: disk-sda, size: 15GB, flag: &quot;boot&quot;, number: 3}<br>      - {id: format-root, type: format, volume: partition-root, fstype: ext4}<br>      - {id: mount-root, type: mount, device: format-root, path: /}<br>      - {id: partition-var, type: partition, device: disk-sda, size: 10GB, number: 4}<br>      - {id: format-var, type: format, fstype: ext4, volume: partition-var}<br>      - {id: mount-var, type: mount, device: format-var, path: /var}<br>      - {id: partition-var-tmp, type: partition, device: disk-sda, size: 1GB, number: 5}<br>      - {id: format-var-tmp, type: format, fstype: ext4, volume: partition-var-tmp}<br>      - {id: mount-var-tmp, type: mount, device: format-var-tmp, path: /var/tmp}<br>      - {id: partition-var-log, type: partition, device: disk-sda, size: 1GB, number: 6}<br>      - {id: format-var-log, type: format, fstype: ext4, volume: partition-var-log}<br>      - {id: mount-var-log, type: mount, device: format-var-log, path: /var/log}<br>      - {id: partition-var-log-audit, type: partition, device: disk-sda, size: 1GB, number: 7}<br>      - {id: format-var-log-audit, type: format, fstype: ext4, volume: partition-var-log-audit}<br>      - {id: mount-var-log-audit, type: mount, device: format-var-log-audit, path: /var/log/audit}<br>      - {id: partition-home, type: partition, device: disk-sda, size: 20GB, number: 8}<br>      - {id: format-home, type: format, fstype: ext4, volume: partition-home}<br>      - {id: mount-home, type: mount, device: format-home, path: /home}<br>  keyboard:<br>    layout: &quot;us&quot;<br>    variant: &quot;&quot;<br>  locale: &quot;en_US.UTF-8&quot;<br>  timezone: &quot;Etc/UTC&quot;<br>  source:<br>    id: ubuntu-desktop-minimal<br>  network:<br>    version: 2<br>    ethernets: {}<br>  apt:<br>    fallback: offline-install<br>  packages:<br>    - i2c-tools<br>    - openssh-server<br>    - net-tools</pre><h3>Final Words</h3><p>Achieving fully offline package installation for Ubuntu Desktop autoinstall required significant effort: parsing dependencies, building a signed local repository, carefully configuring late-commands, and removing network sources to prevent Subiquity from failing.</p><p>The result is a <strong>robust, self-contained ISO</strong> capable of installing any package offline, making it ideal for <strong>secure or isolated environments</strong>, labs, or production systems where internet access is unavailable or restricted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0088165929ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>