First take on resizable btrfs rootfs

This commit is contained in:
ThomasKaiser 2017-08-28 09:19:57 -07:00
parent b21fc4c15f
commit dc09142e75
3 changed files with 51 additions and 26 deletions

View File

@ -28,7 +28,7 @@ ROOTFS_CACHE_MAX=8 # max number of rootfs cache, older ones will be cleaned up
# 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 ))
[[ "btrfs f2fs" == *$ROOTFS_TYPE* && -z $FIXED_IMAGE_SIZE ]] && exit_with_error "Please define FIXED_IMAGE_SIZE"
[[ "f2fs" == *$ROOTFS_TYPE* && -z $FIXED_IMAGE_SIZE ]] && exit_with_error "Please define FIXED_IMAGE_SIZE"
[[ $RELEASE == stretch && $CAN_BUILD_STRETCH != yes ]] && exit_with_error "Building Debian Stretch images with selected kernel is not supported"

View File

@ -291,7 +291,7 @@ prepare_partitions()
# mountopts[ext2] is empty
# mountopts[fat] is empty
# mountopts[f2fs] is empty
# mountopts[btrfs] is empty
mountopts[btrfs]=',commit=600,compress=lzo'
# mountopts[nfs] is empty
# stage: determine partition configuration
@ -330,9 +330,19 @@ prepare_partitions()
fi
else
local imagesize=$(( $rootfs_size + $OFFSET + $BOOTSIZE )) # MiB
# Hardcoded overhead +40% and +128MB for ext4 is needed for desktop images, for CLI it can be lower
# also add extra 128 MiB for the emergency swap file creation and align the size up to 4MiB
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.4) / 1 + 128) / 4 + 1) * 4")
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-force=zlib
local sdsize=$(bc -l <<< "scale=0; (($imagesize * 0.9) / 4 + 1) * 4")
;;
*)
# Hardcoded overhead +40% and +128MB for ext4 is needed for desktop images,
# for CLI it could be lower. Also add extra 128 MiB for the emergency swap
# file creation and align the size up to 4MiB
local sdsize=$(bc -l <<< "scale=0; ((($imagesize * 1.4) / 1 + 128) / 4 + 1) * 4")
;;
esac
fi
# stage: create blank image

View File

@ -119,35 +119,50 @@ do_expand_partition()
fi
}
do_expand_filesystem()
do_expand_ext4()
{
local rootpart=$(findmnt -n -o SOURCE /) # i.e. /dev/mmcblk0p1
echo -e "\n### [resize2fs] Start resizing ext4 partition $1 now\n" >> ${Log}
resize2fs ${rootpart} >> ${Log} 2>&1
}
echo -e "\n### [resize2fs] Start resizing partition now\n" >> ${Log}
resize2fs $rootpart >> ${Log} 2>&1
do_expand_btrfs()
{
echo -e "\n### [btrfs resize] Start resizing btrfs partition $1 now\n" >> ${Log}
btrfs filesystem resize max / >> ${Log} 2>&1
}
case "$1" in
start)
# skip resizing if rootfs is not ext4 or if explicitly disabled
if [[ $(findmnt -n -o FSTYPE /) != ext4 || -f /root/.no_rootfs_resize ]]; then
systemctl disable resize2fs
# skip resizing if rootfs is neither ext4 not btrfs or if explicitly disabled
if [[ -f /root/.no_rootfs_resize ]]; then
systemctl disable resize2fs
exit 0
fi
rootfstype=$(findmnt -n -o FSTYPE /)
rootpart=$(findmnt -n -o SOURCE /) # i.e. /dev/mmcblk0p1
case ${rootfstype} in
ext4)
# first stage - resize the rootfs partition
[[ ! -f /var/lib/armbian/resize_second_stage ]] && do_expand_partition
# second stage - resize the filesystem
[[ ! -f /var/run/resize2fs-reboot ]] && do_expand_ext4 ${rootpart}
;;
btrfs)
# first stage - resize the rootfs partition
[[ ! -f /var/lib/armbian/resize_second_stage ]] && do_expand_partition
# second stage - resize the filesystem
do_expand_btrfs ${rootpart} && systemctl disable resize2fs
;;
esac
# disable itself
[[ ! -f /var/run/resize2fs-reboot ]] && systemctl disable resize2fs
exit 0
fi
# first stage - resize the partition
[[ ! -f /var/lib/armbian/resize_second_stage ]] && do_expand_partition
# second stage - resize the filesystem
[[ ! -f /var/run/resize2fs-reboot ]] && do_expand_filesystem
# disable itself
[[ ! -f /var/run/resize2fs-reboot ]] && systemctl disable resize2fs
exit 0
;;
;;
*)
echo "Usage: $0 start"
exit 0
echo "Usage: $0 start"
exit 0
;;
esac