| #! /bin/bash |
| # support for GRUB version 2 |
| |
| error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code |
| |
| set -a |
| |
| # do not set up grub during dirinstall |
| if [ "$FAI_ACTION" = "dirinstall" ] ; then |
| exit 0 |
| fi |
| # during softupdate use this file |
| [ -r $LOGDIR/disk_var.sh ] && . $LOGDIR/disk_var.sh |
| |
| if [ -z "$BOOT_DEVICE" ]; then |
| exit 189 |
| fi |
| |
| # disable os-prober because of #788062 |
| ainsl /etc/default/grub 'GRUB_DISABLE_OS_PROBER=true' |
| |
| # skip the rest, if not an initial installation |
| if [ $FAI_ACTION != "install" ]; then |
| $ROOTCMD update-grub |
| exit $error |
| fi |
| |
| $ROOTCMD grub-mkdevicemap --no-floppy |
| GROOT=$($ROOTCMD grub-probe -tdrive -d $BOOT_DEVICE) |
| |
| if [[ $GROOT =~ 'hostdisk' ]]; then |
| cat > $target/boot/grub/device.map <<EOF |
| (hd0) $BOOT_DEVICE |
| EOF |
| if ifclass HIKEY; then |
| # Standard grub-install for SD card |
| $ROOTCMD grub-install --removable --no-nvram $BOOT_DEVICE |
| if [ $? -eq 0 ]; then |
| echo "Hikey grub for SD card installed" |
| fi |
| # Custom grub for emmc and lava |
| cat << EOF > $target/boot/grub/emmc.config |
| search.fs_label rootfs root |
| set prefix=(\$root)'/boot/grub' |
| configfile \$prefix/grub.cfg |
| EOF |
| GRUB_MODULES="boot chain configfile echo efinet eval ext2 fat font gettext gfxterm gzio help linux loadenv lsefi normal part_gpt part_msdos read regexp search search_fs_file search_fs_uuid search_label terminal terminfo test tftp time" |
| |
| $ROOTCMD grub-mkimage --prefix='($root)/boot/grub' \ |
| --config=/boot/grub/emmc.config --output=/boot/efi/EFI/BOOT/GRUBAA64.EFI \ |
| --format=arm64-efi --compression=auto $GRUB_MODULES |
| echo "Standalone Hikey grub for eMMC and LAVA installed" |
| fi |
| rm $target/boot/grub/device.map |
| |
| else |
| $ROOTCMD grub-install --no-floppy "$GROOT" |
| if [ $? -eq 0 ]; then |
| echo "Grub installed on $BOOT_DEVICE = $GROOT" |
| fi |
| fi |
| |
| # In case run in docker, dev/disk/by-uuid/ is out of date since udev runs outside docker |
| |
| mkdir -p $target/dev/disk/by-uuid/ |
| for dev in `blkid -o device | grep -v block` |
| do |
| ln -sf "$dev" "$target/dev/disk/by-uuid/$(blkid -o value -s UUID "$dev")" |
| done |
| |
| $ROOTCMD update-grub |
| |
| exit $error |