Improve squashfs

This commit is contained in:
2026-03-29 19:42:14 -07:00
parent 49d398fd6a
commit 53ffdefe2e
2 changed files with 145 additions and 95 deletions

View File

@@ -1,101 +1,7 @@
#!/bin/bash -e
if [ "${LIVEBOOT}" != "1" ]; then
echo "squashfs-export: LIVEBOOT not set — skipping live boot setup"
else
if [ "${ARCH}" != "amd64" ]; then
echo "squashfs-export: skipping live boot setup for non-amd64 arch (${ARCH})"
exit 0
else
on_chroot << EOF
apt-get install -y \
live-boot \
live-boot-initramfs-tools \
live-config \
live-config-systemd
EOF
# Write live-config user settings
mkdir -p "${ROOTFS_DIR}/etc/live"
cat > "${ROOTFS_DIR}/etc/live/config.conf" << EOF
LIVE_USERNAME="${LIVE_USERNAME:-vesperos}"
LIVE_USER_FULLNAME="${LIVE_USER_FULLNAME:-Live User}"
LIVE_USER_DEFAULT_GROUPS="audio cdrom dip floppy video plugdev netdev bluetooth"
LIVE_USER_SHELL="/bin/zsh"
LIVE_USER_PASSWORD="${LIVE_USER_PASSWORD:-vesperos}"
LIVE_LOGIN="true"
EOF
# Rewrite fstab for the live environment.
# live-boot manages root via overlayfs — build-time disk entries cause fsck failures at boot.
cat > "${ROOTFS_DIR}/etc/fstab" << 'FSTABEOF'
# Live system fstab — root is managed by live-boot via overlayfs, not this file.
tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
FSTABEOF
# Remove first-boot trigger so GDM uses autologin in the live session.
rm -f "${ROOTFS_DIR}/var/lib/gdm/run-initial-setup"
# Make GDM wait for live-config
mkdir -p "${ROOTFS_DIR}/etc/systemd/system/gdm.service.d"
cat > "${ROOTFS_DIR}/etc/systemd/system/gdm.service.d/override.conf" << EOF
[Unit]
After=live-config.service
EOF
# Enable autoLogin on GDM
mkdir -p "${ROOTFS_DIR}/etc/gdm3"
cat > "${ROOTFS_DIR}/etc/gdm3/daemon.conf" << EOF
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=${LIVE_USERNAME:-vesperos}
EOF
# Configure initramfs for live boot — squashfs and overlay are required
if [ -f "${ROOTFS_DIR}/etc/initramfs-tools/initramfs.conf" ]; then
sed -i 's/^MODULES=.*/MODULES=most/' "${ROOTFS_DIR}/etc/initramfs-tools/initramfs.conf"
fi
for mod in squashfs overlay; do
grep -qx "${mod}" "${ROOTFS_DIR}/etc/initramfs-tools/modules" 2>/dev/null || \
echo "${mod}" >> "${ROOTFS_DIR}/etc/initramfs-tools/modules"
done
# Enable live-config system wide, instead of via grub
on_chroot << EOF
systemctl enable live-config.service
EOF
# Live-only dconf: separate database + profile so the live wallpaper
# is shown in the live session but not on the real installed system.
mkdir -p "${ROOTFS_DIR}/etc/dconf/db/live.d"
install -m 644 files/live-default-settings "${ROOTFS_DIR}/etc/dconf/db/live.d/00-default-settings"
install -m 644 files/dconf-profile-live-user "${ROOTFS_DIR}/etc/dconf/profile/live"
# Hook sets DCONF_PROFILE=live for the live user at boot
install -m 755 files/9999-vesperos-dconf "${ROOTFS_DIR}/lib/live/config/9999-vesperos-dconf"
on_chroot << EOF
dconf update
EOF
fi
fi
# If live install add calamares installer
if [ "${LIVEINSTALL}" == "1" ]; then
on_chroot << EOF
apt-get install --no-install-recommends -y \
calamares calamares-settings-vesperos \
libcrack2 cracklib-runtime \
squashfs-tools \
grub-efi-amd64 grub-pc-bin efibootmgr \
parted gdisk dosfstools e2fsprogs
EOF
fi
# Ensure update-initramfs actually runs — it silently exits if update_initramfs=no/disabled,
# which may have been set during the build to suppress apt-hook rebuilds.
# This mirrors what exports/iso/04-finalise does before calling update-initramfs.
if [ -f "${ROOTFS_DIR}/etc/initramfs-tools/update-initramfs.conf" ]; then
sed -i 's/^update_initramfs=.*/update_initramfs=yes/' "${ROOTFS_DIR}/etc/initramfs-tools/update-initramfs.conf"
fi

