[general] new option to setup btrfs compression method

for support old and boring 3.x kernels
This commit is contained in:
may 2019-05-10 02:34:03 +08:00
parent 1f5962140e
commit 6d1b94af97
2 changed files with 15 additions and 3 deletions

View File

@ -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 ))

View File

@ -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/@