Cleanup and changes to image parition and sizing, see: https://github.com/RPi-Distro/pi-gen/pull/349#issuecomment-623850785
This commit is contained in:
parent
f917a310b3
commit
5e22be6440
3
build.sh
3
build.sh
|
@ -127,8 +127,7 @@ run_stage(){
|
||||||
log "End ${STAGE_DIR}/prerun.sh"
|
log "End ${STAGE_DIR}/prerun.sh"
|
||||||
fi
|
fi
|
||||||
for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
|
for SUB_STAGE_DIR in "${STAGE_DIR}"/*; do
|
||||||
if [ -d "${SUB_STAGE_DIR}" ] &&
|
if [ -d "${SUB_STAGE_DIR}" ] && [ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
|
||||||
[ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
|
|
||||||
run_sub_stage
|
run_sub_stage
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -85,9 +85,13 @@ export -f umount_qimage
|
||||||
# create base image / backing image / mount image
|
# create base image / backing image / mount image
|
||||||
load_qimage() {
|
load_qimage() {
|
||||||
if [ -z "${CURRENT_MOUNTPOINT}" ]; then
|
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
|
if [ ! -f "${WORK_DIR}/image-${STAGE}.qcow2" ]; then
|
||||||
pushd ${WORK_DIR} > /dev/null
|
pushd ${WORK_DIR} > /dev/null
|
||||||
|
@ -100,7 +104,7 @@ load_qimage() {
|
||||||
qemu-nbd --discard=unmap -c $NBD_DEV image-${STAGE}.qcow2
|
qemu-nbd --discard=unmap -c $NBD_DEV image-${STAGE}.qcow2
|
||||||
sync
|
sync
|
||||||
sfdisk $NBD_DEV << EOF
|
sfdisk $NBD_DEV << EOF
|
||||||
,250MiB,b
|
4,250MiB,b,*
|
||||||
,,83;
|
,,83;
|
||||||
EOF
|
EOF
|
||||||
sync
|
sync
|
||||||
|
@ -109,7 +113,9 @@ EOF
|
||||||
mkfs.ext4 -L rootfs -O "^huge_file,^metadata_csum,^64bit" $MAP_ROOT_DEV
|
mkfs.ext4 -L rootfs -O "^huge_file,^metadata_csum,^64bit" $MAP_ROOT_DEV
|
||||||
sync
|
sync
|
||||||
else
|
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"
|
echo "Creating backing image: image-${STAGE}.qcow2 <- ${WORK_DIR}/image-${PREV_STAGE}.qcow2"
|
||||||
qemu-img create -f qcow2 \
|
qemu-img create -f qcow2 \
|
||||||
-o backing_file=${WORK_DIR}/image-${PREV_STAGE}.qcow2 \
|
-o backing_file=${WORK_DIR}/image-${PREV_STAGE}.qcow2 \
|
||||||
|
@ -119,6 +125,7 @@ EOF
|
||||||
sync
|
sync
|
||||||
kpartx -a $NBD_DEV
|
kpartx -a $NBD_DEV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount -v -t ext4 $MAP_ROOT_DEV "${ROOTFS_DIR}"
|
mount -v -t ext4 $MAP_ROOT_DEV "${ROOTFS_DIR}"
|
||||||
mkdir -p "${ROOTFS_DIR}/boot"
|
mkdir -p "${ROOTFS_DIR}/boot"
|
||||||
mount -v -t vfat $MAP_BOOT_DEV "${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
|
# based on: https://github.com/SirLagz/RaspberryPi-ImgAutoSizer
|
||||||
# helper function for make_bootable_image, do not call directly
|
# helper function for make_bootable_image, do not call directly
|
||||||
function resize_qcow2() {
|
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`
|
PARTED_OUT=`parted -s -m "$NBD_DEV" unit B print`
|
||||||
PART_NO=`echo "$PARTED_OUT" | grep ext4 | awk -F: ' { print $1 } '`
|
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) } '`
|
PART_START=`echo "$PARTED_OUT" | grep ext4 | awk -F: ' { print substr($2,1,length($2)-1) } '`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user