From 6d1b94af9745722847a3dfeef297015b84db0931 Mon Sep 17 00:00:00 2001 From: may Date: Fri, 10 May 2019 02:34:03 +0800 Subject: [PATCH] [general] new option to setup btrfs compression method for support old and boring 3.x kernels --- lib/configuration.sh | 12 ++++++++++++ lib/debootstrap-ng.sh | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/configuration.sh b/lib/configuration.sh index 37a0ffbff5..722e7519f3 100644 --- a/lib/configuration.sh +++ b/lib/configuration.sh @@ -29,6 +29,18 @@ ROOT_MAPPER="armbian-root" [[ -z $ROOTFS_TYPE ]] && ROOTFS_TYPE=ext4 # default rootfs type is ext4 [[ "ext4 f2fs btrfs nfs fel" != *$ROOTFS_TYPE* ]] && exit_with_error "Unknown rootfs type" "$ROOTFS_TYPE" +# setup btrfs compression +if [[ -z $BTRFS_COMPRESSION ]];then + BTRFS_COMPRESSION=lzo +else + local btrfs_compression_ok=0 + for c in 'lzo zlib zstd';do + [[ $c == $BTRFS_COMPRESSION ]] && btrfs_compression_ok=1 + done + [[ $btrfs_compression_ok -eq 0 ]] && exit_with_error "wrong btrfs compression method" "$BTRFS_COMPRESSION" + unset btrfs_compression_ok +fi + # Fixed image size is in 1M dd blocks (MiB) # to get size of block device /dev/sdX execute as root: # echo $(( $(blockdev --getsize64 /dev/sdX) / 1024 / 1024 )) diff --git a/lib/debootstrap-ng.sh b/lib/debootstrap-ng.sh index 7efd3ceb7c..3fc5bd7047 100644 --- a/lib/debootstrap-ng.sh +++ b/lib/debootstrap-ng.sh @@ -310,7 +310,7 @@ prepare_partitions() # mountopts[ext2] is empty # mountopts[fat] is empty # mountopts[f2fs] is empty - mountopts[btrfs]=',commit=600,compress=zstd' + mountopts[btrfs]=",commit=600,compress=${BTRFS_COMPRESSION}" # mountopts[nfs] is empty # stage: determine partition configuration @@ -358,7 +358,7 @@ prepare_partitions() case $ROOTFS_TYPE in btrfs) # Used for server images, currently no swap functionality, so disk space - # requirements are rather low since rootfs gets filled with compress=zstd + # requirements are rather low since rootfs gets filled with compress=$BTRFS_COMPRESSION local sdsize=$(bc -l <<< "scale=0; (($imagesize * 0.8) / 4 + 1) * 4") ;; *) @@ -433,7 +433,7 @@ prepare_partitions() display_alert "Creating rootfs" "$ROOTFS_TYPE on $rootdevice" mkfs.${mkfs[$ROOTFS_TYPE]} ${mkopts[$ROOTFS_TYPE]} $rootdevice [[ $ROOTFS_TYPE == ext4 ]] && tune2fs -o journal_data_writeback $rootdevice > /dev/null - [[ $ROOTFS_TYPE == btrfs ]] && local fscreateopt="-o compress=zstd,space_cache=v2" + [[ $ROOTFS_TYPE == btrfs ]] && local fscreateopt="-o compress=${BTRFS_COMPRESSION},space_cache=v2" mount ${fscreateopt} $rootdevice $MOUNT/ if [[ $ROOTFS_TYPE == btrfs ]];then btrfs subvolume create $MOUNT/@