Benefits of Using LZ4:
- Speed: Modules compress and decompress at remarkable speeds, making boot times lightning fast.
- Eco-friendly: While maintaining high performance, LZ4 delivers reasonable compression ratios combined with efficient decompression that work excellently in embedded or minimal setups due to its low CPU usage.
- Simplicity: Reconverting all base modules took as little as 10 seconds in my Ryzen 7 machine, producing a final base dir size of 799.8 MB for the XFCE4 newer version.
HOW TO CREATE YOUR OWN dir2lz4 script:
Code: Select all
sudo cp /usr/local/bin/dir2xzm /usr/local/bin/dir2lz4
sudo sed -i '2s/dir2xzm/dir2lz4/' /usr/local/bin/dir2lz4
sed -i 's/\$COMP/-b 256k -comp lz4/' /usr/local/bin/dir2lz4
Code: Select all
sudo mkdir -p $PORTDIR/rootcopy/usr/local/bin
sudo cp /usr/local/bin/dir2lz4 $PORTDIR/rootcopy/usr/local/bin/dir2lz4
sudo chmod +x $PORTDIR/rootcopy/usr/local/bin/dir2lz4
Code: Select all
dir2lz4 /your/directory/tree/to/be/converted/into/a/module your-lz4-module.xzm
============
Script to reconvert all your modules to LZ4 algorithm:
Code: Select all
#!/bin/bash
# Converts all .xzm modules in $PORTDIR/base to LZ4 algorithm
# Author: M. Eerie @ forum.porteus.org
[[ $EUID -ne 0 ]] && { echo "This script must be run as root."; exit 1; }
read -p "Enter the path to the input directory: " INPUT_DIR
[[ ! -d "$INPUT_DIR" ]] && { echo "The specified directory does not exist. Exiting."; exit 1; }
OUTPUT_DIR="/tmp/LZ4mods/"
TEMP_DIR="/tmp/LZ4extract" # Temporary extraction folder
mkdir -p "$OUTPUT_DIR" "$TEMP_DIR"
# Create a new SquashFS with LZ4 compression*, preserving permissions *Supported since kernel v3.18
# https://unix.stackexchange.com/questions/256898/squashfs-minimal-compression
ls "$INPUT_DIR"/*.xzm 2>/dev/null | while read -r FILE; do
if [[ -f "$FILE" ]]; then
BASENAME="${FILE%.xzm}"
TEMP_EXTRACT_DIR="$TEMP_DIR/${BASENAME##*/}"
OUTPUT_FILE="$OUTPUT_DIR/${BASENAME##*/}.xzm"
mkdir -p "$TEMP_EXTRACT_DIR"
unsquashfs -f -d "$TEMP_EXTRACT_DIR" "$FILE"
mksquashfs "$TEMP_EXTRACT_DIR" "$OUTPUT_FILE" -comp lz4
rm -rf "$TEMP_EXTRACT_DIR"
echo "Converted: $FILE -> $OUTPUT_FILE"
else
echo "No '.xzm' files were found in $INPUT_DIR."
fi
done
rm -rf "$TEMP_DIR"
echo "Conversion completed. The converted files are in $OUTPUT_DIR."
