CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/packages/raspi/export-image/prerun.sh
Views: 3959
1
#!/bin/bash -e
2
3
#if [ "${NO_PRERUN_QCOW2}" = "0" ]; then
4
# IMG_FILE="${STAGE_WORK_DIR}/${IMG_FILENAME}${IMG_SUFFIX}.img"
5
#
6
# unmount_image "${IMG_FILE}"
7
#
8
# rm -f "${IMG_FILE}"
9
#
10
# rm -rf "${ROOTFS_DIR}"
11
# mkdir -p "${ROOTFS_DIR}"
12
#
13
# BOOT_SIZE="$((256 * 1024 * 1024))"
14
# ROOT_SIZE=$(du --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --exclude boot --block-size=1 | cut -f 1)
15
#
16
# # All partition sizes and starts will be aligned to this size
17
# ALIGN="$((4 * 1024 * 1024))"
18
# # Add this much space to the calculated file size. This allows for
19
# # some overhead (since actual space usage is usually rounded up to the
20
# # filesystem block size) and gives some free space on the resulting
21
# # image.
22
# ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 200 * 1024 * 1024) / 1" | bc)"
23
#
24
# BOOT_PART_START=$((ALIGN))
25
# BOOT_PART_SIZE=$(((BOOT_SIZE + ALIGN - 1) / ALIGN * ALIGN))
26
# ROOT_PART_START=$((BOOT_PART_START + BOOT_PART_SIZE))
27
# ROOT_PART_SIZE=$(((ROOT_SIZE + ROOT_MARGIN + ALIGN - 1) / ALIGN * ALIGN))
28
# IMG_SIZE=$((BOOT_PART_START + BOOT_PART_SIZE + ROOT_PART_SIZE))
29
#
30
# truncate -s "${IMG_SIZE}" "${IMG_FILE}"
31
#
32
# parted --script "${IMG_FILE}" mklabel msdos
33
# parted --script "${IMG_FILE}" unit B mkpart primary fat32 "${BOOT_PART_START}" "$((BOOT_PART_START + BOOT_PART_SIZE - 1))"
34
# parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))"
35
#
36
# echo "Creating loop device..."
37
# cnt=0
38
# until LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do
39
# if [ $cnt -lt 5 ]; then
40
# cnt=$((cnt + 1))
41
# echo "Error in losetup. Retrying..."
42
# sleep 5
43
# else
44
# echo "ERROR: losetup failed; exiting"
45
# exit 1
46
# fi
47
# done
48
#
49
# BOOT_DEV="${LOOP_DEV}p1"
50
# ROOT_DEV="${LOOP_DEV}p2"
51
#
52
# ROOT_FEATURES="^huge_file"
53
# for FEATURE in 64bit; do
54
# if grep -q "$FEATURE" /etc/mke2fs.conf; then
55
# ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES"
56
# fi
57
# done
58
# mkdosfs -n bootfs -F 32 -s 4 -v "$BOOT_DEV" > /dev/null
59
# mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null
60
#
61
# mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4
62
# mkdir -p "${ROOTFS_DIR}/boot"
63
# mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot" -t vfat
64
#
65
# rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/"
66
# rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/" "${ROOTFS_DIR}/boot/"
67
#fi
68
69