Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 2f6a3d53466ca4d733ff527aa07ee25b > scriptlet

grub2-2.00-59.mga4.x86_64.rpm

PREUN

/bin/sh
exec > /var/log/grub2_preun.log 2>&1
# Only if uninstalling
if [ $1 -eq 0 ]; then
rm -rf /boot/grub2/i386-pc
rm -rf /boot/grub2/locale
fi

POSTIN

/bin/sh
rm -f /var/log/grub2_post.log

# Generate grub.cfg only on install
if [ $1 -eq 1 ]; then
    grub2-mkconfig -o /boot/grub2/grub.cfg
# Generate core.img, and install it to filesystem for multiboot
    grub2-install --directory=/usr/lib/grub/i386-pc --grub-setup=/bin/true $BOOT_PARTITION
fi

# Determine the partition with /boot
BOOT_PARTITION=$(df -h /boot |(read; awk '{print $1; exit}'))
# make it work with live images
if [ "$BOOT_PARTITION" == "overlayfs" ]; then
    BOOT_PARTITION=$(df -h /mnt/install/boot |(read; awk '{print $1; exit}'))
fi

# On update re-install grub2 to where it was installed by drakboot if possible,
# otherwise next boot may fail due to mismatched boot code.

if [ $1 -eq 2 ]; then
# Check for drakboot.conf
  if [ -e /boot/grub2/drakboot.conf ]; then
# Get install device from drakboot.conf
  install_dev=$(cat /boot/grub2/drakboot.conf|grep "boot="|cut -d= -f2)
# Check it's not a partition
    if ! echo $install_dev | grep -q "[0-9]"; then
# Only run grub2-install if target has a grub2 MBR
      if head $install_dev | grep -q "GRUB" && ! head $install_dev | grep -q "stage1.5"; then
	  echo "Installing grub2 to $install_dev" | tee -a /var/log/grub2_post.log
	  grub2-install --target=i386-pc $install_dev	
      else
	  echo "MBR not grub2 so skipping grub2-install" | tee -a /var/log/grub2_post.log
      fi
    else
# Target is a partition so update /boot/grub2/i386-pc/core.img
      echo "Partition specified so updating /boot/grub2/i386-pc/core.img" | tee -a /var/log/grub2_post.log
      grub2-install --directory=/usr/lib/grub/i386-pc --grub-setup=/bin/true $BOOT_PARTITION
    fi
  else
## TODO Possible issue with multiboot systems where Mageia is using grub legacy but has grub2 installed
##  and another OS is providing grub2 in the MBR and chainloading Mageia. If grub2 was installed manually (outside 
## drakboot) then update of grub2 would overwrite MBR, but at least Mageia would boot.

# If grub2 was manually installed (outside drakboot) and no drakboot.conf exists
# then try to determine boot device.
# Get array of devices with grub2 bootloader
  drvarr=($(cat /proc/diskstats| grep -e "^   8"|tr -s ' '|cut -d' ' -f4,6|rev|grep -v "^0 "|rev|cut -d' ' -f1|grep -v "[0-9]"|sort))
  grub2arr=()
    for drv in ${drvarr[@]}; do
      if head /dev/$drv | grep -q "GRUB" && ! head /dev/$drv | grep -q "stage1.5"; then
	grub2arr+=($drv)
      fi
    done
# If there is only one it's *probably* ours so update it
      if [ ${#grub2arr[@]} -eq 1 ]; then
	echo "Installing grub2 to /dev/${grub2arr[0]}" | tee -a /var/log/grub2_post.log
	grub2-install --target=i386-pc /dev/${grub2arr[0]}
	exit 0
# If there is more than one then we can't decide so give up with warning 	
      elif [ ${#grub2arr[@]} -gt 1 ]; then
	echo "More than one grub2 MBR so skipping grub2-install" | tee -a /var/log/grub2_post.log
# If there are none then skip
      elif [ ${#grub2arr[@]} -lt 1 ]; then
	echo "No grub2 MBR so skipping grub2-install" | tee -a /var/log/grub2_post.log
	exit 0
      fi
cat >> /var/log/grub2_post.log<<EOF
************************** WARNING ***************************
Could not install grub2 to a device boot sector as the target was not known.
IF grub2 is your current bootloader installed to a MBR, please ensure that 
grub2-install is run on the correct boot device BEFORE re-booting.
e.g. as root: grub2-install /dev/sdX
To avoid this warning in future please either use MCC -> Boot to set up grub2
or create the file: /boot/grub2/drakboot.conf containing boot=/dev/sdX
where /dev/sdX is the boot device.
EOF
cat /var/log/grub2_post.log
  fi
fi