Skip to content

Commit 148cc86

Browse files
setup erofs for tiny rootfs! (#68)
1 parent bb57436 commit 148cc86

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

kernel/configs/vamos.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,10 @@ CONFIG_TOUCHSCREEN_S6SY761=y
8989
CONFIG_EXPERT=y
9090
CONFIG_GPIO_SYSFS=y
9191

92+
# EROFS
93+
CONFIG_EROFS_FS=y
94+
CONFIG_EROFS_FS_ZIP=y
95+
CONFIG_EROFS_FS_ZIP_LZ4=y
96+
9297
# Misc
9398
CONFIG_LOCALVERSION_AUTO=n

tools/build/Dockerfile.builder

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ RUN apk add --no-cache \
1919
git \
2020
libcap \
2121
linux-headers \
22+
lz4-dev \
2223
openssl \
2324
openssl-dev \
2425
perl \
25-
python3
26+
python3 \
27+
util-linux-dev \
28+
xz-dev
29+
30+
# Build erofs-utils from source (not packaged in Alpine)
31+
RUN git clone https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git /tmp/erofs-utils \
32+
&& cd /tmp/erofs-utils \
33+
&& git checkout v1.8.5 \
34+
&& apk add --no-cache autoconf automake libtool \
35+
&& autoreconf -fi \
36+
&& ./configure --enable-lz4 --enable-lzma --disable-fuse \
37+
&& make -j$(nproc) \
38+
&& make install \
39+
&& rm -rf /tmp/erofs-utils
2640

2741
# Cross-compiler for x86_64 hosts building aarch64 kernel
2842
# gcc-aarch64-none-elf is bare-metal but works for kernel (freestanding code)

tools/build/build_system.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ MOUNT_CONTAINER_ID="$MOUNT_CONTAINER_ID" ROOTFS_DIR="$ROOTFS_DIR" \
129129
ROOTFS_IMAGE="$ROOTFS_IMAGE" OUTPUT_DIR="$OUTPUT_DIR" \
130130
"$DIR/vamos" profile
131131

132+
# Build EROFS image (before unmount, while rootfs is still mounted)
133+
EROFS_IMAGE="$BUILD_DIR/system.erofs.img"
134+
OUT_EROFS_IMAGE="$OUTPUT_DIR/system.erofs.img"
135+
echo "Building EROFS image (LZ4HC, 64K clusters)"
136+
exec_as_root mkfs.erofs \
137+
-zlz4hc,12 \
138+
-C65536 \
139+
-T0 \
140+
--all-root \
141+
"$EROFS_IMAGE" "$ROOTFS_DIR"
142+
132143
# Unmount image
133144
echo "Unmount filesystem"
134145
exec_as_root umount -l "$ROOTFS_DIR"
@@ -137,6 +148,9 @@ exec_as_root umount -l "$ROOTFS_DIR"
137148
echo "Sparsifying system image"
138149
exec_as_user img2simg "$ROOTFS_IMAGE" "$OUT_IMAGE"
139150

151+
# Copy EROFS image to output
152+
cp "$EROFS_IMAGE" "$OUT_EROFS_IMAGE"
153+
140154
# Patch sparse image size into profile JSON
141155
SPARSE_SIZE=$(stat -c%s "$OUT_IMAGE" 2>/dev/null || stat -f%z "$OUT_IMAGE")
142156
if command -v jq &>/dev/null; then
@@ -145,4 +159,13 @@ if command -v jq &>/dev/null; then
145159
mv "$OUTPUT_DIR/rootfs-profile.json.tmp" "$OUTPUT_DIR/rootfs-profile.json"
146160
fi
147161

162+
# Size comparison
163+
EXT4_SPARSE_SIZE=$(stat -c%s "$OUT_IMAGE" 2>/dev/null || stat -f%z "$OUT_IMAGE")
164+
EROFS_SIZE=$(stat -c%s "$OUT_EROFS_IMAGE" 2>/dev/null || stat -f%z "$OUT_EROFS_IMAGE")
165+
echo ""
166+
echo "=== Image size comparison ==="
167+
echo "ext4 (sparse): $(numfmt --to=iec-i --suffix=B "$EXT4_SPARSE_SIZE") ($EXT4_SPARSE_SIZE bytes)"
168+
echo "EROFS (LZ4HC): $(numfmt --to=iec-i --suffix=B "$EROFS_SIZE") ($EROFS_SIZE bytes)"
169+
echo ""
170+
148171
echo "Done!"

0 commit comments

Comments
 (0)