Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions gen-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ source lib.bash
ARCH=${ARCH:-$(dpkg --print-architecture)}
# Topic parameter to pass to aoscbootstrap
TOPIC_OPT=
# Filesystem type.
FSTYPE="${FSTYPE:-erofs}"
# Path to aoscbootstrap scripts and recipes
AOSCBOOTSTRAP=${AOSCBOOTSTRAP:-/usr/share/aoscbootstrap}
# Package repository to download packages from.
Expand All @@ -20,6 +22,8 @@ REPO=${REPO:-https://repo.aosc.io/debs}
WORKDIR=${WORKDIR:-$PWD/work}
# Output directory.
OUTDIR=${OUTDIR:-$PWD/iso}
# Prefix directory for layers, templates and configuration.
OUT_PREFIX="$OUTDIR"/livekit
# Layers.
LAYERS=("desktop-common" "livekit" "desktop" "desktop-nvidia")
LAYERS_NONVIDIA=("desktop-common" "livekit" "desktop")
Expand Down Expand Up @@ -301,15 +305,13 @@ squash_layer() {
return
fi
info "Squashing layer $tgt ..."
pushd "$WORKDIR/$tgt"
if [ "x$1" = "xbase" ] ; then
outfile="${OUTDIR}/squashfs/$tgt.squashfs"
outfile="${OUT_PREFIX}/$tgt.$FSTYPE"
else
outfile="${OUTDIR}/squashfs/layers/$tgt.squashfs"
outfile="${OUT_PREFIX}/layers/$tgt.$FSTYPE"
fi
mksquashfs . ${outfile} \
-noappend -comp xz -processors $(nproc)
popd
packfs "$FSTYPE" "$outfile" "$WORKDIR"/"$tgt" || \
die "Failed to pack layer into an filesystem image."
}

pack_templates() {
Expand Down Expand Up @@ -347,11 +349,9 @@ pack_templates() {
info "Umounting template layer ..."
umount ${WORKDIR}/$tgt-template-merged
info "Squashing template layer ..."
outfile=${OUTDIR}/squashfs/templates/$tgt.squashfs
pushd ${WORKDIR}/$tgt-template
mksquashfs . ${outfile} \
-noappend -comp xz -processors $(nproc)
popd
outfile=${OUT_PREFIX}/templates/"$tgt"."$FSTYPE"
packfs "$FSTYPE" "$outfile" "${WORKDIR}"/"$tgt"-template || \
die "Failed to pack the template into a filesystem image."
}

get_info() {
Expand Down Expand Up @@ -401,12 +401,12 @@ prepare() {
done
mkdir -pv ${WORKDIR}/merged
mkdir -pv ${OUTDIR}/manifest
mkdir -pv ${OUTDIR}/squashfs/layers
mkdir -pv ${OUTDIR}/squashfs/templates
mkdir -pv ${OUT_PREFIX}/layers
mkdir -pv ${OUT_PREFIX}/templates
# File for gen-recipe.py to read. Contains recipe information.
touch ${OUTDIR}/sysroots.ini
# File for the dracut loader to read. Contains layers and their dependencies.
touch ${OUTDIR}/squashfs/layers.conf
touch ${OUT_PREFIX}/livekit.conf
if [ "x$TOPICS" != "x" ] ; then
for t in $TOPICS ; do
info "Will opt in topic '$t'."
Expand Down Expand Up @@ -458,7 +458,9 @@ cat > ${OUTDIR}/sysroots.ini << EOF
sysroots=${AVAIL_SYSROOTS1[@]}

EOF
cat > ${OUTDIR}/squashfs/layers.conf << EOF
cat > ${OUT_PREFIX}/livekit.conf << EOF
# Filesystem type.
FSTYPE="$FSTYPE"
# All available layers.
LAYERS=$(dump_array AVAIL_LAYERS)
# All possible sysroots these layers combine to.
Expand All @@ -474,9 +476,9 @@ SYSROOT_DEP_desktop_nvidia=("base" "desktop-common" "desktop" "desktop-nvidia")
SYSROOT_DEP_desktop_latx=("base" "desktop-common" "desktop" "desktop-latx")
SYSROOT_DEP_livekit_nvidia=("base" "desktop-common" "desktop-nvidia" "livekit")

TEMPLATE_desktop_nvidia="desktop.squashfs"
TEMPLATE_desktop_latx="desktop.squashfs"
TEMPLATE_livekit_nvidia="livekit.squashfs"
TEMPLATE_desktop_nvidia="desktop.$FSTYPE"
TEMPLATE_desktop_latx="desktop.$FSTYPE"
TEMPLATE_livekit_nvidia="livekit.$FSTYPE"
EOF
bootstrap_base
get_info base
Expand All @@ -503,8 +505,8 @@ info "Downloading translated recipe ..."
curl -Lo "$OUTDIR"/manifest/recipe-i18n.json https://releases.aosc.io/manifest/recipe-i18n.json

info "Copying hooks ..."
cp -av ${PWD}/hooks ${OUTDIR}/squashfs/
cp -av ${PWD}/hooks ${OUT_PREFIX}/

info "Build successful!"
tree -h ${OUTDIR}
info "Total image size: $(du -sh ${OUTDIR}/squashfs | awk '{ print $1 }')"
info "Total image size: $(du -sh ${OUT_PREFIX} | awk '{ print $1 }')"
24 changes: 13 additions & 11 deletions gen-livekit.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#!/bin/bash
# New LiveKit generator.
# This "new" LiveKit will use our dracut loader to load the LiveKit.

set -e
source lib.bash
# Config file for the dracut loader.
CONF="# AOSC OS LiveKit config for LiveKit loader.
# The LiveKit itself is the base layer.
# No more configuration required!
SYSROOT_DEP_base=('base')
"

# Set of '--topics TOPIC' options to be passed to aoscbootstrap.
TOPICS_OPT=
Expand All @@ -17,13 +11,14 @@ WORKDIR=${PWD}/work
ISODIR=${PWD}/iso
AOSCBOOTSTRAP=${AOSCBOOTSTRAP:-/usr/share/aoscbootstrap}
FSTYPE=${FSTYPE:-squashfs}
OUT_PREFIX="$ISODIR"/livekit

info "Generating LiveKit distribution ..."

info "Preparing ..."
rm -rf iso work
mkdir -p $WORKDIR/livekit
mkdir -p $ISODIR/$FSTYPE
mkdir -p $ISODIR/livekit
# We have to pack up the dracut module and copy into the target sysroot
# where it will be untarred and installed into initrd.
tar cf $WORKDIR/livekit/dracut.tar dracut
Expand Down Expand Up @@ -107,16 +102,23 @@ if [[ "${RETRO}" != "1" ]]; then
fi
fi

# Config file for the dracut loader.
CONF="# AOSC OS LiveKit config for LiveKit loader.
# The LiveKit itself is the base layer.
# No more configuration required!
FSTYPE="$FSTYPE"
SYSROOT_DEP_base=('base')
"
info "Squashing rootfs ..."
packfs "$FSTYPE" "$ISODIR"/"$FSTYPE"/base.squashfs "$WORKDIR"/livekit
packfs "$FSTYPE" "$OUT_PREFIX"/base."$FSTYPE" "$WORKDIR"/livekit

info "Installing GRUB config files ..."
make -C "$PWD"/boot/grub install TARGET=livekit

info "Writing config file ..."
echo "$CONF" > $ISODIR/$FSTYPE/layers.conf
echo "$CONF" > "$OUT_PREFIX"/livekit.conf

info "Copying hooks ..."
cp -a "$PWD"/hooks $ISODIR/$FSTYPE/
cp -a "$PWD"/hooks "$OUT_PREFIX"/

info "Done generating the LiveKit image!"
104 changes: 86 additions & 18 deletions lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export LANG=C.UTF-8
export LANGUAGE=C.UTF-8
export LC_ALL=C.UTF-8

if [ "$LOCAL_TESTING" = "1" ] ; then
SQUASHFS_COMP=none
EROFS_COMP=none
fi

info() {
echo -e "\033[1;37m[\033[36mINFO\033[37m]: $@\033[0m"
}
Expand All @@ -21,6 +26,84 @@ die() {
exit 1
}

pack_squashfs() {
local _comp outfile="$1" rootpath="$2"
pushd "$WORKDIR/$tgt"
case "${SQUASHFS_COMP:-xz}" in
none)
_comp="-no-compression"
;;
xz)
_comp="-comp xz"
;;
zstd)
# Default level is 15.
_comp="-comp zstd"
;;
lz4hc)
_comp="-comp lz4 -Xhc"
;;
*)
die "Unsupported compression method '$SQUASHFS_COMP'."
;;
esac
pushd "$rootpath"
mksquashfs . ${outfile} \
-noappend $_comp -processors $(nproc)
popd
}

