Skip to content
Snippets Groups Projects
Commit 93257bd2 authored by lejeune quentin's avatar lejeune quentin
Browse files

[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: a9a8aa5e
parent b327dee6
No related branches found
No related tags found
No related merge requests found
......@@ -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}"
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}"
sleep 5
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}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment