25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

68 satır
2.3 KiB

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