|
| 1 | +#!/usr/bin/bash |
| 2 | + |
| 3 | +set -exo pipefail |
| 4 | + |
| 5 | +{ export PS4='+( ${BASH_SOURCE}:${LINENO} ): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'; } 2>/dev/null |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | + |
| 9 | +# Create the directory that /root is symlinked to |
| 10 | +mkdir -p "$(realpath /root)" |
| 11 | + |
| 12 | +# bwrap tries to write /proc/sys/user/max_user_namespaces which is mounted as ro |
| 13 | +# so we need to remount it as rw |
| 14 | +mount -o remount,rw /proc/sys |
| 15 | + |
| 16 | +# Install flatpaks if list exists |
| 17 | +if [[ -f "$SCRIPT_DIR/flatpaks.list" ]]; then |
| 18 | + echo "Installing flatpaks..." |
| 19 | + curl --retry 3 -Lo /etc/flatpak/remotes.d/flathub.flatpakrepo https://dl.flathub.org/repo/flathub.flatpakrepo |
| 20 | + xargs -r flatpak install -y --noninteractive < "$SCRIPT_DIR/flatpaks.list" || true |
| 21 | +fi |
| 22 | + |
| 23 | +# Configure podman temporarily to write to /usr/lib/containers/storage |
| 24 | +# This avoids storing the huge base image in /var/lib/containers/storage |
| 25 | +# (which is empty/tmpfs in the booted live environment and would exhaust RAM) |
| 26 | +mkdir -p /etc/containers |
| 27 | +cat >/etc/containers/storage.conf <<'EOF' |
| 28 | +[storage] |
| 29 | +driver = "overlay" |
| 30 | +runroot = "/run/containers/storage" |
| 31 | +graphroot = "/usr/lib/containers/storage" |
| 32 | +EOF |
| 33 | + |
| 34 | +# Pull the container image to be installed |
| 35 | +if [[ -n "${BASE_IMAGE:-}" ]]; then |
| 36 | + podman pull "${BASE_IMAGE}" |
| 37 | +else |
| 38 | + # Fallback to reading image-info.json if BASE_IMAGE not set |
| 39 | + IMAGE_INFO="$(cat /usr/share/ublue-os/image-info.json)" |
| 40 | + IMAGE_TAG="$(jq -c -r '."image-tag"' <<<"$IMAGE_INFO")" |
| 41 | + IMAGE_REF="$(jq -c -r '."image-ref"' <<<"$IMAGE_INFO")" |
| 42 | + IMAGE_REF="${IMAGE_REF##*://}" |
| 43 | + podman pull "${IMAGE_REF}:${IMAGE_TAG}" |
| 44 | +fi |
| 45 | + |
| 46 | +# Clean up the temporary storage configuration so that runtime podman uses the default |
| 47 | +rm -f /etc/containers/storage.conf |
| 48 | + |
| 49 | +# Install required packages |
| 50 | +dnf install -y \ |
| 51 | + dracut-live \ |
| 52 | + livesys-scripts \ |
| 53 | + git \ |
| 54 | + jq \ |
| 55 | + rsync \ |
| 56 | + desktop-file-utils \ |
| 57 | + anaconda-live \ |
| 58 | + anaconda-webui \ |
| 59 | + libblockdev-btrfs \ |
| 60 | + libblockdev-lvm \ |
| 61 | + libblockdev-dm |
| 62 | + |
| 63 | +kernel=$(find /usr/lib/modules -maxdepth 1 -type d -printf '%P\n' | grep . | head -1) |
| 64 | +DRACUT_NO_XATTR=1 dracut -v --force --zstd --reproducible --no-hostonly \ |
| 65 | + --add "dmsquash-live dmsquash-live-autooverlay" \ |
| 66 | + "/usr/lib/modules/${kernel}/initramfs.img" "${kernel}" |
| 67 | + |
| 68 | +# Configure livesys-scripts |
| 69 | +sed -i "s/^livesys_session=.*/livesys_session=kde/" /etc/sysconfig/livesys |
| 70 | +systemctl enable livesys.service livesys-late.service |
| 71 | + |
| 72 | +# Run the configure/postrootfs hook |
| 73 | +# We pass BASE_IMAGE so it can be used inside the script |
| 74 | +export BASE_IMAGE="${BASE_IMAGE:-}" |
| 75 | +bash "$SCRIPT_DIR/configure_iso_anaconda.sh" |
| 76 | + |
| 77 | +# image-builder needs gcdx64.efi / grub modules |
| 78 | +_arch=$(uname -m) |
| 79 | +if [[ $_arch == "x86_64" ]]; then |
| 80 | + dnf install -y grub2-efi-x64-cdboot |
| 81 | +elif [[ $_arch == "aarch64" ]]; then |
| 82 | + dnf install -y grub2-efi-aa64-modules |
| 83 | +fi |
| 84 | + |
| 85 | +# image-builder expects the EFI directory to be in /boot/efi |
| 86 | +mkdir -p /boot/efi |
| 87 | +cp -av /usr/lib/efi/*/*/EFI /boot/efi/ |
| 88 | + |
| 89 | +# Remove fallback efi |
| 90 | +_arch=$(uname -m) |
| 91 | +if [[ $_arch == "x86_64" ]]; then |
| 92 | + cp -v /boot/efi/EFI/fedora/grubx64.efi /boot/efi/EFI/BOOT/fbx64.efi |
| 93 | +elif [[ $_arch == "aarch64" ]]; then |
| 94 | + cp -v /boot/efi/EFI/fedora/grubaa64.efi /boot/efi/EFI/BOOT/fbaa64.efi |
| 95 | +fi |
| 96 | + |
| 97 | +# Set the timezone to UTC |
| 98 | +rm -f /etc/localtime |
| 99 | +systemd-firstboot --timezone UTC |
| 100 | + |
| 101 | +# Mount a larger tmpfs to /var/tmp at boot time to avoid disk space issues |
| 102 | +mkdir -p /var/tmp |
| 103 | +cat >/etc/systemd/system/var-tmp.mount <<'EOF' |
| 104 | +[Unit] |
| 105 | +Description=Larger tmpfs for /var/tmp on live system |
| 106 | +
|
| 107 | +[Mount] |
| 108 | +What=tmpfs |
| 109 | +Where=/var/tmp |
| 110 | +Type=tmpfs |
| 111 | +Options=size=50%,nr_inodes=1m,x-systemd.graceful-option=usrquota |
| 112 | +
|
| 113 | +[Install] |
| 114 | +WantedBy=local-fs.target |
| 115 | +EOF |
| 116 | +systemctl enable var-tmp.mount |
| 117 | + |
| 118 | +# Copy in the iso config for image-builder |
| 119 | +mkdir -p /usr/lib/bootc-image-builder |
| 120 | +cp "$SCRIPT_DIR/iso.yaml" /usr/lib/bootc-image-builder/iso.yaml |
| 121 | + |
| 122 | +# Clean up dnf cache to save space |
| 123 | +dnf clean all |
0 commit comments