#!/bin/sh set -e grub_install="/usr/sbin/grub2-install" grub_probe="/usr/sbin/grub2-probe" grub_script_check="/usr/bin/grub2-script-check" btrfs_util="/sbin/btrfs" # Get GRUB_DISTRIBUTOR. if test -f "/etc/default/grub" ; then . "/etc/default/grub" fi root_fstype=`$grub_probe -t fs /` boot_fstype=`$grub_probe -t fs /boot` if [ "x$SUSE_BTRFS_SNAPSHOT_BOOTING" != "xtrue" ] || [ "x${root_fstype}" != "xbtrfs" ] || [ "x${boot_fstype}" != "xbtrfs" ] ; then echo "requirement not met" >&2 exit 1; fi make_grubcfg () { prefix="$1" descriptive_config="snapshot_submenu.cfg" if [ "x${platform}" = "xpc" ]; then cat </dev/null || true if [ -d /sys/firmware/efi ]; then target="x86_64-efi" else target=i386-pc fi ;; x"i"?"86"*) modprobe -q efivars 2>/dev/null || true if [ -d /sys/firmware/efi ]; then target="i386-efi" elif [ -e /proc/device-tree ]; then target=i386-pc for x in /proc/device-tree/*; do if [ -e "$x" ]; then target="i386-ieee1275" fi done else target=i386-pc fi ;; *) target="" ;; esac if [ "x${target}" = "xi386-pc" ]; then platform="pc" elif [ "x${target}" = "xx86_64-efi" ] || [ "x${target}" = "xi386-efi" ]; then platform="efi" else exit 0 fi if [ "x${platform}" = "xefi" ]; then bootloader_id="$(echo "$GRUB_DISTRIBUTOR" | tr 'A-Z' 'a-z' | cut -d' ' -f1)" if test -z "$bootloader_id"; then bootloader_id=grub fi boot_directory="/boot/efi/EFI/${bootloader_id}" if echo "$@" | grep -q '--boot-directory='; then ${grub_install} $@ else ${grub_install} --boot-directory="${boot_directory}" --efi-directory="/boot/efi" $@ make_grubcfg "/EFI/${bootloader_id}/grub2" >"${boot_directory}/grub2/grub.cfg.new" fi elif [ "x${platform}" = "xpc" ]; then boot_directory="/.boot" if [ ! -d "$boot_directory" ]; then ${btrfs_util} subvolume create "$boot_directory" echo "UUID=`$grub_probe -t fs_uuid /` /.boot btrfs subvol=@/.boot 0 0" >>/etc/fstab fi if echo "$@" | grep -q '--boot-directory='; then ${grub_install} $@ else ${grub_install} --boot-directory="${boot_directory}" $@ make_grubcfg "${boot_directory}/grub2" >"${boot_directory}/grub2/grub.cfg.new" fi fi if $grub_script_check "${boot_directory}/grub2/grub.cfg.new"; then mv -f "${boot_directory}/grub2/grub.cfg.new" "${boot_directory}/grub2/grub.cfg" fi