You are not logged in.

#1 2020-02-08 15:34:21

steppeno
Member
Registered: 2020-02-08
Posts: 5

PKGBUILD request: grub2 with openSUSE btrfs patches.

Hi, i'm trying to set-up my perfect arch installation. What i want to replicate is the openSUSE btrfs snapshot function. I follow the arch wiki for snapper, installed snap-pac (pacman hook that's made pre and post snapshot), grub-btrfs so i can boot in every snapshots.... but when i try to do a snapper rollback, nothings happens. After a day on google "labyrinth" i found a lot of information on the nature of the problem.  When u do "sudo snapper rollback" from a booted snapshot, snapper create a new r/w snapshot of the current one and then set the new snapshot as default (btrfs subvolume set-default) but GRUB doesn't follow the btrfs subvol default variable. The problem starts here: http://git.savannah.gnu.org/cgit/grub.g … dfe0641974  (i think), so what i want is to make a grub2 package with openSUSE btrfs patches taken from openSUSE grub2-2.04-3.2.src.rpm:

grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
grub2-btrfs-02-export-subvolume-envvars.patch
grub2-btrfs-03-follow_default.patch
grub2-btrfs-04-grub2-install.patch
grub2-btrfs-05-grub2-mkconfig.patch

I started with the official arch Grub PKGBUILD https://git.archlinux.org/svntogit/pack … kages/grub, added the patches:

# Maintainer : Christian Hesse <mail@eworm.de>
# Maintainer : Ronald van Haren <ronald.archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Keshav Amburay <(the ddoott ridikulus ddoott rat) (aatt) (gemmaeiil) (ddoott) (ccoomm)>

## "1" to enable IA32-EFI build in Arch x86_64, "0" to disable
_IA32_EFI_IN_ARCH_X64="1"

## "1" to enable EMU build, "0" to disable
_GRUB_EMU_BUILD="0"

_GRUB_EXTRAS_COMMIT="8a245d5c1800627af4cefa99162a89c7a46d8842"
_GNULIB_COMMIT="be584c56eb1311606e5ea1a36363b97bddb6eed3"
_UNIFONT_VER="12.1.03"

[[ "${CARCH}" == "x86_64" ]] && _EFI_ARCH="x86_64"
[[ "${CARCH}" == "i686" ]] && _EFI_ARCH="i386"

[[ "${CARCH}" == "x86_64" ]] && _EMU_ARCH="x86_64"
[[ "${CARCH}" == "i686" ]] && _EMU_ARCH="i386"

pkgname='grub'
pkgdesc='GNU GRand Unified Bootloader (2)'
_pkgver=2.04
pkgver=${_pkgver/-/}
pkgrel=5
epoch=2
url='https://www.gnu.org/software/grub/'
arch=('x86_64')
license=('GPL3')
backup=('etc/default/grub'
        'etc/grub.d/40_custom')
install="${pkgname}.install"
options=('!makeflags')

conflicts=('grub-common' 'grub-bios' 'grub-emu' "grub-efi-${_EFI_ARCH}" 'grub-legacy')
replaces=('grub-common' 'grub-bios' 'grub-emu' "grub-efi-${_EFI_ARCH}")
provides=('grub-common' 'grub-bios' 'grub-emu' "grub-efi-${_EFI_ARCH}")

makedepends=('git' 'rsync' 'xz' 'freetype2' 'ttf-dejavu' 'python' 'autogen'
             'texinfo' 'help2man' 'gettext' 'device-mapper' 'fuse2')
depends=('sh' 'xz' 'gettext' 'device-mapper')
optdepends=('freetype2: For grub-mkfont usage'
            'fuse2: For grub-mount usage'
            'dosfstools: For grub-mkrescue FAT FS and EFI support'
            'efibootmgr: For grub-install EFI support'
            'libisoburn: Provides xorriso for generating grub rescue iso using grub-mkrescue'
            'os-prober: To detect other OSes when generating grub.cfg in BIOS systems'
            'mtools: For grub-mkrescue FAT FS support')

if [[ "${_GRUB_EMU_BUILD}" == "1" ]]; then
    makedepends+=('libusbx' 'sdl')
    optdepends+=('libusbx: For grub-emu USB support'
                 'sdl: For grub-emu SDL support')
fi

validpgpkeys=('E53D497F3FA42AD8C9B4D1E835A93B74E82E4209'  # Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
              'BE5C23209ACDDACEB20DB0A28C8189F1988C2166'  # Daniel Kiper <dkiper@net-space.pl>
              '95D2E9AB8740D8046387FD151A09227B1F435A33') # Paul Hardy <unifoundry@unifoundry.com>
            
