Skip to content

Commit

Permalink
Btrfs compression (#889)
Browse files Browse the repository at this point in the history
* btrfs: compress image at build time
Adding force-compress will force btrfs to try compress every file in the image and writing the compression result only if it is smaller than the original file, otherwise the original file will be stored: this will spare space on the user disk while slowing down builds.
Compressing the btrfs image makes almost no difference in the size of the xz image (a few bytes, about 1MiB in my tests), and the decompression penality is not noticeable and in case of slow disk loading less data might actually be benefiacial to the end-user.

* btrfs: enable run-time compression
This commits enable default compression on btrfs using the zstd algorithm with a compression level that is reported as being real-time by official btrfs documentation: https://btrfs.readthedocs.io/en/latest/Compression.html

Using compress instead of compress-force leaves enabled the heuristic to determine if compressing the whole file is worth it: this avoids additional strain on the end-user system.

* btrfs: allow compression by removing nodatacow

Address concerns about data fragmentation by executing a btrfs filesystem defragment.
  • Loading branch information
NeroReflex committed Apr 1, 2024
1 parent cda461e commit af9fe8c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mkdir -p ${MOUNT_PATH}

fallocate -l ${SIZE} ${BUILD_IMG}
mkfs.btrfs -f ${BUILD_IMG}
mount -t btrfs -o loop,nodatacow ${BUILD_IMG} ${MOUNT_PATH}
mount -t btrfs -o loop,compress-force=zstd:15 ${BUILD_IMG} ${MOUNT_PATH}
btrfs subvolume create ${BUILD_PATH}

# copy the makepkg.conf into chroot
Expand Down Expand Up @@ -152,9 +152,9 @@ Subsystem sftp /usr/lib/ssh/sftp-server
echo "
LABEL=frzr_root / btrfs subvol=deployments/${SYSTEM_NAME}-${VERSION},ro,noatime,nodatacow 0 0
LABEL=frzr_root /var btrfs subvol=var,rw,noatime,nodatacow 0 0
LABEL=frzr_root /home btrfs subvol=home,rw,noatime,nodatacow 0 0
LABEL=frzr_root /frzr_root btrfs subvol=/,rw,noatime,nodatacow 0 0
LABEL=frzr_root /var btrfs subvol=var,rw,noatime,nodatacow,compress=zstd:3 0 0
LABEL=frzr_root /home btrfs subvol=home,rw,noatime,nodatacow,compress=zstd:3 0 0
LABEL=frzr_root /frzr_root btrfs subvol=/,rw,noatime,nodatacow,compress=zstd:3 0 0
LABEL=frzr_efi /boot vfat rw,noatime,nofail 0 0
" > /etc/fstab
Expand Down Expand Up @@ -213,6 +213,9 @@ mkdir /var
mkdir /frzr_root
EOF

#defrag the image
btrfs filesystem defragment -r ${BUILD_PATH}

# copy files into chroot again
cp -R rootfs/. ${BUILD_PATH}/
rm -rf ${BUILD_PATH}/extra_certs
Expand Down

0 comments on commit af9fe8c

Please sign in to comment.