Skip to content

Commit

Permalink
mklive: add support for erofs rootfs and use it by default
Browse files Browse the repository at this point in the history
We get roughly 4% larger images with erofs which is not much
of a difference (and maybe it can be further tweaked) while
being able to store xattrs and getting better performance.
  • Loading branch information
q66 committed Sep 17, 2024
1 parent 4c984fa commit 605f516
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
3 changes: 3 additions & 0 deletions initramfs-tools/hooks/live
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ manual_add_modules squashfs
manual_add_modules sqlzma
manual_add_modules unlzma

# Filesystem: erofs
manual_add_modules erofs

# Filesystem: overlay
manual_add_modules overlay

Expand Down
5 changes: 3 additions & 2 deletions initramfs-tools/lib/live/boot/9990-misc-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
is_live_path()
{
DIRECTORY="${1}/${LIVE_MEDIA_PATH}"
for FILESYSTEM in squashfs ext2 ext3 ext4 xfs dir jffs
for FILESYSTEM in squashfs erofs ext2 ext3 ext4 xfs dir jffs
do
if ls "${DIRECTORY}/"*.${FILESYSTEM} > /dev/null 2>&1
then
Expand Down Expand Up @@ -43,7 +43,7 @@ matches_uuid ()
get_backing_device ()
{
case "${1}" in
*.squashfs|*.ext2|*.ext3|*.ext4|*.jffs2|*.*.verity|*.*.fec)
*.squashfs|*.erofs|*.ext2|*.ext3|*.ext4|*.jffs2|*.*.verity|*.*.fec)
echo $(setup_loop "${1}" "loop" "/sys/block/loop*" '0' "${2}")
;;

Expand Down Expand Up @@ -356,6 +356,7 @@ find_livefs ()
fi
done
elif [ "${fstype}" = "squashfs" -o \
"${fstype}" = "erofs" -o \
"${fstype}" = "btrfs" -o \
"${fstype}" = "ext2" -o \
"${fstype}" = "ext3" -o \
Expand Down
2 changes: 1 addition & 1 deletion initramfs-tools/lib/live/boot/9990-mount-http.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ do_httpmount ()
if [ -n "$url" ]
then
case "${extension}" in
iso|squashfs|tgz|tar)
iso|squashfs|erofs|tgz|tar)
if [ "${extension}" = "iso" ]
then
mkdir -p "${alt_mountpoint}"
Expand Down
4 changes: 2 additions & 2 deletions initramfs-tools/lib/live/boot/9990-overlay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ setup_unionfs ()
done
else
# ${MODULE}.module does not exist, create a list of images
for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
for FILESYSTEM in squashfs erofs ext2 ext3 ext4 xfs jffs2 dir
do
for IMAGE in "${image_directory}"/*."${FILESYSTEM}"
do
Expand All @@ -50,7 +50,7 @@ setup_unionfs ()

if [ -n "${addimage_directory}" ] && [ -d "${addimage_directory}" ]
then
for FILESYSTEM in squashfs ext2 ext3 ext4 xfs jffs2 dir
for FILESYSTEM in squashfs erofs ext2 ext3 ext4 xfs jffs2 dir
do
for IMAGE in "${addimage_directory}"/*."${FILESYSTEM}"
do
Expand Down
54 changes: 41 additions & 13 deletions mklive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ Options:
-r REPO Path to apk repository.
-k DIR Path to apk repository public key directory.
-p PACKAGES List of additional packages to install.
-s FSTYPE Filesystem to use (squashfs or erofs, default: erofs)
-h Print this message.
EOF
exit ${1:=1}
}

APK_BIN="apk"
FSTYPE="erofs"

if ! command -v "$APK_BIN" > /dev/null 2>&1; then
die "invalid apk command"
fi

if ! command -v gensquashfs > /dev/null 2>&1; then
die "gensquashfs needs to be installed (squashfs-tools-ng)"
fi

APK_ARCH=$(${APK_BIN} --print-arch)

run_apk() {
Expand All @@ -65,11 +63,26 @@ while getopts "a:f:k:o:p:r:h" opt; do
o) OUT_FILE="$OPTARG";;
p) PACKAGES="$OPTARG";;
r) APK_REPO="$APK_REPO --repository $OPTARG";;
s) FSTYPE="$OPTARG";;
h) usage 0 ;;
*) usage ;;
esac
done

case "$FSTYPE" in
squashfs)
if ! command -v gensquashfs > /dev/null 2>&1; then
die "gensquashfs needs to be installed (squashfs-tools-ng)"
fi
;;
erofs)
if ! command -v mkfs.erofs > /dev/null 2>&1; then
die "mkfs.erofs needs to be installed (erofs-utils)"
fi
;;
*) die "unknown live filesystem (${FSTYPE})" ;;
esac

shift $((OPTIND - 1))

case "$APK_ARCH" in
Expand Down Expand Up @@ -257,19 +270,34 @@ rm -f "${ROOT_DIR}/etc/shadow-" "${ROOT_DIR}/etc/gshadow-" \
"${ROOT_DIR}/etc/passwd-" "${ROOT_DIR}/etc/group-" \
"${ROOT_DIR}/etc/subuid-" "${ROOT_DIR}/etc/subgid-"

# clean up tmpfiles with xattrs not supported by squashfs
# (sd-tmpfiles will recreate them as necessary)
#
# this list may be expanded as needed
rm -rf "${ROOT_DIR}/var/lib/tpm2-tss/system/keystore"
case "$FSTYPE" in
squashfs)
# clean up tmpfiles with xattrs not supported by squashfs
# (sd-tmpfiles will recreate them as necessary)
#
# this list may be expanded as needed
rm -rf "${ROOT_DIR}/var/lib/tpm2-tss/system/keystore"
;;
esac

# generate squashfs
msg "Generating squashfs filesystem..."
# generate filesystem
msg "Generating root filesystem..."

umount_pseudo

gensquashfs --pack-dir "${ROOT_DIR}" -c xz -k -x \
"${LIVE_DIR}/filesystem.squashfs" || die "gensquashfs failed"
case "$FSTYPE" in
squashfs)
gensquashfs --pack-dir "${ROOT_DIR}" -c xz -k -x \
"${LIVE_DIR}/filesystem.squashfs" || die "gensquashfs failed"
;;
erofs)
# tried zstd, it's quite a bit bigger than xz... and experimental
# when testing, level=3 is 1.9% bigger than 16 and 0.7% bigger than 9
# ztailpacking has measurable space savings, fragments+dedupe does not
mkfs.erofs -z lzma -E ztailpacking "${LIVE_DIR}/filesystem.erofs" \
"${ROOT_DIR}" || die "mkfs.erofs failed"
;;
esac

# generate iso image
msg "Generating ISO image..."
Expand Down

0 comments on commit 605f516

Please sign in to comment.