armbian-next: don't leak .raw image if failure before move; show rootfs-tmpfs info
- add escapings and TODO's around the area...
This commit is contained in:
parent
1636a2afea
commit
af7ace7e57
@ -133,7 +133,7 @@ function prepare_partitions() {
|
||||
|
||||
# stage: create blank image
|
||||
display_alert "Creating blank image for rootfs" "truncate: $sdsize MiB" "info"
|
||||
run_host_command_logged truncate --size=${sdsize}M ${SDCARD}.raw # please provide EVIDENCE of problems with this; using dd is very slow
|
||||
run_host_command_logged truncate "--size=${sdsize}M" "${SDCARD}".raw # please provide EVIDENCE of problems with this; using dd is very slow
|
||||
run_host_command_logged sync
|
||||
|
||||
# stage: calculate boot partition size
|
||||
@ -145,7 +145,7 @@ function prepare_partitions() {
|
||||
display_alert "Creating partitions" "${bootfs:+/boot: $bootfs }root: $ROOTFS_TYPE" "info"
|
||||
if [[ "${USE_HOOK_FOR_PARTITION}" == "yes" ]]; then
|
||||
{ [[ "$IMAGE_PARTITION_TABLE" == "msdos" ]] && echo "label: dos" || echo "label: $IMAGE_PARTITION_TABLE"; } |
|
||||
run_host_command_logged sfdisk ${SDCARD}.raw || exit_with_error "Create partition table fail"
|
||||
run_host_command_logged sfdisk "${SDCARD}".raw || exit_with_error "Create partition table fail"
|
||||
|
||||
call_extension_method "create_partition_table" <<- 'CREATE_PARTITION_TABLE'
|
||||
*only called when USE_HOOK_FOR_PARTITION=yes to create the complete partition table*
|
||||
@ -153,6 +153,7 @@ function prepare_partitions() {
|
||||
yourself. Good luck.
|
||||
CREATE_PARTITION_TABLE
|
||||
else
|
||||
# Create a script in a bracket shell, then pipe it to fdisk.
|
||||
{
|
||||
[[ "$IMAGE_PARTITION_TABLE" == "msdos" ]] && echo "label: dos" || echo "label: $IMAGE_PARTITION_TABLE"
|
||||
|
||||
@ -189,7 +190,7 @@ function prepare_partitions() {
|
||||
echo "$rootpart : name=\"rootfs\", start=${next}MiB, type=${type}"
|
||||
fi
|
||||
} |
|
||||
run_host_command_logged sfdisk ${SDCARD}.raw || exit_with_error "Partition fail."
|
||||
run_host_command_logged sfdisk "${SDCARD}".raw || exit_with_error "Partition fail."
|
||||
fi
|
||||
|
||||
call_extension_method "post_create_partitions" <<- 'POST_CREATE_PARTITIONS'
|
||||
@ -207,16 +208,16 @@ function prepare_partitions() {
|
||||
|
||||
CHECK_LOOP_FOR_SIZE="no" check_loop_device "$LOOP" # initially loop is zero sized, ignore it.
|
||||
|
||||
run_host_command_logged losetup $LOOP ${SDCARD}.raw # @TODO: had a '-P- here, what was it?
|
||||
run_host_command_logged losetup "${LOOP}" "${SDCARD}".raw # @TODO: had a '-P- here, what was it?
|
||||
|
||||
# loop device was grabbed here, unlock
|
||||
flock -u $FD
|
||||
|
||||
display_alert "Running partprobe" "${LOOP}" "debug"
|
||||
run_host_command_logged partprobe $LOOP
|
||||
run_host_command_logged partprobe "${LOOP}"
|
||||
|
||||
display_alert "Checking again after partprobe" "${LOOP}" "debug"
|
||||
check_loop_device "$LOOP" # check again, now it has to have a size! otherwise wait.
|
||||
check_loop_device "${LOOP}" # check again, now it has to have a size! otherwise wait.
|
||||
|
||||
# stage: create fs, mount partitions, create fstab
|
||||
rm -f $SDCARD/etc/fstab
|
||||
|
||||
@ -100,7 +100,7 @@ create_image_from_sdcard_rootfs() {
|
||||
mkdir -p "${DESTIMG}"
|
||||
# @TODO: misterious cwd, who sets it?
|
||||
|
||||
mv "${SDCARD}.raw" "${DESTIMG}/${version}.img"
|
||||
run_host_command_logged mv -v "${SDCARD}.raw" "${DESTIMG}/${version}.img"
|
||||
|
||||
# custom post_build_image_modify hook to run before fingerprinting and compression
|
||||
[[ $(type -t post_build_image_modify) == function ]] && display_alert "Custom Hook Detected" "post_build_image_modify" "info" && post_build_image_modify "${DESTIMG}/${version}.img"
|
||||
|
||||
@ -22,20 +22,24 @@ function build_rootfs_and_image() {
|
||||
# CLI needs ~2GiB, desktop ~5GiB
|
||||
# vs 60% of available RAM (free + buffers + magic)
|
||||
local available_physical_memory_mib=$(($(awk '/MemAvailable/ {print $2}' /proc/meminfo) * 6 / 1024 / 10)) # MiB
|
||||
local tmpfs_estimated_size=2000 # MiB
|
||||
[[ $BUILD_DESKTOP == yes ]] && tmpfs_estimated_size=5000 # MiB
|
||||
|
||||
local use_tmpfs=no # by default
|
||||
# @TODO: well those are very... arbitrary numbers.
|
||||
# predicting the size of tmpfs is hard/impossible, so would be nice to show the used size at the end so we can tune.
|
||||
local tmpfs_estimated_size=2000 # MiB
|
||||
[[ $BUILD_DESKTOP == yes ]] && tmpfs_estimated_size=5000 # MiB
|
||||
|
||||
declare use_tmpfs=no # by default
|
||||
if [[ ${FORCE_USE_RAMDISK} == no ]]; then # do not use, even if it fits
|
||||
:
|
||||
display_alert "Not using tmpfs for rootfs" "due to FORCE_USE_RAMDISK=no" "info"
|
||||
elif [[ ${FORCE_USE_RAMDISK} == yes || ${available_physical_memory_mib} -gt ${tmpfs_estimated_size} ]]; then # use, either force or fits
|
||||
use_tmpfs=yes
|
||||
display_alert "Using tmpfs for rootfs" "RAM available: ${available_physical_memory_mib}MiB > ${tmpfs_estimated_size}MiB estimated" "debug"
|
||||
display_alert "Using tmpfs for rootfs build" "RAM available: ${available_physical_memory_mib}MiB > ${tmpfs_estimated_size}MiB estimated" "info"
|
||||
else
|
||||
display_alert "Not using tmpfs for rootfs" "RAM available: ${available_physical_memory_mib}MiB < ${tmpfs_estimated_size}MiB estimated" "debug"
|
||||
display_alert "Not using tmpfs for rootfs" "RAM available: ${available_physical_memory_mib}MiB < ${tmpfs_estimated_size}MiB estimated" "info"
|
||||
fi
|
||||
|
||||
if [[ $use_tmpfs == yes ]]; then
|
||||
declare -g -r ROOTFS_IS_UNDER_TMPFS=yes
|
||||
mount -t tmpfs tmpfs "${SDCARD}" # do not specify size; we've calculated above that it should fit, and Linux will try its best if it doesn't.
|
||||
fi
|
||||
|
||||
@ -117,7 +121,8 @@ function trap_handler_cleanup_rootfs_and_image() {
|
||||
# unmount tmpfs mounted on SDCARD if it exists. #@TODO: move to new tmpfs-utils scheme
|
||||
mountpoint -q "${SDCARD}" && umount "${SDCARD}"
|
||||
|
||||
mountpoint -q "${SRC}"/cache/toolchain && umount -l "${SRC}"/cache/toolchain >&2 # @TODO: why does Igor uses lazy umounts? nfs?
|
||||
# @TODO: rpardini: igor: why lazy umounts?
|
||||
mountpoint -q "${SRC}"/cache/toolchain && umount -l "${SRC}"/cache/toolchain >&2
|
||||
mountpoint -q "${SRC}"/cache/rootfs && umount -l "${SRC}"/cache/rootfs >&2
|
||||
[[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose "${ROOT_MAPPER}" >&2
|
||||
|
||||
@ -134,6 +139,7 @@ function trap_handler_cleanup_rootfs_and_image() {
|
||||
|
||||
[[ -d "${SDCARD}" ]] && rm -rf --one-file-system "${SDCARD}"
|
||||
[[ -d "${MOUNT}" ]] && rm -rf --one-file-system "${MOUNT}"
|
||||
[[ -f "${SDCARD}".raw ]] && rm -f "${SDCARD}".raw
|
||||
|
||||
return 0 # short-circuit above, so exit clean here
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user