Cleanup and changes to image parition and sizing, see: https://github.com/RPi-Distro/pi-gen/pull/349#issuecomment-623850785

pull/349/head
Holger Pandel 2020-05-05 15:37:22 +02:00
parent f917a310b3
commit 5e22be6440
8 changed files with 369 additions and 359 deletions

View File

@ -127,8 +127,7 @@ run_stage(){
log "End ${STAGE_DIR}/prerun.sh"
fi
for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
if [ -d "${SUB_STAGE_DIR}" ] &&
[ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
if [ -d "${SUB_STAGE_DIR}" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
run_sub_stage
fi
done

View File

@ -85,9 +85,13 @@ export -f umount_qimage
# create base image / backing image / mount image
load_qimage() {
if [ -z "${CURRENT_MOUNTPOINT}" ]; then
if [ ! -d "${ROOTFS_DIR}" ]; then mkdir -p "${ROOTFS_DIR}"; fi
if [ ! -d "${ROOTFS_DIR}" ]; then
mkdir -p "${ROOTFS_DIR}";
fi
if [ "${CLEAN}" = "1" ] && [ -f "${WORK_DIR}/image-${STAGE}.qcow2" ]; then rm -f "${WORK_DIR}/image-${STAGE}.qcow2"; fi
if [ "${CLEAN}" = "1" ] && [ -f "${WORK_DIR}/image-${STAGE}.qcow2" ]; then
rm -f "${WORK_DIR}/image-${STAGE}.qcow2";
fi
if [ ! -f "${WORK_DIR}/image-${STAGE}.qcow2" ]; then
pushd ${WORK_DIR} > /dev/null
@ -100,7 +104,7 @@ load_qimage() {
qemu-nbd --discard=unmap -c $NBD_DEV image-${STAGE}.qcow2
sync
sfdisk $NBD_DEV << EOF
,250MiB,b
4,250MiB,b,*
,,83;
EOF
sync
@ -109,7 +113,9 @@ EOF
mkfs.ext4 -L rootfs -O "^huge_file,^metadata_csum,^64bit" $MAP_ROOT_DEV
sync
else
if [ ! -f "${WORK_DIR}/image-${PREV_STAGE}.qcow2" ]; then exit 1; fi
if [ ! -f "${WORK_DIR}/image-${PREV_STAGE}.qcow2" ]; then
exit 1;
fi
echo "Creating backing image: image-${STAGE}.qcow2 <- ${WORK_DIR}/image-${PREV_STAGE}.qcow2"
qemu-img create -f qcow2 \
-o backing_file=${WORK_DIR}/image-${PREV_STAGE}.qcow2 \
@ -119,6 +125,7 @@ EOF
sync
kpartx -a $NBD_DEV
fi
mount -v -t ext4 $MAP_ROOT_DEV "${ROOTFS_DIR}"
mkdir -p "${ROOTFS_DIR}/boot"
mount -v -t vfat $MAP_BOOT_DEV "${ROOTFS_DIR}/boot"
@ -145,9 +152,13 @@ export -f unload_qimage
# based on: https://github.com/SirLagz/RaspberryPi-ImgAutoSizer
# helper function for make_bootable_image, do not call directly
function resize_qcow2() {
if [ -z "$CALL_FROM_MBI" ]; then echo "resize_qcow2: cannot be called directly, use make_bootable_image instead"; return 1; fi
if [ -z "$CALL_FROM_MBI" ]; then
echo "resize_qcow2: cannot be called directly, use make_bootable_image instead"
return 1
fi
ROOT_MARGIN=$((800*1024*1024))
# ROOT_MARGIN=$((800*1024*1024))
ROOT_MARGIN=$((1*1024*1024))
PARTED_OUT=`parted -s -m "$NBD_DEV" unit B print`
PART_NO=`echo "$PARTED_OUT" | grep ext4 | awk -F: ' { print $1 } '`
PART_START=`echo "$PARTED_OUT" | grep ext4 | awk -F: ' { print substr($2,1,length($2)-1) } '`