Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 283637 - sys-boot/grub-0.97-r9: Patch to add btrfs support
Summary: sys-boot/grub-0.97-r9: Patch to add btrfs support
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High enhancement with 1 vote (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on: 674364
Blocks:
  Show dependency tree
 
Reported: 2009-09-04 09:33 UTC by Jochen Seeber
Modified: 2019-02-08 15:29 UTC (History)
12 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
btrfs support for grub-0.97 (grub_0.97_btrfs.patch,105.46 KB, patch)
2009-10-29 19:55 UTC, Johannes Hirte
Details | Diff
grub_0.97_btrfs.patch (grub_0.97_btrfs.patch,105.53 KB, patch)
2009-12-11 00:22 UTC, Johannes Hirte
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jochen Seeber 2009-09-04 09:33:52 UTC
The attached patch adds btrfs support to grub. It is based on a patch created by Edward Shishkin: http://osdir.com/ml/grub-devel-gnu/2009-07/msg00349.html

It should be added as last patch to the patch list of grub-0.97-r9

Reproducible: Always
Comment 1 Johannes Hirte 2009-10-29 19:55:57 UTC
Created attachment 208666 [details, diff]
btrfs support for grub-0.97

Hm, maybe I'm blind, but I don't see any atteched patch.

I've taken the posted patches from Edward Shishkin on the btrfs-ML and put them into shape for gentoo-grub. The patch was made against a full patched grub-0.97 from gentoo. It's tested and works fine for me on a single-device btrfs as root-fs.
Comment 2 Zac Medico gentoo-dev 2009-10-31 05:25:35 UTC
The patch triggers this error with USE=netboot enabled:

fsys_btrfs.c: In function ‘scan_grub_devices’:
fsys_btrfs.c:458: error: ‘network_ready’ undeclared (first use in this function)
fsys_btrfs.c:458: error: (Each undeclared identifier is reported only once
fsys_btrfs.c:458: error: for each function it appears in.)
Comment 3 Zac Medico gentoo-dev 2009-11-12 05:06:43 UTC
With this patch, I was able to boot indirectly (using stage2 from a ext3 parition) into a btrfs root filesystem. However, when I try to use the grub shell to update the mbr to boot directly into the btrfs root, I get this:

grub> root (hd0,2)
 Filesystem type is btrfs, partition type 0x83

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... no

Error 15: File not found
Comment 4 pragnesh 2009-11-18 03:10:50 UTC
(In reply to comment #3)
> With this patch, I was able to boot indirectly (using stage2 from a ext3
> parition) into a btrfs root filesystem. However, when I try to use the grub
> shell to update the mbr to boot directly into the btrfs root, I get this:
> 
> grub> root (hd0,2)
>  Filesystem type is btrfs, partition type 0x83
> 
> grub> setup (hd0)
>  Checking if "/boot/grub/stage1" exists... no
>  Checking if "/grub/stage1" exists... no
> 
> Error 15: File not found
> 

i was also facing same problem. later i found that btrfs_stage1_5 is not present under /boot/grub dir even after compilation with this patch so i did manual compilation,installation and copied btrfs_stage1_5 under /boot/grub and it work for me
Comment 5 Zac Medico gentoo-dev 2009-11-19 08:25:13 UTC
(In reply to comment #4)
> i was also facing same problem. later i found that btrfs_stage1_5 is not
> present under /boot/grub dir even after compilation with this patch

That file was always been present for me, but I still got the 'Error 15: File not found' think.
Comment 6 Johannes Hirte 2009-12-10 15:18:59 UTC
(In reply to comment #1)
> Created an attachment (id=208666) [details]
> btrfs support for grub-0.97
> 
> Hm, maybe I'm blind, but I don't see any atteched patch.
> 
> I've taken the posted patches from Edward Shishkin on the btrfs-ML and put them
> into shape for gentoo-grub. The patch was made against a full patched grub-0.97
> from gentoo. It's tested and works fine for me on a single-device btrfs as
> root-fs.
> 

Please be carefull with this patch. I've tested now with a second machine and with this pacht grub is unable to detect the still present XFS root filesystem.
Comment 7 Johannes Hirte 2009-12-11 00:22:04 UTC
Created attachment 212661 [details, diff]
grub_0.97_btrfs.patch
Comment 8 Johannes Hirte 2009-12-11 00:27:23 UTC
(In reply to comment #2)
> The patch triggers this error with USE=netboot enabled:
> 
> fsys_btrfs.c: In function ‘scan_grub_devices’:
> fsys_btrfs.c:458: error: ‘network_ready’ undeclared (first use in this
> function)
> fsys_btrfs.c:458: error: (Each undeclared identifier is reported only once
> fsys_btrfs.c:458: error: for each function it appears in.)
> 

Fixed with the new submitted patch. The new patch also fixes the problem with not detected XFS filesystems. The bug affects other filesystems too, like JFS or ISO9660. The only filesystem which is still (possibly) affected by this bug is FFS. All other should work as expected.
Comment 9 Johannes Hirte 2009-12-11 00:35:04 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > With this patch, I was able to boot indirectly (using stage2 from a ext3
> > parition) into a btrfs root filesystem. However, when I try to use the grub
> > shell to update the mbr to boot directly into the btrfs root, I get this:
> > 
> > grub> root (hd0,2)
> >  Filesystem type is btrfs, partition type 0x83
> > 
> > grub> setup (hd0)
> >  Checking if "/boot/grub/stage1" exists... no
> >  Checking if "/grub/stage1" exists... no
> > 
> > Error 15: File not found
> > 
> 
> i was also facing same problem. later i found that btrfs_stage1_5 is not
> present under /boot/grub dir even after compilation with this patch so i did
> manual compilation,installation and copied btrfs_stage1_5 under /boot/grub and
> it work for me
> 

(In reply to comment #3)
> With this patch, I was able to boot indirectly (using stage2 from a ext3
> parition) into a btrfs root filesystem. However, when I try to use the grub
> shell to update the mbr to boot directly into the btrfs root, I get this:
> 
> grub> root (hd0,2)
>  Filesystem type is btrfs, partition type 0x83
> 
> grub> setup (hd0)
>  Checking if "/boot/grub/stage1" exists... no
>  Checking if "/grub/stage1" exists... no
> 
> Error 15: File not found
> 

That's a little strange. Did you tried to update the mbr from a btrfs filesystem? I forgot to mention, that setup in grub shell needs a little different handling. 

grub> root (hdX,Y)
grub> setup --stage2=/mnt/grub/stage2 (hdX)

The stage2 option tells grug to rewrite the stage2 file by the OS filesystem driver. Without this option, the rewrite is done bypassing the OS, which will fail. So the ebuild should be updated too, to warn users about this.

But this doesn't explain the missing stage1.
Comment 10 haarp 2009-12-11 17:00:47 UTC
Thank you. It's working fine for me now.
Comment 11 piavlo 2010-01-10 11:13:53 UTC
(In reply to comment #9)
> I forgot to mention, that setup in grub shell needs a little different
> handling.
> 
> grub> root (hdX,Y)
> grub> setup --stage2=/mnt/grub/stage2 (hdX)

Is still does not work for me , see blow:

# cat /boot/grub/install-btrfs.sh
grub --device-map=/dev/null --batch <<EOF
device (hd0) /dev/vda
root (hd0,1)
setup --stage2=/mnt/grub/stage2 (hd0)
EOF
# /boot/grub/install-btrfs.sh


    GNU GRUB  version 0.97  (640K lower / 7168K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename. ]
grub> device (hd0) /dev/vda
grub> root (hd0,1)
 Filesystem type is btrfs, partition type 0x83
grub> setup --stage2=/mnt/grub/stage2 (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/btrfs_stage1_5" exists... yes
 Running "embed /boot/grub/btrfs_stage1_5 (hd0)"...  29 sectors are embedded.
succeeded
 Running "install --stage2=/mnt/grub/stage2 /boot/grub/stage1 (hd0) (hd0)1+29 p (hd0,1)/boot/grub/stage2 /boot/grub/menu.lst"... failed

Error 15: File not found
grub> 

It does work with the following script:

# cat /boot/grub/install-btrfs-ext3.sh
grub --device-map=/dev/null --batch <<EOF
device (hd0) /dev/vda
root (hd0,1)
embed /boot/grub/btrfs_stage1_5 (hd0)
install /boot/grub/stage1 (hd0) (hd0)1+29 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst
EOF
# /boot/grub/install-btrfs-ext3.sh


    GNU GRUB  version 0.97  (640K lower / 7168K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename. ]
grub> device (hd0) /dev/vda
grub> root (hd0,1)
 Filesystem type is btrfs, partition type 0x83
grub> embed /boot/grub/btrfs_stage1_5 (hd0)
 29 sectors are embedded.
grub> install /boot/grub/stage1 (hd0) (hd0)1+29 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst
grub>
#                                                          

 Any ideas?
Comment 12 piavlo 2010-01-10 11:15:48 UTC
forgot to mention that (hd0,0) is ext3 and (hd0,1) is btrfs
Comment 13 Brandon 2010-04-10 18:58:50 UTC
With the 2009-12-11 patch (added to the Ubuntu grub patches in the .deb) applied, grub gave the "Error 15: File not found" error that piavlo mentioned.  I had intentionally used compression to be able to fit the operating system on a small ssd disk, and realized that grub is looking for an uncompressed stage1, stage2, btrfs_stage1_5, and menu.lst with fixed offsets on the disk for each.  After remounting the root filesystem containing /boot without compression and rewriting /boot on disk ( mv /boot /boot. ; cp -ar /boot. /boot ), grub was satisfied and updated the MBR, but upon rebooting the (Ubuntu) kernel couldn't find the btrfs filesystem on the disk, even though the btrfs kernel modules were in the /boot initrd and, if I remember correctly, were loaded before trying to mount the filesystem.  At this point I decided to compile btrfs into the booting kernel, and then the kernel found the btrfs filesystem, but it didn't use the initrd even though it was specified in the boot command line, so I had other driver-related problems.  However, after a number of fixes to the /sbin/init boot process, the system now boots directly into a compressed btrfs filesystem without any issues.  I should note that a bootable USB disk with syslinux was quite valuable during this process, and I will keep it handy in case a system update accidentally overwrites some of the necessary changes.
Comment 14 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-06-25 04:14:43 UTC
pushing to -r11 due to other patches going into -r10
Comment 15 Anton Bolshakov 2010-08-27 21:39:25 UTC
(In reply to comment #14)
> pushing to -r11 due to other patches going into -r10
> 

Could someone port the patch for -r11? It can't be apply with -r10 currently.
Thanks
Comment 16 Mikle Kolyada archtester Gentoo Infrastructure gentoo-dev Security 2019-02-08 15:29:26 UTC
grub:0 is gone