From fed2cb9ebc888a900cd1d37f937b038610fea6a2 Mon Sep 17 00:00:00 2001 From: xfnw Date: Tue, 4 Jan 2022 18:33:11 -0500 Subject: [PATCH] btrfs compression! --- alpine-make-vm-image | 16 ++++++++++++++-- example/configure.sh | 7 +++++++ example/packages | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/alpine-make-vm-image b/alpine-make-vm-image index b8053d1..dd9a7fc 100755 --- a/alpine-make-vm-image +++ b/alpine-make-vm-image @@ -271,6 +271,10 @@ setup_extlinux() { -e "s|^[# ]*(serial_port)=.*|\1=$serial_port|" \ "$mnt"/etc/update-extlinux.conf + sed -Ei \ + -e "s|remount,rw|&,noatime$COMPRESSFLAGS|" \ + "$mnt"/etc/init.d/root + chroot "$mnt" extlinux --install /boot chroot "$mnt" update-extlinux --warn-only # 2>&1 \ # | grep -Fv 'extlinux: cannot open device /dev' >&2 @@ -351,10 +355,12 @@ done : ${KEYS_DIR:="/etc/apk/keys"} : ${PACKAGES:=} : ${REPOS_FILE:="/etc/apk/repositories"} -: ${ROOTFS:="ext4"} +: ${ROOTFS:="btrfs"} : ${SCRIPT_CHROOT:="no"} : ${SERIAL_CONSOLE:="no"} +export ROOTFS + case "$ALPINE_BRANCH" in [0-9]*) ALPINE_BRANCH="v$ALPINE_BRANCH";; esac @@ -475,12 +481,18 @@ fi #----------------------------------------------------------------------- einfo 'Setting up extlinux bootloader' +COMPRESSFLAGS= +if [ "$ROOTFS" = 'btrfs' ]; then + COMPRESSFLAGS=',compress=zstd' +fi +export COMPRESSFLAGS + _apk add --root . --no-scripts syslinux setup_extlinux . "UUID=$root_uuid" "$ROOTFS" "$KERNEL_FLAVOR" "$SERIAL_PORT" cat > etc/fstab <<-EOF # - UUID=$root_uuid / $ROOTFS noatime 0 1 + UUID=$root_uuid / $ROOTFS noatime$COMPRESSFLAGS 0 1 EOF #----------------------------------------------------------------------- diff --git a/example/configure.sh b/example/configure.sh index 80d8176..d25cce7 100755 --- a/example/configure.sh +++ b/example/configure.sh @@ -45,3 +45,10 @@ rc-update add sshd default step 'Creating authorized_keys for root' mkdir -p /root/.ssh/ echo "$SSHPUBKEY" >> /root/.ssh/authorized_keys + +if [ "$ROOTFS" = 'btrfs' ]; then + step 'Compressing btrfs' + btrfs filesystem defragment -r -czstd / +fi + + diff --git a/example/packages b/example/packages index 37164c9..8a5c223 100644 --- a/example/packages +++ b/example/packages @@ -1,6 +1,7 @@ alpine-base busybox btrfs-progs +btrfs-compsize chrony network-extras openssl