View File

@@ -4,6 +4,7 @@ SQUASHFS_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.squashfs"
unmount "${ROOTFS_DIR}"
# ── 1. Raw squashfs ────────────────────────────────────────────────────────────
mksquashfs "${ROOTFS_DIR}" "${SQUASHFS_FILE}" \
-comp xz \
-noappend \
@@ -68,10 +69,153 @@ cp "${SQUASHFS_FILE}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.rootfs.squ
[ -n "${VMLINUZ}" ] && cp "${VMLINUZ}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.rootfs.vmlinuz"
[ -n "${INITRD}" ] && cp "${INITRD}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}.rootfs.initrd.img"
# ── 2. Liveboot squashfs (only when LIVEBOOT=1 and amd64) ──────────────────────
if [ "${LIVEBOOT}" == "1" ]; then
if [ "${ARCH}" != "amd64" ]; then
echo "squashfs-export: skipping live boot squashfs for non-amd64 arch (${ARCH})"
else
echo "squashfs-export: applying live boot changes for liveboot squashfs"
on_chroot << EOF
apt-get install -y \
live-boot \
live-boot-initramfs-tools \
live-config \
live-config-systemd
EOF
# Write live-config user settings
mkdir -p "${ROOTFS_DIR}/etc/live"
cat > "${ROOTFS_DIR}/etc/live/config.conf" << EOF
LIVE_USERNAME="${LIVE_USERNAME:-vesperos}"
LIVE_USER_FULLNAME="${LIVE_USER_FULLNAME:-Live User}"
LIVE_USER_DEFAULT_GROUPS="audio cdrom dip floppy video plugdev netdev bluetooth"
LIVE_USER_SHELL="/bin/zsh"
LIVE_USER_PASSWORD="${LIVE_USER_PASSWORD:-vesperos}"
LIVE_LOGIN="true"
EOF
# Rewrite fstab for the live environment.
# live-boot manages root via overlayfs — build-time disk entries cause fsck failures at boot.
cat > "${ROOTFS_DIR}/etc/fstab" << 'FSTABEOF'
# Live system fstab — root is managed by live-boot via overlayfs, not this file.
tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
FSTABEOF
# Remove first-boot trigger so GDM uses autologin in the live session.
rm -f "${ROOTFS_DIR}/var/lib/gdm/run-initial-setup"
# Make GDM wait for live-config
mkdir -p "${ROOTFS_DIR}/etc/systemd/system/gdm.service.d"
cat > "${ROOTFS_DIR}/etc/systemd/system/gdm.service.d/override.conf" << EOF
[Unit]
After=live-config.service
EOF
# Enable autoLogin on GDM
mkdir -p "${ROOTFS_DIR}/etc/gdm3"
cat > "${ROOTFS_DIR}/etc/gdm3/daemon.conf" << EOF
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=${LIVE_USERNAME:-vesperos}
EOF
# Configure initramfs for live boot — squashfs and overlay are required
if [ -f "${ROOTFS_DIR}/etc/initramfs-tools/initramfs.conf" ]; then
sed -i 's/^MODULES=.*/MODULES=most/' "${ROOTFS_DIR}/etc/initramfs-tools/initramfs.conf"
fi
for mod in squashfs overlay; do
grep -qx "${mod}" "${ROOTFS_DIR}/etc/initramfs-tools/modules" 2>/dev/null || \
echo "${mod}" >> "${ROOTFS_DIR}/etc/initramfs-tools/modules"
done
# Enable live-config system wide, instead of via grub
on_chroot << EOF
systemctl enable live-config.service
EOF
# Live-only dconf: separate database + profile so the live wallpaper
# is shown in the live session but not on the real installed system.
FINALISE_DIR="$(dirname "$0")/../03-finalise"
mkdir -p "${ROOTFS_DIR}/etc/dconf/db/live.d"
install -m 644 "${FINALISE_DIR}/files/live-default-settings" "${ROOTFS_DIR}/etc/dconf/db/live.d/00-default-settings"
install -m 644 "${FINALISE_DIR}/files/dconf-profile-live-user" "${ROOTFS_DIR}/etc/dconf/profile/live"
# Hook sets DCONF_PROFILE=live for the live user at boot
install -m 755 "${FINALISE_DIR}/files/9999-vesperos-dconf" "${ROOTFS_DIR}/lib/live/config/9999-vesperos-dconf"
on_chroot << EOF
dconf update
EOF
# If live install, add calamares installer
if [ "${LIVEINSTALL}" == "1" ]; then
on_chroot << EOF
apt-get install --no-install-recommends -y \
calamares calamares-settings-vesperos \
libcrack2 cracklib-runtime \
squashfs-tools \
grub-efi-amd64 grub-pc-bin efibootmgr \
parted gdisk dosfstools e2fsprogs
EOF
fi
# Rebuild initramfs with live-boot modules
on_chroot << EOF
update-initramfs -k all -u
EOF
LIVE_SQUASHFS_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}-live.squashfs"
unmount "${ROOTFS_DIR}"
mksquashfs "${ROOTFS_DIR}" "${LIVE_SQUASHFS_FILE}" \
-comp xz \
-noappend \
-e boot/efi
# Locate updated kernel/initrd for liveboot
LIVE_VMLINUZ=$(find "${ROOTFS_DIR}/boot" -maxdepth 1 -name "vmlinuz-*" | sort | tail -1)
LIVE_INITRD=$(find "${ROOTFS_DIR}/boot" -maxdepth 1 -name "initrd.img-*" | sort | tail -1)
case "${DEPLOY_COMPRESSION}" in
zip)
pushd "${STAGE_WORK_DIR}" > /dev/null
LIVE_ZIP_MEMBERS="$(basename "${LIVE_SQUASHFS_FILE}")"
# shellcheck disable=SC2086
zip -"${COMPRESSION_LEVEL}" \
"${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.zip" \
${LIVE_ZIP_MEMBERS}
popd > /dev/null
echo "Live archive created at ${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.zip"
;;
gz)
pigz --force -"${COMPRESSION_LEVEL}" "${LIVE_SQUASHFS_FILE}" --stdout > \
"${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.squashfs.gz"
echo "Live squashfs exported at ${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.squashfs.gz"
;;
xz)
xz --compress --force --threads 0 --memlimit-compress=50% -"${COMPRESSION_LEVEL}" \
--stdout "${LIVE_SQUASHFS_FILE}" > "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.squashfs.xz"
echo "Live squashfs exported at ${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.squashfs.xz"
;;
none | *)
cp "${LIVE_SQUASHFS_FILE}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.squashfs"
echo "Live squashfs exported at ${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.squashfs"
;;
esac
cp "${LIVE_SQUASHFS_FILE}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.rootfs.squashfs"
[ -n "${LIVE_VMLINUZ}" ] && cp "${LIVE_VMLINUZ}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.rootfs.vmlinuz"
[ -n "${LIVE_INITRD}" ] && cp "${LIVE_INITRD}" "${DEPLOY_DIR}/${ARCHIVE_FILENAME}${IMG_SUFFIX}-live.rootfs.initrd.img"
fi
fi
# Cleanup
#rm -f "${SQUASHFS_FILE}"
#[ -n "${VMLINUZ_FILE}" ] && rm -f "${VMLINUZ_FILE}"
#[ -n "${INITRD_FILE}" ] && rm -f "${INITRD_FILE}"
# cleanup stage work dir
#rm -rf "${STAGE_WORK_DIR}"
#rm -rf "${STAGE_WORK_DIR}"