From 93257bd23f4aa7f58db9bf69aafc6e22e6b41acd Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Fri, 13 Dec 2019 12:36:33 +0000 Subject: [PATCH] [IMP] point_of_sale: Modify the partitions of the IoT Box Extend boot partition to 512Mo to be compatible with a future version of Raspbian and auto flash X-original-commit: a9a8aa5ed46f7740d59c4e6f6fd6b7f3e45aabf8 --- .../tools/posbox/posbox_create_image.sh | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/addons/point_of_sale/tools/posbox/posbox_create_image.sh b/addons/point_of_sale/tools/posbox/posbox_create_image.sh index a4e81601377..dd6842df462 100755 --- a/addons/point_of_sale/tools/posbox/posbox_create_image.sh +++ b/addons/point_of_sale/tools/posbox/posbox_create_image.sh @@ -67,40 +67,60 @@ rm -v ngrok.zip cd "${__dir}" mv -v /tmp/ngrok "${USR_BIN}" -# zero pad the image to be around 3.5 GiB, by default the image is only ~1.3 GiB +# zero pad the image to be around 4.4 GiB, by default the image is only ~2.2 GiB echo "Enlarging the image..." dd if=/dev/zero bs=1M count=2048 status=progress >> iotbox.img # resize partition table echo "Fdisking" + +SECTORS_BOOT_START=$(sudo fdisk -l iotbox.img | tail -n 2 | awk 'NR==1 {print $2}') +SECTORS_BOOT_END=$((SECTORS_BOOT_START + 1048576)) # sectors to have a partition of ~512Mo +SECTORS_ROOT_START=$((SECTORS_BOOT_END + 1)) + START_OF_ROOT_PARTITION=$(fdisk -l iotbox.img | tail -n 1 | awk '{print $2}') (echo 'p'; # print echo 'd'; # delete - echo '2'; # second partition + echo '2'; # number 2 + echo 'd'; # delete number 1 by default + echo 'n'; # create new partition + echo 'p'; # primary + echo '1'; # number 1 + echo "${SECTORS_BOOT_START}"; # first sector + echo "${SECTORS_BOOT_END}"; # partition size + echo 't'; # change type of partition. 1 selected by default + echo 'c'; # change to W95 FAT32 (LBA) echo 'n'; # create new partition echo 'p'; # primary echo '2'; # number 2 - echo "${START_OF_ROOT_PARTITION}"; # starting at previous offset + echo "${SECTORS_ROOT_START}"; # starting at previous offset echo ''; # ending at default (fdisk should propose max) echo 'p'; # print echo 'w') | fdisk iotbox.img # write and quit -LOOP=$(kpartx -avs iotbox.img) -LOOP_MAPPER_PATH=$(echo "${LOOP}" | tail -n 1 | awk '{print $3}') -LOOP_PATH="/dev/${LOOP_MAPPER_PATH::-2}" -LOOP_MAPPER_PATH="/dev/mapper/${LOOP_MAPPER_PATH}" -LOOP_MAPPER_BOOT=$(echo "${LOOP}" | tail -n 2 | awk 'NR==1 {print $3}') -LOOP_MAPPER_BOOT="/dev/mapper/${LOOP_MAPPER_BOOT}" +LOOP_RASPBIAN=$(kpartx -avs "${RASPBIAN}") +LOOP_RASPBIAN_ROOT=$(echo "${LOOP_RASPBIAN}" | tail -n 1 | awk '{print $3}') +LOOP_RASPBIAN_PATH="/dev/${LOOP_RASPBIAN_ROOT::-2}" +LOOP_RASPBIAN_ROOT="/dev/mapper/${LOOP_RASPBIAN_ROOT}" -sleep 5 +LOOP_IOT=$(kpartx -avs iotbox.img) +LOOP_IOT_ROOT=$(echo "${LOOP_IOT}" | tail -n 1 | awk '{print $3}') +LOOP_IOT_PATH="/dev/${LOOP_IOT_ROOT::-2}" +LOOP_IOT_ROOT="/dev/mapper/${LOOP_IOT_ROOT}" +LOOP_IOT_BOOT=$(echo "${LOOP_IOT}" | tail -n 2 | awk 'NR==1 {print $3}') +LOOP_IOT_BOOT="/dev/mapper/${LOOP_IOT_BOOT}" + +mkfs.ext4 -v "${LOOP_IOT_ROOT}" + +dd if="${LOOP_RASPBIAN_ROOT}" of="${LOOP_IOT_ROOT}" bs=4M status=progress # resize filesystem -e2fsck -f "${LOOP_MAPPER_PATH}" # resize2fs requires clean fs -resize2fs "${LOOP_MAPPER_PATH}" +e2fsck -fv "${LOOP_IOT_ROOT}" # resize2fs requires clean fs +resize2fs "${LOOP_IOT_ROOT}" -mkdir -p "${MOUNT_POINT}" #-p: no error if existing -mount "${LOOP_MAPPER_PATH}" "${MOUNT_POINT}" -mount "${LOOP_MAPPER_BOOT}" "${MOUNT_POINT}/boot/" +mkdir -pv "${MOUNT_POINT}" #-p: no error if existing +mount -v "${LOOP_IOT_ROOT}" "${MOUNT_POINT}" +mount -v "${LOOP_IOT_BOOT}" "${MOUNT_POINT}/boot/" QEMU_ARM_STATIC="/usr/bin/qemu-arm-static" cp -v "${QEMU_ARM_STATIC}" "${MOUNT_POINT}/usr/bin/" @@ -129,6 +149,7 @@ umount -fv "${MOUNT_POINT}"/ rm -rfv "${MOUNT_POINT}" echo "Running zerofree..." -zerofree -v "${LOOP_MAPPER_PATH}" || true +zerofree -v "${LOOP_IOT_ROOT}" || true -kpartx -d "${LOOP_PATH}" +kpartx -dv "${LOOP_IOT_PATH}" +kpartx -dv "${LOOP_RASPBIAN_PATH}"