pack_erofs() {
local _pagesize _comp outfile="$1" srcdir="$2"
info "Creating an EROFS image \"$outfile\" from \"$srcdir\" ..."
# Kernels with larger page size can mount images with smaller block
# sizes. It does not work vice versa.
case "$ARCH" in
loongarch64|loongson3)
# The installer uses 16K kernel
_pagesize=16384
;;
ppc64el)
_pagesize=65536
;;
*)
# This is where the problem ocurrs:
# We may use a machine running a 16K kernel to
# generate EROFS images, which can not be mounted
# using a 4KB kernel.
_pagesize=4096
;;
esac
case "${EROFS_COMP:-lzma}" in
lzma)
_comp="-zlzma,level=6"
;;
lz4hc)
_comp="-zlz4hc,level=9"
;;
zstd)
# zstd uses level 1 to 19.
_comp="-zzstd,level=9"
;;
none)
_comp=""
;;
*)
die "Unsupported EROFS compression method."
;;
esac
# Use a larger cluster size for better compression.
# -E ztailpacking: Embed fragmented file contents into metadata
# blocks.
# # -E fragments: Pack small enough files into a special inode.
# The two options above makes it behave like how NTFS stores smaller
# files.
mkfs.erofs "$outfile" "$srcdir" \
-b "$_pagesize" \
-C 1048576 $_comp --worker $(nproc) -E fragments,ztailpacking
}


# $1: fstype
# $2: Output file
# $3: Path used as root (can not be a file)
Expand All @@ -45,26 +128,11 @@ packfs() {
squashfs)
pack_squashfs "$outfile" "$rootpath"
;;
erofs)
pack_erofs "$outfile" "$rootpath"
;;
*)
die "Unknown filesystem type '$fstype'."
;;
esac
}

# $1: Output file
# $2: Path used as root (can not be a file)
pack_squashfs() {
local rootpath outfile comp
outfile="$1"
rootpath="$2"
if [ "$LOCAL_TESTING" = "1" ] ; then
comp="-no-compression"
else
comp="-comp xz"
fi
info "Packing squashfs from '$rootpath' to '$outfile' ..."
pushd "$rootpath"
mksquashfs . ${outfile} \
-noappend $comp -processors $(nproc)
popd
}