Switch to squashfs for tiny rootfs! (#438)

* try squashfs

* rw

* build squash directly

* oops

* cleanup
This commit is contained in:
Adeeb Shihadeh
2025-01-24 15:41:49 -08:00
committed by GitHub
parent f0d8f77a56
commit 1e16811f45
9 changed files with 76 additions and 24 deletions
+1
View File
@@ -18,6 +18,7 @@ RUN apt-get update && \
openssl \
ccache \
libcap2-bin \
squashfs-tools \
&& rm -rf /var/lib/apt/lists/*
RUN if [ ${UID:-0} -ne 0 ] && [ ${GID:-0} -ne 0 ]; then \
+3 -17
View File
@@ -13,13 +13,8 @@ BUILD_DIR="$DIR/build"
OUTPUT_DIR="$DIR/output"
ROOTFS_DIR="$BUILD_DIR/agnos-rootfs"
ROOTFS_IMAGE="$BUILD_DIR/system.img"
OUT_IMAGE="$OUTPUT_DIR/system.img"
# the partition is 10G, but openpilot's updater didn't always handle the full size
# openpilot fix, shipped in 0.9.8 (8/18/24): https://github.com/commaai/openpilot/pull/33320
ROOTFS_IMAGE_SIZE=4200M
# Create temp dir if non-existent
mkdir -p $BUILD_DIR $OUTPUT_DIR
@@ -93,15 +88,9 @@ exec_as_root() {
docker exec $MOUNT_CONTAINER_ID "$@"
}
# Create filesystem ext4 image
echo "Creating empty filesystem"
exec_as_user fallocate -l $ROOTFS_IMAGE_SIZE $ROOTFS_IMAGE
exec_as_user mkfs.ext4 $ROOTFS_IMAGE &> /dev/null
# Mount filesystem
echo "Mounting empty filesystem"
exec_as_root mkdir -p $ROOTFS_DIR
exec_as_root mount $ROOTFS_IMAGE $ROOTFS_DIR
# Also unmount filesystem (overwrite previous trap)
trap "exec_as_root umount -l $ROOTFS_DIR &> /dev/null || true; \
@@ -139,11 +128,8 @@ set_network_stuff() {
GIT_HASH=${GIT_HASH:-$(git --git-dir=$DIR/.git rev-parse HEAD)}
exec_as_root bash -c "set -e; export ROOTFS_DIR=$ROOTFS_DIR GIT_HASH=$GIT_HASH; $(declare -f set_network_stuff); set_network_stuff"
# Unmount image
echo "Unmount filesystem"
exec_as_root umount -l $ROOTFS_DIR
# Copy system image to output
cp $ROOTFS_IMAGE $OUT_IMAGE
echo "Creating final squashfs image"
rm -f $OUT_IMAGE
exec_as_root mksquashfs $ROOTFS_DIR $OUT_IMAGE -comp xz -Xbcj arm -b 1M -Xdict-size 100%
echo "Done!"
+1
View File
@@ -94,6 +94,7 @@ apt-fast install --no-install-recommends -yq \
speedtest-cli \
ssh \
sshfs \
squashfs-tools \
sudo \
systemd-resolved \
systemd-timesyncd \
+1 -2
View File
@@ -1,7 +1,6 @@
#!/bin/bash -e
sudo mount -o rw,remount /
sudo resize2fs $(findmnt -n -o SOURCE /) &>/dev/null || sudo resize2fs $(findmnt -n -o SOURCE /)
/usr/comma/remount.sh
sudo mount -o remount,size=1500M /var
sudo cp -r /usr/default/var/lib/dpkg /var/lib/
sudo sed -i '/bionic/s/^/#/' /etc/apt/sources.list
+1
View File
@@ -73,6 +73,7 @@ mkdir -p /data/tmp
mkdir -p /data/tmp/vscode-server
ln -s /data/tmp/vscode-server ~/.vscode-server
ln -s /data/tmp/vscode-server ~/.cursor-server
ln -s /data/tmp/vscode-server ~/.windsurf-server
while true; do
pkill -f "$SETUP"
+66
View File
@@ -0,0 +1,66 @@
#!/bin/bash
set -e
if [ "$(df -T / | tail -n1 | awk '{print $2}')" = "ext4" ]; then
sudo mount -o rw,remount /
exit 0
fi
echo "AGNOS is in read-only production mode. Switching to development mode."
echo
echo "WARNING: DO NOT power off while this script is running."
echo "If you do, use https://flash.comma.ai to recover."
echo "Once the script is done, it will automatically reboot into development mode."
echo
echo -n "Ready to continue? [y/N] "
read response
if [[ ! "$response" =~ ^[yY]$ ]]; then
echo "Aborting."
exit 1
fi
CUR_SLOT="$(getslotsuffix)"
if [ "$CUR_SLOT" == "_b" ]; then
NEW_SLOT="_a"
elif [ "$CUR_SLOT" == "_a" ]; then
NEW_SLOT="_b"
else
echo "Invalid slot"
exit 1
fi
echo "- cur slot: $CUR_SLOT"
echo "- new slot: $NEW_SLOT"
# copy all the partitions from the current slot to the new slot, except for system
echo "- copying partitions"
cd /dev/disk/by-partlabel
for part in $(ls | grep "${CUR_SLOT}$"); do
base_part=$(echo "$part" | sed "s/${CUR_SLOT}$//")
if [ "$base_part" != "system" ]; then
echo " - $base_part"
dd if="$part" of="${base_part}${NEW_SLOT}" bs=1M status=none
fi
done
# unpack the squashfs system image into an ext4 image for the other slot
set -x
echo "- unpacking squashfs image"
yes | sudo mkfs.ext4 "/dev/disk/by-partlabel/system${NEW_SLOT}" >/dev/null 2>&1
MNT="$(mktemp -d)"
sudo mount "/dev/disk/by-partlabel/system${NEW_SLOT}" $MNT
sudo rm -rf "$MNT/lost+found/"
sudo unsquashfs -d $MNT "/dev/disk/by-partlabel/system${CUR_SLOT}"
sudo umount $MNT
sync
# set the boot slot
echo "- setting new boot slot"
SLOT_NUM=0
if [ "$NEW_SLOT" == "_b" ]; then
SLOT_NUM=1
fi
abctl --set_active $SLOT_NUM
echo
echo "All done! Rebooting into development AGNOS..."
sudo reboot
+1 -2
View File
@@ -6,8 +6,7 @@ export TMPDIR=/tmp/pip-tmp
# setup large tmp for install
mkdir -p $TMPDIR
sudo mount -o remount,size=2G /tmp
sudo mount -o rw,remount /
sudo resize2fs $(findmnt -n -o SOURCE /) &>/dev/null || sudo resize2fs $(findmnt -n -o SOURCE /)
/usr/comma/remount.sh
# run command
sudo TMPDIR=$TMPDIR PIP_NO_CACHE_DIR=1 $PIP_PATH "$@"
+1 -2
View File
@@ -6,8 +6,7 @@ export TMPDIR=/tmp/uv-tmp
# setup large tmp for install
mkdir -p $TMPDIR
sudo mount -o remount,size=2G /tmp
sudo mount -o rw,remount /
sudo resize2fs $(findmnt -n -o SOURCE /) &>/dev/null || sudo resize2fs $(findmnt -n -o SOURCE /)
/usr/comma/remount.sh
# run command
sudo -E TMPDIR=$TMPDIR UV_NO_CACHE=1 $UV_PATH "$@"