You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

92 regels
2.4 KiB

  1. #!/bin/bash
  2. set -e
  3. INPUT_DIR="$1"
  4. IMAGE_NAME="$(basename $INPUT_DIR)"
  5. GRUB_IMG="$TARGET$BUILD/export.img"
  6. GRUB_DIR="$TARGET$BUILD/grub"
  7. LOOP_DEV="/dev/loop5"
  8. printf "Creating image file... "
  9. if [ "$(lsblk | grep $(basename $LOOP_DEV))" ]; then
  10. losetup -d $LOOP_DEV || true
  11. fi
  12. rm -fr $GRUB_IMG
  13. printf "(OK)\n"
  14. echo "Allocating image file..."
  15. if [ -f $GRUB_IMG ]; then
  16. rm -fr $GRUB_IMG
  17. fi
  18. qemu-img create $GRUB_IMG 10G
  19. parted -s -a optimal -- $GRUB_IMG \
  20. mklabel gpt \
  21. mkpart primary fat32 1MiB 270MiB \
  22. mkpart primary ext4 1GiB -0 \
  23. name 1 uefi \
  24. name 2 root \
  25. set 1 esp on
  26. losetup --partscan $LOOP_DEV $GRUB_IMG
  27. partprobe $LOOP_DEV
  28. echo "Allocating image file... (OK)"
  29. printf "Find partitions UUID... "
  30. ROOT_UUID=$(blkid | grep "^$LOOP_DEV" | grep ' PARTLABEL="root" ' | grep -o ' PARTUUID="[^"]\+"' | sed -e 's/^ //' )
  31. EFI_UUID=$(blkid | grep "^$LOOP_DEV" | grep ' PARTLABEL="uefi" ' | grep -o ' PARTUUID="[^"]\+"' | sed -e 's/^ //' )
  32. printf "(OK)\n"
  33. echo "Formatting image file..."
  34. mkfs -t vfat -F 32 -n EFI ${LOOP_DEV}p1
  35. mkfs -t ext4 -L root ${LOOP_DEV}p2
  36. echo "Formatting image file... (OK)"
  37. printf "Mounting root filesystem... "
  38. if [ -d "$GRUB_DIR" ]; then
  39. umount -q $GRUB_DIR || true
  40. rm -fr $GRUB_DIR
  41. fi
  42. mkdir -p $GRUB_DIR
  43. mount $ROOT_UUID $GRUB_DIR
  44. printf "(OK)\n"
  45. printf "Copying filesystem to image... "
  46. cp -rax $INPUT_DIR/. $GRUB_DIR/
  47. printf "(OK)\n"
  48. printf "Mounting efi filesystem... "
  49. if [ -d "$GRUB_DIR/boot/efi" ]; then
  50. umount -q $GRUB_DIR/boot/efi || true
  51. rm -fr $GRUB_DIR/boot/efi
  52. fi
  53. mkdir -p $GRUB_DIR/boot/efi
  54. mount $EFI_UUID $GRUB_DIR/boot/efi
  55. printf "(OK)\n"
  56. echo "Run GRUB installation tasks..."
  57. pushd $TARGET/ansible > /dev/null
  58. export ANSIBLE_ROOTFS_DIR=$GRUB_DIR
  59. ansible-playbook -v 03_grub.yaml
  60. echo "Run GRUB installation tasks... (OK)"
  61. printf "Installing fstab... "
  62. echo "$ROOT_UUID / ext4 errors=remount-ro 0 1" > $GRUB_DIR/etc/fstab
  63. echo "$EFI_UUID /boot/efi vfat defaults 0 1" >> $GRUB_DIR/etc/fstab
  64. printf "(OK)\n"
  65. printf "Umounting everything... "
  66. umount -q $GRUB_DIR/boot/efi
  67. umount -q $GRUB_DIR
  68. printf "(OK)\n"
  69. echo "Checking filesystem..."
  70. fsck -y ${LOOP_DEV}p2
  71. echo "Checking filesystem... (OK)"
  72. echo "Detaching loop device..."
  73. losetup -d $LOOP_DEV
  74. echo "Detaching loop device... (OK)"
  75. printf "Moving export image file... "
  76. mv $GRUB_IMG "${EXPORT_DIR}/${PISDR_IMG_NAME}-${IMAGE_NAME}-amd64.img" > /dev/null
  77. printf "(OK)\n"