source=("git+https://git.savannah.gnu.org/git/grub.git#tag=grub-${_pkgver}?signed"
        "git+https://git.savannah.gnu.org/git/grub-extras.git#commit=${_GRUB_EXTRAS_COMMIT}"
        "git+https://git.savannah.gnu.org/git/gnulib.git#commit=${_GNULIB_COMMIT}"
        "https://ftp.gnu.org/gnu/unifont/unifont-${_UNIFONT_VER}/unifont-${_UNIFONT_VER}.bdf.gz"{,.sig}
        '0003-10_linux-detect-archlinux-initramfs.patch'
        '0004-add-GRUB_COLOR_variables.patch'
        'grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch'
        'grub2-btrfs-02-export-subvolume-envvars.patch'
        'grub2-btrfs-03-follow_default.patch'
        'grub2-btrfs-04-grub2-install.patch'
        'grub2-btrfs-05-grub2-mkconfig.patch'
        'grub.default')

sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP')
_backports=(
	# grub-mkconfig: Use portable "command -v" to detect installed programs
	'28a7e597de0d5584f65e36f9588ff9041936e617'
)

_configure_options=(
	FREETYPE="pkg-config freetype2"
	BUILD_FREETYPE="pkg-config freetype2"
	--enable-mm-debug
	--enable-nls
	--enable-device-mapper
	--enable-cache-stats
	--enable-grub-mkfont
	--enable-grub-mount
	--prefix="/usr"
	--bindir="/usr/bin"
	--sbindir="/usr/bin"
	--mandir="/usr/share/man"
	--infodir="/usr/share/info"
	--datarootdir="/usr/share"
	--sysconfdir="/etc"
	--program-prefix=""
	--with-bootdir="/boot"
	--with-grubdir="grub"
	--disable-silent-rules
	--disable-werror
)

