Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/packages/raspi/export-image/prerun.sh
Views: 3959
#!/bin/bash -e12#if [ "${NO_PRERUN_QCOW2}" = "0" ]; then3# IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"4#5# unmount_image "${IMG_FILE}"6#7# rm -f "${IMG_FILE}"8#9# rm -rf "${ROOTFS_DIR}"10# mkdir -p "${ROOTFS_DIR}"11#12# BOOT_SIZE="$((256 * 1024 * 1024))"13# ROOT_SIZE=$(du --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --exclude boot --block-size=1 | cut -f 1)14#15# # All partition sizes and starts will be aligned to this size16# ALIGN="$((4 * 1024 * 1024))"17# # Add this much space to the calculated file size. This allows for18# # some overhead (since actual space usage is usually rounded up to the19# # filesystem block size) and gives some free space on the resulting20# # image.21# ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 200 * 1024 * 1024) / 1" | bc)"22#23# BOOT_PART_START=$((ALIGN))24# BOOT_PART_SIZE=$(((BOOT_SIZE + ALIGN - 1) / ALIGN * ALIGN))25# ROOT_PART_START=$((BOOT_PART_START + BOOT_PART_SIZE))26# ROOT_PART_SIZE=$(((ROOT_SIZE + ROOT_MARGIN + ALIGN - 1) / ALIGN * ALIGN))27# IMG_SIZE=$((BOOT_PART_START + BOOT_PART_SIZE + ROOT_PART_SIZE))28#29# truncate -s "${IMG_SIZE}" "${IMG_FILE}"30#31# parted --script "${IMG_FILE}" mklabel msdos32# parted --script "${IMG_FILE}" unit B mkpart primary fat32 "${BOOT_PART_START}" "$((BOOT_PART_START + BOOT_PART_SIZE - 1))"33# parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))"34#35# echo "Creating loop device..."36# cnt=037# until LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do38# if [ $cnt -lt 5 ]; then39# cnt=$((cnt + 1))40# echo "Error in losetup. Retrying..."41# sleep 542# else43# echo "ERROR: losetup failed; exiting"44# exit 145# fi46# done47#48# BOOT_DEV="${LOOP_DEV}p1"49# ROOT_DEV="${LOOP_DEV}p2"50#51# ROOT_FEATURES="^huge_file"52# for FEATURE in 64bit; do53# if grep -q "$FEATURE" /etc/mke2fs.conf; then54# ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES"55# fi56# done57# mkdosfs -n bootfs -F 32 -s 4 -v "$BOOT_DEV" > /dev/null58# mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null59#60# mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext461# mkdir -p "${ROOTFS_DIR}/boot"62# mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot" -t vfat63#64# rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/"65# rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/" "${ROOTFS_DIR}/boot/"66#fi676869