From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Xy4cl-00047E-RA for mharc-grub-devel@gnu.org; Mon, 08 Dec 2014 15:09:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xy4cf-00046Y-0r for grub-devel@gnu.org; Mon, 08 Dec 2014 15:09:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xy4ca-00073b-Ok for grub-devel@gnu.org; Mon, 08 Dec 2014 15:09:32 -0500 Received: from mail-la0-x236.google.com ([2a00:1450:4010:c03::236]:61041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xy4ca-00073N-3L for grub-devel@gnu.org; Mon, 08 Dec 2014 15:09:28 -0500 Received: by mail-la0-f54.google.com with SMTP id pv20so4463951lab.41 for ; Mon, 08 Dec 2014 12:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=PHYEtNDFBkCQnGnCZbn6Lf3E/oLFrBBs/YX91E5vINw=; b=wZtKOYQmHPAUtcFuXUVZdvZNlcmrzuZcKfK+Df/vE68BinpV14gyQM1kIm8JEZp3uH eTFBlRnq1gnIIDsjCAESu5MNyvN/Mq6AbX9k4E4GF1UGsm5QZvOjzt4w3J+g4UxibwRt CSSf4vozfLyuV6iBb0RVVRctNu6q8OsKI58KTy9OYXB1XGrKwrR63GUPdmUqFxKktaGq ZVsOfhcypsKqr4MtAVHaKe6xzPVi6h82GQZuIBZWlk7lCuqGksX0LJf2XoEkByWq9DJ5 yidSyXU+zTUn4eEebHIyREBlVTcqVSDJeCSAneS/TEorZ2ufZDpdbBXlHLK5UvUFTZpg FbmQ== X-Received: by 10.112.135.229 with SMTP id pv5mr18057882lbb.52.1418069367229; Mon, 08 Dec 2014 12:09:27 -0800 (PST) Received: from opensuse.site (ppp91-76-15-25.pppoe.mtu-net.ru. [91.76.15.25]) by mx.google.com with ESMTPSA id kc3sm2215867lbc.33.2014.12.08.12.09.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Dec 2014 12:09:26 -0800 (PST) Date: Mon, 8 Dec 2014 23:09:24 +0300 From: Andrei Borzenkov To: Martin Steigerwald Subject: Re: Bug#747653: grub2-common: update-grub adds both devices and a line feed for BTRFS RAID 1 setup Message-ID: <20141208230924.36804ca7@opensuse.site> In-Reply-To: <16494259.4vNOI0uB2Y@merkaba> References: <20140510185334.5756.69796.reportbug@merkaba.lichtvoll> <20140602193922.18d3a188@opensuse.site> <16494259.4vNOI0uB2Y@merkaba> X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.25; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::236 Cc: Debian Bug Tracking System , The development of GNU GRUB X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Dec 2014 20:09:37 -0000 =D0=92 Sat, 06 Dec 2014 12:01:11 +0100 Martin Steigerwald =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > Am Montag, 2. Juni 2014, 19:39:22 schrieb Andrey Borzenkov: > > =D0=92 Sat, 10 May 2014 20:53:34 +0200 > >=20 > > Martin Steigerwald =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > > > Package: grub2-common > > > Version: 2.02~beta2-10 > > > Severity: normal > > >=20 > > > Dear Maintainer, > > >=20 > > > I am booting my Debian system via a BTRFS RAID 1 which spans a logical > > > volume on a Crucial MSATA and Intel SATA SSD each. > > >=20 > > > After running update-grub I am getting this in /boot/grub/grub.cfg: > > > echo 'Linux 3.15.0-rc5-tp520 wird geladen =E2=80= =A6' > > > linux /vmlinuz-3.15.0-rc5-tp520 > > > root=3D/dev/mapper/sata-debian > > > =20 > > > /dev/mapper/msata-debian ro rootflags=3Dsubvol=3Ddebian=20 > > > init=3D/bin/systemd resume=3D/dev/mapper/sata-swap> =20 > > > echo 'Initiale Ramdisk wird geladen =E2=80=A6' > > > initrd /initrd.img-3.15.0-rc5-tp520 > > >=20 > > > update-grub basically adds both devices of the BTRFS RAID 1 device > > > separated by a line feed. For mounting BTRFS RAID 1 tough one of them > > > is enough, once btrfs device scan is run, for which I currently use an > > > script for initramfs-tools as a work-around as it didn=C2=B4t work ou= t of > > > the box on my last tests[1]. > > >=20 > > > This behaviour is due to grub-probe which is called by grub-mkconfig > > > at line 139 > > >=20 > > > 138 # Device containing our userland. Typically used for root=3D par= ameter. > > > 139 GRUB_DEVICE=3D"`${grub_probe} --target=3Ddevice /`" > > > 140 GRUB_DEVICE_UUID=3D"`${grub_probe} --device ${GRUB_DEVICE} > > > --target=3Dfs_uuid 2> /dev/null`" || true > > >=20 > > > which is called by update-grub returns both devices with a > > > linefeed: > > >=20 > > > merkaba:~> grub-probe --target=3Ddevice / > > > /dev/mapper/sata-debian > > > /dev/mapper/msata-debian > > >=20 > > > grub-probe is an ELF binary. > > >=20 > > > The following little change workarounds the issue for me: > > >=20 > > > merkaba:~> diff -u /usr/sbin/grub-mkconfig.dist /usr/sbin/grub-mkconf= ig > > > --- /usr/sbin/grub-mkconfig.dist 2014-05-08 14:35:25.000000000 > > > +0200 > > > +++ /usr/sbin/grub-mkconfig 2014-05-10 20:46:00.380096263 +0200 > > > @@ -136,7 +136,7 @@ > > >=20 > > > fi > > > =20 > > > # Device containing our userland. Typically used for root=3D parame= ter. > > >=20 > > > -GRUB_DEVICE=3D"`${grub_probe} --target=3Ddevice /`" > > > +GRUB_DEVICE=3D"`${grub_probe} --target=3Ddevice / | head -1`" > > >=20 > > > GRUB_DEVICE_UUID=3D"`${grub_probe} --device ${GRUB_DEVICE} --target= =3Dfs_uuid > > > 2> /dev/null`" || true > > > =20 > > > # Device containing our /boot partition. Usually the same as > > > GRUB_DEVICE. > > >=20 > > > But I suppose the real fix is to be made in the binary grub-probe. > >=20 > > No, grub-probe is correct; grub needs to know all devices so it can > > have full information which drivers it requires to access them. > >=20 > > See also > > https://lists.gnu.org/archive/html/grub-devel/2014-05/msg00005.html > >=20 > > I suggest you discuss it with Colin, but for now I tend to think, fix > > should go into 10_linux. May be always use UUID for btrfs. > >=20 > > But this sounds like new can of worms :( >=20 > Any way on how to proceed on this one? >=20 Try patch below From: Andrei Borzenkov Subject: [PATCH] fix linux kernel root=3D argument with multidev btrfs Btrfs may reside on multiple devices, but only one of them should be passed to root=3D kernel argument. Add two helper functions: - get_root_device: select "best" device for the list. For single device just return it to skip probing; for multiple devices try to find LVM as before but fall back to the first device if not found. - find_abstraction: return device with requested abstraction driver from the given list. Refactor code to use them and reimplement uses_abstraction on top of find_abstraction. Also replace check for LVM with uses_abstraction in 10_kfreebsd. --- util/grub-mkconfig_lib.in | 50 ++++++++++++++++++++++++++++++++++-------= ---- util/grub.d/10_kfreebsd.in | 8 +++----- util/grub.d/10_linux.in | 10 +++++---- util/grub.d/20_linux_xen.in | 10 +++++---- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index 29ef865..ecae264 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -283,21 +283,27 @@ gettext_printf () { printf "$(gettext "$gettext_printf_format")" "$@" } =20 -uses_abstraction () { - device=3D"$1" - old_ifs=3D"$IFS" +find_abstraction () { + abstraction=3D"$1" + devices=3D"$2" + old_IFS=3D"$IFS" IFS=3D' ' - - abstraction=3D"`"${grub_probe}" --device ${device} --target=3Dabstractio= n`" - for module in ${abstraction}; do - if test "x${module}" =3D "x$2"; then - IFS=3D"$old_ifs" - return 0 - fi + set $devices + IFS=3D"$old_IFS" + + for device in "$@"; do + for module in `"${grub_probe}" --device "${device}" --target=3Dabstrac= tion`; do + if test "x${module}" =3D "x${abstraction}"; then + printf "%s" "${device}" + return + fi + done done - IFS=3D"$old_ifs" - return 1 +} + +uses_abstraction () { + test -n "`find_abstraction "$2" "$1"`" } =20 print_option_help () { @@ -368,3 +374,23 @@ grub_add_tab () { sed -e "s/^/$grub_tab/" } =20 +get_root_device() { + devices=3D"$1" + old_IFS=3D"$IFS" + IFS=3D' +' + set $devices + IFS=3D"$old_IFS" + + if [ x"$#" =3D x1 ]; then + printf "%s" "$1" + return + fi + + out=3D"`find_abstraction lvm "$devices"`" + if [ x"$out" =3D x ]; then + out=3D"$1" + fi + + printf "%s" "$out" +} diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in index 65f6c32..d9d0199 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -112,11 +112,9 @@ EOF =20 load_kfreebsd_module acpi true =20 - for abstraction in dummy $(${grub_probe} -t abstraction --device ${GRUB_= DEVICE}) ; do - case $abstraction in - lvm) load_kfreebsd_module geom_linux_lvm false ;; - esac - done + if uses_abstraction "${GRUB_DEVICE}" lvm; then + load_kfreebsd_module geom_linux_lvm false + fi =20 case "${kfreebsd_fs}" in zfs) diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index a2a84dc..68aa1e7 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -44,11 +44,13 @@ case ${GRUB_DEVICE} in esac =20 if [ "x${GRUB_DEVICE_UUID}" =3D "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = =3D "xtrue" ] \ - || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ - || uses_abstraction "${GRUB_DEVICE}" lvm; then - LINUX_ROOT_DEVICE=3D${GRUB_DEVICE} + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}"; then + LINUX_ROOT_DEVICE=3D"`get_root_device "${GRUB_DEVICE}"`" else - LINUX_ROOT_DEVICE=3DUUID=3D${GRUB_DEVICE_UUID} + LINUX_ROOT_DEVICE=3D"`find_abstraction lvm "${GRUB_DEVICE}"`" + if [ x"${LINUX_ROOT_DEVICE}" =3D x ]; then + LINUX_ROOT_DEVICE=3DUUID=3D${GRUB_DEVICE_UUID} + fi fi =20 case x"$GRUB_FS" in diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in index de34c8d..b9426e9 100644 --- a/util/grub.d/20_linux_xen.in +++ b/util/grub.d/20_linux_xen.in @@ -44,11 +44,13 @@ case ${GRUB_DEVICE} in esac =20 if [ "x${GRUB_DEVICE_UUID}" =3D "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = =3D "xtrue" ] \ - || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ - || uses_abstraction "${GRUB_DEVICE}" lvm; then - LINUX_ROOT_DEVICE=3D${GRUB_DEVICE} + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}"; then + LINUX_ROOT_DEVICE=3D"`get_root_device "${GRUB_DEVICE}"`" else - LINUX_ROOT_DEVICE=3DUUID=3D${GRUB_DEVICE_UUID} + LINUX_ROOT_DEVICE=3D"`find_abstraction lvm "${GRUB_DEVICE}"`" + if [ x"${LINUX_ROOT_DEVICE}" =3D x ]; then + LINUX_ROOT_DEVICE=3DUUID=3D${GRUB_DEVICE_UUID} + fi fi =20 # Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT. --=20 tg: (17328db..) u/btrfs-multidev (depends on: master)