prepare() {
	cd "${srcdir}/grub/"

	echo "Apply backports..."
	local _c
	for _c in "${_backports[@]}"; do
		git log --oneline -1 "${_c}"
		git cherry-pick -n "${_c}"
	done

	echo "Patch to detect of Arch Linux initramfs images by grub-mkconfig..."
	patch -Np1 -i "${srcdir}/0003-10_linux-detect-archlinux-initramfs.patch"

	echo "Patch to enable GRUB_COLOR_* variables in grub-mkconfig..."
	## Based on http://lists.gnu.org/archive/html/grub-devel/2012-02/msg00021.html
	patch -Np1 -i "${srcdir}/0004-add-GRUB_COLOR_variables.patch"

	
	echo "grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch..."
	patch -Np1 -i "${srcdir}/grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch"
	
	echo "grub2-btrfs-02-export-subvolume-envvars.patch..."
	patch -Np1 -i "${srcdir}/grub2-btrfs-02-export-subvolume-envvars.patch"
	
	echo "grub2-btrfs-03-follow_default.patch..."
	patch -Np1 -i "${srcdir}/grub2-btrfs-03-follow_default.patch"
	
	echo "grub2-btrfs-04-grub2-install.patch..."
	patch -Np1 -i "${srcdir}/grub2-btrfs-04-grub2-install.patch"
	
	echo "grub2-btrfs-05-grub2-mkconfig.patch..."
	patch -Np1 -i "${srcdir}/grub2-btrfs-05-grub2-mkconfig.patch"
	
	
	
	
	
	echo "Fix DejaVuSans.ttf location so that grub-mkfont can create *.pf2 files for starfield theme..."
	sed 's|/usr/share/fonts/dejavu|/usr/share/fonts/dejavu /usr/share/fonts/TTF|g' -i "configure.ac"

	echo "Fix mkinitcpio 'rw' FS#36275..."
	sed 's| ro | rw |g' -i "util/grub.d/10_linux.in"

	echo "Fix OS naming FS#33393..."
	sed 's|GNU/Linux|Linux|' -i "util/grub.d/10_linux.in"

	echo "Pull in latest language files..."
	./linguas.sh

	echo "Avoid problem with unifont during compile of grub..."
	# http://savannah.gnu.org/bugs/?40330 and https://bugs.archlinux.org/task/37847
	gzip -cd "${srcdir}/unifont-${_UNIFONT_VER}.bdf.gz" > "unifont.bdf"

	echo "Run bootstrap..."
	./bootstrap \
		--gnulib-srcdir="${srcdir}/gnulib/" \
		--no-git

	echo "Make translations reproducible..."
	sed -i '1i /^PO-Revision-Date:/ d' po/*.sed
}

_build_grub-common_and_bios() {
	echo "Set ARCH dependent variables for bios build..."
	if [[ "${CARCH}" == 'x86_64' ]]; then
		_EFIEMU="--enable-efiemu"
	else
		_EFIEMU="--disable-efiemu"
	fi

	echo "Copy the source for building the bios part..."
	cp -r "${srcdir}/grub/" "${srcdir}/grub-bios/"
	cd "${srcdir}/grub-bios/"

	echo "Add the grub-extra sources for bios build..."
	install -d "${srcdir}/grub-bios/grub-extras"
	cp -r "${srcdir}/grub-extras/915resolution" \
		"${srcdir}/grub-bios/grub-extras/915resolution"
	export GRUB_CONTRIB="${srcdir}/grub-bios/grub-extras/"

	echo "Unset all compiler FLAGS for bios build..."
	unset CFLAGS
	unset CPPFLAGS
	unset CXXFLAGS
	unset LDFLAGS
	unset MAKEFLAGS

	echo "Run ./configure for bios build..."
	./configure \
		--with-platform="pc" \
		--target="i386" \
		"${_EFIEMU}" \
		--enable-boot-time \
		"${_configure_options[@]}"

	if [ ! -z "${SOURCE_DATE_EPOCH}" ]; then
		echo "Make info pages reproducible..."
		touch -d "@${SOURCE_DATE_EPOCH}" $(find -name '*.texi')
	fi

	echo "Run make for bios build..."
	make
}

_build_grub-efi() {
	echo "Copy the source for building the ${_EFI_ARCH} efi part..."
	cp -r "${srcdir}/grub/" "${srcdir}/grub-efi-${_EFI_ARCH}/"
	cd "${srcdir}/grub-efi-${_EFI_ARCH}/"

	echo "Unset all compiler FLAGS for ${_EFI_ARCH} efi build..."
	unset CFLAGS
	unset CPPFLAGS
	unset CXXFLAGS
	unset LDFLAGS
	unset MAKEFLAGS

	echo "Run ./configure for ${_EFI_ARCH} efi build..."
	./configure \
		--with-platform="efi" \
		--target="${_EFI_ARCH}" \
		--disable-efiemu \
		--enable-boot-time \
		"${_configure_options[@]}"

	echo "Run make for ${_EFI_ARCH} efi build..."
	make
}

_build_grub-emu() {
	echo "Copy the source for building the emu part..."
	cp -r "${srcdir}/grub/" "${srcdir}/grub-emu/"
	cd "${srcdir}/grub-emu/"

	echo "Unset all compiler FLAGS for emu build..."
	unset CFLAGS
	unset CPPFLAGS
	unset CXXFLAGS
	unset LDFLAGS
	unset MAKEFLAGS

	echo "Run ./configure for emu build..."
	./configure \
		--with-platform="emu" \
		--target="${_EMU_ARCH}" \
		--enable-grub-emu-usb=no \
		--enable-grub-emu-sdl=no \
		--disable-grub-emu-pci \
		"${_configure_options[@]}"

	echo "Run make for emu build..."
	make
}

build() {
	cd "${srcdir}/grub/"

	echo "Build grub bios stuff..."
	_build_grub-common_and_bios

	echo "Build grub ${_EFI_ARCH} efi stuff..."
	_build_grub-efi

	if [[ "${CARCH}" == "x86_64" ]] && [[ "${_IA32_EFI_IN_ARCH_X64}" == "1" ]]; then
		echo "Build grub i386 efi stuff..."
		_EFI_ARCH="i386" _build_grub-efi
	fi

	if [[ "${_GRUB_EMU_BUILD}" == "1" ]]; then
		echo "Build grub emu stuff..."
		_build_grub-emu
	fi
}

_package_grub-common_and_bios() {
	cd "${srcdir}/grub-bios/"

	echo "Run make install for bios build..."
	make DESTDIR="${pkgdir}/" bashcompletiondir="/usr/share/bash-completion/completions" install

	echo "Remove gdb debugging related files for bios build..."
	rm -f "${pkgdir}/usr/lib/grub/i386-pc"/*.module || true
	rm -f "${pkgdir}/usr/lib/grub/i386-pc"/*.image || true
	rm -f "${pkgdir}/usr/lib/grub/i386-pc"/{kernel.exec,gdb_grub,gmodule.pl} || true

	echo "Install /etc/default/grub (used by grub-mkconfig)..."
	install -D -m0644 "${srcdir}/grub.default" "${pkgdir}/etc/default/grub"
}

_package_grub-efi() {
	cd "${srcdir}/grub-efi-${_EFI_ARCH}/"

	echo "Run make install for ${_EFI_ARCH} efi build..."
	make DESTDIR="${pkgdir}/" bashcompletiondir="/usr/share/bash-completion/completions" install

	echo "Remove gdb debugging related files for ${_EFI_ARCH} efi build..."
	rm -f "${pkgdir}/usr/lib/grub/${_EFI_ARCH}-efi"/*.module || true
	rm -f "${pkgdir}/usr/lib/grub/${_EFI_ARCH}-efi"/*.image || true
	rm -f "${pkgdir}/usr/lib/grub/${_EFI_ARCH}-efi"/{kernel.exec,gdb_grub,gmodule.pl} || true
}

_package_grub-emu() {
	cd "${srcdir}/grub-emu/"

	echo "Run make install for emu build..."
	make DESTDIR="${pkgdir}/" bashcompletiondir="/usr/share/bash-completion/completions" install

	echo "Remove gdb debugging related files for emu build..."
	rm -f "${pkgdir}/usr/lib/grub/${_EMU_ARCH}-emu"/*.module || true
	rm -f "${pkgdir}/usr/lib/grub/${_EMU_ARCH}-emu"/*.image || true
	rm -f "${pkgdir}/usr/lib/grub/${_EMU_ARCH}-emu"/{kernel.exec,gdb_grub,gmodule.pl} || true
}

package() {
	cd "${srcdir}/grub/"

	echo "Package grub ${_EFI_ARCH} efi stuff..."
	_package_grub-efi

	if [[ "${CARCH}" == "x86_64" ]] && [[ "${_IA32_EFI_IN_ARCH_X64}" == "1" ]]; then
		echo "Package grub i386 efi stuff..."
		_EFI_ARCH="i386" _package_grub-efi
	fi

	if [[ "${_GRUB_EMU_BUILD}" == "1" ]]; then
		echo "Package grub emu stuff..."
		_package_grub-emu
	fi

	echo "Package grub bios stuff..."
	_package_grub-common_and_bios
}

but i have this error and i don't know what to do sad

 
==> Making package: grub 2:2.04-5 (Sat Feb  8 16:53:29 2020)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating grub git repo...
Fetching origin
  -> Updating grub-extras git repo...
Fetching origin
  -> Updating gnulib git repo...
Fetching origin
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 18 (delta 16), reused 0 (delta 0)
Unpacking objects: 100% (18/18), 2.21 KiB | 10.00 KiB/s, done.
From https://git.savannah.gnu.org/git/gnulib
   4d4a22ab1..3be55f263  master     -> master
  -> Found unifont-12.1.03.bdf.gz
  -> Found unifont-12.1.03.bdf.gz.sig
  -> Found 0003-10_linux-detect-archlinux-initramfs.patch
  -> Found 0004-add-GRUB_COLOR_variables.patch
  -> Found grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
  -> Found grub2-btrfs-02-export-subvolume-envvars.patch
  -> Found grub2-btrfs-03-follow_default.patch
  -> Found grub2-btrfs-04-grub2-install.patch
  -> Found grub2-btrfs-05-grub2-mkconfig.patch
  -> Found grub.default
==> Validating source files with sha256sums...
    grub ... Skipped
    grub-extras ... Skipped
    gnulib ... Skipped
    unifont-12.1.03.bdf.gz ... Skipped
    unifont-12.1.03.bdf.gz.sig ... Skipped
    0003-10_linux-detect-archlinux-initramfs.patch ... Skipped
    0004-add-GRUB_COLOR_variables.patch ... Skipped
    grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch ... Skipped
    grub2-btrfs-02-export-subvolume-envvars.patch ... Skipped
    grub2-btrfs-03-follow_default.patch ... Skipped
    grub2-btrfs-04-grub2-install.patch ... Skipped
    grub2-btrfs-05-grub2-mkconfig.patch ... Skipped
    grub.default ... Skipped
==> Verifying source file signatures with gpg...
    grub git repo ... Passed
    unifont-12.1.03.bdf.gz ... Passed
==> Extracting sources...
  -> Creating working copy of grub git repo...
Reset branch 'makepkg'
  -> Creating working copy of grub-extras git repo...
Reset branch 'makepkg'
  -> Creating working copy of gnulib git repo...
From /home/stefano/Scaricati/Grub2/gnulib
   4d4a22ab1..3be55f263  master     -> origin/master
Reset branch 'makepkg'
  -> Extracting unifont-12.1.03.bdf.gz with gzip
==> Starting prepare()...
Apply backports...
Auto-merging util/grub.d/30_os-prober.in
Auto-merging util/grub-mkconfig_lib.in
Patch to detect of Arch Linux initramfs images by grub-mkconfig...
patching file util/grub.d/10_linux.in
Hunk #1 succeeded at 93 (offset 10 lines).
Hunk #2 succeeded at 200 (offset 12 lines).
Hunk #3 succeeded at 279 (offset 29 lines).
Patch to enable GRUB_COLOR_* variables in grub-mkconfig...
patching file util/grub-mkconfig.in
Hunk #1 succeeded at 233 (offset 15 lines).
patching file util/grub.d/00_header.in
grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch...
patching file grub-core/fs/btrfs.c
patching file include/grub/btrfs.h
grub2-btrfs-02-export-subvolume-envvars.patch...
patching file grub-core/fs/btrfs.c
Hunk #1 succeeded at 2694 (offset 442 lines).
grub2-btrfs-03-follow_default.patch...
patching file grub-core/fs/btrfs.c
Hunk #1 succeeded at 1236 (offset 323 lines).
Hunk #2 succeeded at 1267 (offset 323 lines).
Hunk #3 succeeded at 1839 (offset 428 lines).
Hunk #4 succeeded at 1882 (offset 428 lines).
Hunk #5 succeeded at 1909 (offset 428 lines).
Hunk #6 succeeded at 1942 (offset 428 lines).
Hunk #7 succeeded at 2013 (offset 428 lines).
Hunk #8 succeeded at 2065 (offset 428 lines).
Hunk #9 succeeded at 2740 (offset 428 lines).
grub2-btrfs-04-grub2-install.patch...
patching file grub-core/osdep/unix/config.c
Hunk #1 succeeded at 82 (offset -137 lines).
Hunk #2 succeeded at 118 (offset -137 lines).
patching file include/grub/emu/config.h
patching file util/config.c
patching file util/grub-install.c
Hunk #1 succeeded at 819 (offset -9 lines).
Hunk #2 succeeded at 854 (offset -9 lines).
Hunk #3 succeeded at 1349 (offset -3 lines).
patching file grub-core/osdep/linux/getroot.c
patching file util/grub-mkrelpath.c
grub2-btrfs-05-grub2-mkconfig.patch...
patching file util/grub-mkconfig_lib.in
patching file util/grub.d/00_header.in
Hunk #2 succeeded at 51 with fuzz 1.
Hunk #3 succeeded at 372 (offset -5 lines).
patching file util/grub-mkconfig.in
Hunk #1 FAILED at 262.
1 out of 1 hunk FAILED -- saving rejects to file util/grub-mkconfig.in.rej
patching file util/grub.d/10_linux.in
Hunk #1 succeeded at 65 (offset 8 lines).
Hunk #2 FAILED at 240.
1 out of 2 hunks FAILED -- saving rejects to file util/grub.d/10_linux.in.rej
patching file util/grub.d/20_linux_xen.in
Hunk #1 succeeded at 73 (offset 2 lines).
==> ERROR: A failure occurred in prepare().
    Aborting...

P.S. Sorry for my bad, bad english!

Last edited by steppeno (2020-02-08 15:54:29)

Offline

#2 2020-02-08 15:49:30

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,680
Website

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

The grub2-btrfs-05-grub2-mkconfig.patch is failing, presumably because the util/grub-mkconfig.in & util/grub.d/10_linux.in files have already been altered by Arch's own patches.

You will have to modify the patch to take account of this, the error messages tell you on which lines the patch is failing.

And for the record please prepend the problematic command (makepkg in this case) with LC_ALL=C to make it speak English.

Offline

#3 2020-02-09 12:25:34

steppeno
Member
Registered: 2020-02-08
Posts: 5

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

Thanks for the quick replay, these are the rejected code:

grub-mkconfig.in.rej

--- util/grub-mkconfig.in
+++ util/grub-mkconfig.in
@@ -262,7 +262,8 @@ export GRUB_DEFAULT \
   GRUB_OS_PROBER_SKIP_LIST \
   GRUB_DISABLE_SUBMENU \
   GRUB_CMDLINE_LINUX_RECOVERY \
-  GRUB_USE_LINUXEFI
+  GRUB_USE_LINUXEFI \
+  SUSE_BTRFS_SNAPSHOT_BOOTING

if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"

And 10_linux.in.rej:

--- util/grub.d/10_linux.in
+++ util/grub.d/10_linux.in
@@ -240,7 +244,12 @@ while [ "x$list" != "x" ] ; do
   if [ $PLATFORM != "emu" ]; then
     hotkey=0
   else
-    rel_dirname=$dirname
+    if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+       [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+       rel_dirname="\${btrfs_subvol}$dirname"
+    else
+       rel_dirname="$dirname"
+    fi
   fi
   version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`

But I'm only a linux user, i don't know how to read these.
Any helps are welcome!!!!
Thanks

P.s. Can be an help?
https://dustymabe.com/2015/07/14/fedora … eparation/
https://github.com/dustymabe/fedora-gru … r/fedora25

Last edited by steppeno (2020-02-09 12:45:43)

Offline

#4 2020-02-09 18:09:29

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,680
Website

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

steppeno wrote:

But I'm only a linux user, i don't know how to read these.

https://unix.stackexchange.com/question … iff-output

The patch fails at lines 262 (for grub-mkconfig.in) & 240 (for 10_linux.in) because the instructions in the patch don't align with the contents of the files. So you need to examine the relevant contents of the patch and the files and make any required changes yourself then produce a new patch from the modified files either by using the diff(1) command or just editing the patch directly so that it "fits".

If you want more help then post the actual grub2-btrfs-05-grub2-mkconfig.patch file and I might take a look if I'm bored enough. Or perhaps somebody else will.

Offline

#5 2020-02-09 18:31:42

steppeno
Member
Registered: 2020-02-08
Posts: 5

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

grub2-btrfs-05-grub2-mkconfig.patch:

 
---
 util/grub-mkconfig.in       |    3 ++-
 util/grub-mkconfig_lib.in   |    4 ++++
 util/grub.d/00_header.in    |   23 ++++++++++++++++++++++-
 util/grub.d/10_linux.in     |   11 ++++++++++-
 util/grub.d/20_linux_xen.in |    4 ++++
 5 files changed, 42 insertions(+), 3 deletions(-)

Index: grub-2.02~beta2/util/grub-mkconfig_lib.in
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig_lib.in
+++ grub-2.02~beta2/util/grub-mkconfig_lib.in
@@ -49,7 +49,11 @@ grub_warn ()
 
 make_system_path_relative_to_its_root ()
 {
+  if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
+  "${grub_mkrelpath}" -r "$1"
+  else
   "${grub_mkrelpath}" "$1"
+  fi
 }
 
 is_path_readable_by_grub ()
Index: grub-2.02~beta2/util/grub.d/00_header.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/00_header.in
+++ grub-2.02~beta2/util/grub.d/00_header.in
@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+    cat <<EOF
+set btrfs_relative_path="y"
+export btrfs_relative_path
+EOF
+fi
+
 # Do this as early as possible, since other commands might depend on it.
 # (e.g. the `loadfont' command might need lvm or raid modules)
 for i in ${GRUB_PRELOAD_MODULES} ; do
@@ -43,7 +51,9 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved
 if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
 
 cat << EOF
-if [ -s \$prefix/grubenv ]; then
+if [ -f \${config_directory}/grubenv ]; then
+  load_env -f \${config_directory}/grubenv
+elif [ -s \$prefix/grubenv ]; then
   load_env
 fi
 
@@ -367,3 +377,15 @@ fi
 if [ "x${GRUB_BADRAM}" != "x" ] ; then
   echo "badram ${GRUB_BADRAM}"
 fi
+
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+    # Note: No $snapshot_num on *read-only* rollback!  (bsc#901487)
+    cat <<EOF
+if [ -n "\$extra_cmdline" ]; then
+  submenu "Bootable snapshot #\$snapshot_num" {
+    menuentry "If OK, run 'snapper rollback' and reboot." { true; }
+  }
+fi
+EOF
+fi
Index: grub-2.02~beta2/util/grub-mkconfig.in
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig.in
+++ grub-2.02~beta2/util/grub-mkconfig.in
@@ -262,7 +262,8 @@ export GRUB_DEFAULT \
   GRUB_OS_PROBER_SKIP_LIST \
   GRUB_DISABLE_SUBMENU \
   GRUB_CMDLINE_LINUX_RECOVERY \
-  GRUB_USE_LINUXEFI
+  GRUB_USE_LINUXEFI \
+  SUSE_BTRFS_SNAPSHOT_BOOTING
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"
Index: grub-2.02~beta2/util/grub.d/10_linux.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/10_linux.in
+++ grub-2.02~beta2/util/grub.d/10_linux.in
@@ -57,10 +57,14 @@ fi
 
 case x"$GRUB_FS" in
     xbtrfs)
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
+	else
 	rootsubvol="`make_system_path_relative_to_its_root /`"
 	rootsubvol="${rootsubvol#/}"
 	if [ "x${rootsubvol}" != x ]; then
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
+	fi
 	fi;;
     xzfs)
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
@@ -236,7 +240,12 @@ while [ "x$list" != "x" ] ; do
   if [ $PLATFORM != "emu" ]; then
     hotkey=0
   else
-    rel_dirname=$dirname
+    if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+       [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+       rel_dirname="\${btrfs_subvol}$dirname"
+    else
+       rel_dirname="$dirname"
+    fi
   fi
   version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`
Index: grub-2.02~beta2/util/grub.d/20_linux_xen.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/20_linux_xen.in
+++ grub-2.02~beta2/util/grub.d/20_linux_xen.in
@@ -71,10 +71,14 @@ fi
 
 case x"$GRUB_FS" in
     xbtrfs)
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
+	else
 	rootsubvol="`make_system_path_relative_to_its_root /`"
 	rootsubvol="${rootsubvol#/}"
 	if [ "x${rootsubvol}" != x ]; then
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
+	fi
 	fi;;
     xzfs)
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`

Thanks for your help!!

Offline

#6 2020-02-09 20:04:42

loqs
Member
Registered: 2014-03-06
Posts: 17,195

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

grub2-btrfs-05-grub2-mkconfig.patch with context adjusted

---
 util/grub-mkconfig.in       |    3 ++-
 util/grub-mkconfig_lib.in   |    4 ++++
 util/grub.d/00_header.in    |   23 ++++++++++++++++++++++-
 util/grub.d/10_linux.in     |   11 ++++++++++-
 util/grub.d/20_linux_xen.in |    4 ++++
 5 files changed, 42 insertions(+), 3 deletions(-)

Index: grub-2.02~beta2/util/grub-mkconfig_lib.in
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig_lib.in
+++ grub-2.02~beta2/util/grub-mkconfig_lib.in
@@ -49,7 +49,11 @@ grub_warn ()
 
 make_system_path_relative_to_its_root ()
 {
+  if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
+  "${grub_mkrelpath}" -r "$1"
+  else
   "${grub_mkrelpath}" "$1"
+  fi
 }
 
 is_path_readable_by_grub ()
Index: grub-2.02~beta2/util/grub.d/00_header.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/00_header.in
+++ grub-2.02~beta2/util/grub.d/00_header.in
@@ -27,6 +27,14 @@ export TEXTDOMAINDIR="@localedir@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+    cat <<EOF
+set btrfs_relative_path="y"
+export btrfs_relative_path
+EOF
+fi
+
 # Do this as early as possible, since other commands might depend on it.
 # (e.g. the `loadfont' command might need lvm or raid modules)
 for i in ${GRUB_PRELOAD_MODULES} ; do
@@ -43,7 +51,9 @@ if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved
 if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
 
 cat << EOF
-if [ -s \$prefix/grubenv ]; then
+if [ -f \${config_directory}/grubenv ]; then
+  load_env -f \${config_directory}/grubenv
+elif [ -s \$prefix/grubenv ]; then
   load_env
 fi
 
@@ -367,3 +377,15 @@ fi
 if [ "x${GRUB_BADRAM}" != "x" ] ; then
   echo "badram ${GRUB_BADRAM}"
 fi
+
+if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+   [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+    # Note: No $snapshot_num on *read-only* rollback!  (bsc#901487)
+    cat <<EOF
+if [ -n "\$extra_cmdline" ]; then
+  submenu "Bootable snapshot #\$snapshot_num" {
+    menuentry "If OK, run 'snapper rollback' and reboot." { true; }
+  }
+fi
+EOF
+fi
Index: grub-2.02~beta2/util/grub-mkconfig.in
===================================================================
--- grub-2.02~beta2.orig/util/grub-mkconfig.in
+++ grub-2.02~beta2/util/grub-mkconfig.in
@@ -262,7 +262,8 @@ export GRUB_DEFAULT \
   GRUB_ENABLE_CRYPTODISK \
   GRUB_BADRAM \
   GRUB_OS_PROBER_SKIP_LIST \
-  GRUB_DISABLE_SUBMENU
+  GRUB_DISABLE_SUBMENU \
+  SUSE_BTRFS_SNAPSHOT_BOOTING
 
 if test "x${grub_cfg}" != "x"; then
   rm -f "${grub_cfg}.new"
Index: grub-2.02~beta2/util/grub.d/10_linux.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/10_linux.in
+++ grub-2.02~beta2/util/grub.d/10_linux.in
@@ -57,10 +57,14 @@ fi
 
 case x"$GRUB_FS" in
     xbtrfs)
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
+	else
 	rootsubvol="`make_system_path_relative_to_its_root /`"
 	rootsubvol="${rootsubvol#/}"
 	if [ "x${rootsubvol}" != x ]; then
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
+	fi
 	fi;;
     xzfs)
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
@@ -236,7 +240,12 @@ while [ "x$list" != "x" ] ; do
   gettext_printf "Found linux image: %s\n" "$linux" >&2
   basename=`basename $linux`
   dirname=`dirname $linux`
-  rel_dirname=`make_system_path_relative_to_its_root $dirname`
+    if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
+       [ "x${GRUB_FS}" = "xbtrfs" ] ; then
+       rel_dirname="\${btrfs_subvol}$dirname"
+    else
+       rel_dirname=`make_system_path_relative_to_its_root $dirname`
+    fi
   version=`echo $basename | sed -e "s,vmlinuz-,,g"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`
   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
Index: grub-2.02~beta2/util/grub.d/20_linux_xen.in
===================================================================
--- grub-2.02~beta2.orig/util/grub.d/20_linux_xen.in
+++ grub-2.02~beta2/util/grub.d/20_linux_xen.in
@@ -71,10 +71,14 @@ fi
 
 case x"$GRUB_FS" in
     xbtrfs)
+	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
+	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
+	else
 	rootsubvol="`make_system_path_relative_to_its_root /`"
 	rootsubvol="${rootsubvol#/}"
 	if [ "x${rootsubvol}" != x ]; then
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
+	fi
 	fi;;
     xzfs)
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`

Offline

#7 2020-02-11 14:04:39

steppeno
Member
Registered: 2020-02-08
Posts: 5

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

Thanks to all for the massive help, but grub doesn't work as expected (follow btrfs default subvolume variable), i added other patch from suse grub src:

grub2-btrfs-06-subvol-mount.patch
grub2-btrfs-07-subvol-fallback.patch
grub2-btrfs-08-workaround-snapshot-menu-default-entry.patch
grub2-btrfs-09-get-default-subvolume.patch
grub2-btrfs-10-config-directory.patch

After makepkg ends, i have installed the new package (pacman - U grub.......), reinstalled grub (sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB)

Can be this variable at /etc/grub.d/10_linux?:

case x"$GRUB_FS" in
    xbtrfs)
	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
	else
	rootsubvol="`make_system_path_relative_to_its_root /`"
	rootsubvol="${rootsubvol#/}"
	if [ "x${rootsubvol}" != x ]; then
	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
	fi

sad

Offline

#8 2020-02-11 18:19:23

loqs
Member
Registered: 2014-03-06
Posts: 17,195

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

Yes that variable needs to be set for the patches to take effect.
If it still does not work try adding 80_suse_btrfs_snapshot needs to be installed to "$pkgdir"/etc/grub.d/

Last edited by loqs (2020-02-11 18:22:22)

Offline

#9 2020-02-15 20:07:25

steppeno
Member
Registered: 2020-02-08
Posts: 5

Re: PKGBUILD request: grub2 with openSUSE btrfs patches.

As always, the easy way is better. Now i can restore my system with 2 commands without fighting with grub patches only for snapper rollback ability.

First my fstab:

UUID=A177-C4C8                            /boot/efi      vfat    umask=0077 0 2
UUID=965a21e4-f1d4-4682-b5c1-ca969ac58c9b swap           swap    defaults,noatime,discard 0 2
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /              btrfs   subvol=@,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /var           btrfs   subvol=@var,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /home          btrfs   subvol=@home,defaults,noatime,space_cache,autodefrag,discard,compress=zstd  0 2
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /.snapshots    btrfs   subvol=@snapshots,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /master        btrfs   subvolid=0,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0

Now i have /var in a separate subvolume, with cow disable (so it always mount r/w if i boot from a subvolume, and in this way i can boot read-only snapshot) and a /master folder with the master btrfs id 0.
If something goes wrong, i can boot (with btrfs-grub) in last working snapshot, and  move @ to a bad@ (just for diff)

 sudo mv /master/@ /master/@bad

Create a snapshot of current (xxx) booted one to @

 sudo btrfs subvolume snapshot /master/@snapshots/xxx/snapshot  /master/@

Where xxx is the number of the snapper snapshot i wish to restore.
On reboot i have a working system. So i can restore my system by arch itself, instead booting  into a live Arch Linux USB/CD. (what I wanted from the beginning)

Thanks to all!!

Last edited by steppeno (2020-02-15 20:17:58)

Offline

Board footer

Powered by FluxBB