forked from pool/grub2
- snapper rollback support (fate#317062) * add btrfs_follow_default.patch * add suse_btrfs_grub2_install.sh * add 80_suse_btrfs_snapshot * refresh grub2-snapper-plugin.sh - add grub2-x86_64-xen subpackage (bnc#863821) - ieee1275: check for IBM pseries emulated machine (bnc#869964) - added patches: * grub2-ppc64-build-ppc64-32bit.patch - Build ppc64 as 32bit - added patches: * grub2-ppc64-build-ppc64-32bit.patch - Rename PowerPC patches so it will have architecture in it's name - added patches: * grub2-ppc64le-01-Add-Little-Endian-support-for-Power64-to-the-build.patch * grub2-ppc64le-02-Build-grub-as-O1-until-we-add-savegpr-and-restgpr-ro.patch * grub2-ppc64le-03-disable-creation-of-vsx-and-altivec-instructions.patch * grub2-ppc64le-04-powerpc64-LE-s-linker-knows-how-to-handle-the-undefi.patch * grub2-ppc64le-05-grub-install-can-now-recognize-and-install-a-LE-grub.patch * grub2-ppc64le-06-set-the-ABI-version-to-0x02-in-the-e_flag-of-the-PPC.patch * grub2-ppc64le-07-Add-IEEE1275_ADDR-helper.patch * grub2-ppc64le-08-Fix-some-more-warnings-when-casting.patch * grub2-ppc64le-09-Add-powerpc64-types.patch * grub2-ppc64le-10-powerpc64-is-not-necessarily-BigEndian-anymore.patch * grub2-ppc64le-11-Fix-warnings-when-building-powerpc-linux-loader-64bi.patch * grub2-ppc64le-12-GRUB_ELF_R_PPC_-processing-is-applicable-only-for-32.patch OBS-URL: https://build.opensuse.org/request/show/228323 OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=81
216 lines
4.4 KiB
Bash
216 lines
4.4 KiB
Bash
#!/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 <<EOF
|
|
insmod part_gpt
|
|
insmod part_msdos
|
|
insmod acpi
|
|
insmod btrfs
|
|
insmod multiboot
|
|
insmod configfile
|
|
insmod linux
|
|
insmod search
|
|
insmod search_fs_uuid
|
|
insmod search_fs_file
|
|
insmod search_label
|
|
insmod chain
|
|
insmod sleep
|
|
insmod test
|
|
insmod echo
|
|
insmod all_video
|
|
insmod regexp
|
|
insmod font
|
|
insmod terminal
|
|
insmod terminfo
|
|
insmod sleep
|
|
insmod ls
|
|
insmod minicmd
|
|
insmod png
|
|
insmod gzio
|
|
insmod boot
|
|
insmod read
|
|
insmod cat
|
|
insmod vbe
|
|
insmod vga
|
|
insmod video_bochs
|
|
insmod video_cirrus
|
|
insmod gettext
|
|
insmod true
|
|
insmod reboot
|
|
insmod password
|
|
insmod password_pbkdf2
|
|
insmod loadenv
|
|
insmod legacycfg
|
|
insmod jpeg
|
|
insmod gfxmenu
|
|
insmod gfxterm_background
|
|
insmod gfxterm_menu
|
|
insmod gfxterm
|
|
EOF
|
|
fi
|
|
|
|
cat <<EOF
|
|
|
|
set btrfs_relative_path="y"
|
|
set extra_cmdline=""
|
|
btrfs_subvolid=""
|
|
btrfs_subvol="/"
|
|
|
|
export btrfs_relative_path
|
|
export extra_cmdline
|
|
EOF
|
|
|
|
if [ "x${platform}" = "xpc" ]; then
|
|
cat <<EOF
|
|
|
|
set prefix="(\$root)${prefix}"
|
|
EOF
|
|
elif [ "x${platform}" = "xefi" ]; then
|
|
cat <<EOF
|
|
|
|
set prefix="(\$root)${prefix}"
|
|
search --fs-uuid --set=root `"$grub_probe" --target=fs_uuid /boot/grub2`
|
|
EOF
|
|
fi
|
|
|
|
cat <<EOF
|
|
|
|
terminal_input console
|
|
terminal_output console
|
|
|
|
set timeout=0
|
|
|
|
menuentry 'default' {
|
|
btrfs_subvol=""
|
|
configfile /boot/grub2/grub.cfg
|
|
btrfs_subvol="/"
|
|
}
|
|
|
|
if [ -f "/.snapshots/${descriptive_config}" ]; then
|
|
source "/.snapshots/${descriptive_config}"
|
|
else
|
|
submenu 'Available Snapshots' {
|
|
for i in /.snapshots/*; do
|
|
if [ -f "\$i/${descriptive_config}" ]; then
|
|
source "\$i/${descriptive_config}"
|
|
elif [ -f "\$i/snapshot/boot/grub2/grub.cfg" ]; then
|
|
menuentry "\$i" "/.snapshots\$i/snapshot" {
|
|
btrfs_subvol="\$2"
|
|
extra_cmdline="rootflags=subvol=\$2"
|
|
configfile /boot/grub2/grub.cfg
|
|
btrfs_subvol="/"
|
|
}
|
|
fi
|
|
done
|
|
}
|
|
fi
|
|
EOF
|
|
|
|
}
|
|
|
|
case x"`uname -m`" in
|
|
x"powerpc"* | x"ppc"*)
|
|
target="powerpc-ieee1275";;
|
|
x"sparc"*)
|
|
target="sparc64-ieee1275";;
|
|
x"mips"*"el")
|
|
target="mipsel-loongson";;
|
|
x"mips"*)
|
|
target="mips-arc";;
|
|
x"ia64"*)
|
|
target="ia64-efi";;
|
|
x"x86_64"* | x"amd64"*)
|
|
modprobe -q efivars 2>/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
|
|
|