Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

88 lignes
3.1 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="$((256 * 1024 * 1024))"
  9. ROOT_SIZE=$(du --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --exclude boot --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. PARTED_OUT=$(parted -sm "${IMG_FILE}" unit b print)
  27. BOOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 2 | tr -d B)
  28. BOOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^1:' | cut -d':' -f 4 | tr -d B)
  29. ROOT_OFFSET=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 2 | tr -d B)
  30. ROOT_LENGTH=$(echo "$PARTED_OUT" | grep -e '^2:' | cut -d':' -f 4 | tr -d B)
  31. echo "Mounting BOOT_DEV..."
  32. cnt=0
  33. until BOOT_DEV=$(losetup --show -f -o "${BOOT_OFFSET}" --sizelimit "${BOOT_LENGTH}" "${IMG_FILE}"); do
  34. if [ $cnt -lt 5 ]; then
  35. cnt=$((cnt + 1))
  36. echo "Error in losetup for BOOT_DEV. Retrying..."
  37. sleep 5
  38. else
  39. echo "ERROR: losetup for BOOT_DEV failed; exiting"
  40. exit 1
  41. fi
  42. done
  43. echo "Mounting ROOT_DEV..."
  44. cnt=0
  45. until ROOT_DEV=$(losetup --show -f -o "${ROOT_OFFSET}" --sizelimit "${ROOT_LENGTH}" "${IMG_FILE}"); do
  46. if [ $cnt -lt 5 ]; then
  47. cnt=$((cnt + 1))
  48. echo "Error in losetup for ROOT_DEV. Retrying..."
  49. sleep 5
  50. else
  51. echo "ERROR: losetup for ROOT_DEV failed; exiting"
  52. exit 1
  53. fi
  54. done
  55. echo "/boot: offset $BOOT_OFFSET, length $BOOT_LENGTH"
  56. echo "/: offset $ROOT_OFFSET, length $ROOT_LENGTH"
  57. ROOT_FEATURES="^huge_file"
  58. for FEATURE in metadata_csum 64bit; do
  59. if grep -q "$FEATURE" /etc/mke2fs.conf; then
  60. ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES"
  61. fi
  62. done
  63. mkdosfs -n boot -F 32 -v "$BOOT_DEV" > /dev/null
  64. mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null
  65. mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4
  66. mkdir -p "${ROOTFS_DIR}/boot"
  67. mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot" -t vfat
  68. rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/"
  69. rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/" "${ROOTFS_DIR}/boot/"
  70. fi