--- grub2-2.12.orig/grub-core/osdep/linux/getroot.c
+++ grub2-2.12/grub-core/osdep/linux/getroot.c
@@ -512,6 +512,41 @@ again:
 				       entries[i].enc_root);
 	    }
 	}
+      else if (grub_strcmp (entries[i].fstype, "bcachefs") == 0)
+	{
+          /* bcachefs supports multi-device filesystems, where /proc/self/mountinfo
+             lists all the devices separated by : (colon). Split back into individual
+             strings if so.  */
+          char *entry_copy = strdup(entries[i].device);
+          char *ptri = entry_copy;
+          char *device_start = entry_copy;
+          int j = 0;
+
+          /* First, count the number of colons to allocate memory.  */
+          while (*ptri)
+            {
+              if (*ptri++ == ':')
+                  ++j;
+            }
+	  ret = xmalloc ((j + 2) * sizeof (ret[0]));
+          ret[j + 1] = 0;
+
+          /* Then, split and allocate the individual entries.  */
+          j = 0;
+          ptri = entry_copy;
+          while (*ptri)
+            {
+              if (*ptri == ':')
+                {
+                  *ptri = 0;
+                  ret[j++] = strdup(device_start);
+                  device_start = ptri + 1;
+                }
+              ++ptri;
+            }
+          ret[j++] = strdup(device_start);
+          free(entry_copy);
+	}
       else if (grub_strcmp (entries[i].fstype, "btrfs") == 0)
 	{
 	  ret = grub_find_root_devices_from_btrfs (dir);

Index: grub2-2.12/Makefile.util.am
===================================================================
--- grub2-2.12.orig/Makefile.util.am
+++ grub2-2.12/Makefile.util.am
@@ -23,7 +23,7 @@ dist_noinst_DATA += grub-core/kern/disk_
 BUILT_SOURCES += $(nodist_libgrubkern_a_SOURCES)
 CLEANFILES += $(nodist_libgrubkern_a_SOURCES)
 noinst_LIBRARIES += libgrubmods.a
-libgrubmods_a_SOURCES += grub-core/commands/blocklist.c grub-core/commands/ls.c grub-core/commands/macbless.c grub-core/commands/testload.c grub-core/commands/xnu_uuid.c grub-core/disk/dmraid_nvidia.c grub-core/disk/loopback.c grub-core/disk/lvm.c grub-core/disk/mdraid1x_linux.c grub-core/disk/mdraid_linux.c grub-core/disk/mdraid_linux_be.c grub-core/disk/raid5_recover.c grub-core/disk/raid6_recover.c grub-core/font/font.c grub-core/fs/affs.c grub-core/fs/afs.c grub-core/fs/bfs.c grub-core/fs/btrfs.c grub-core/fs/cbfs.c grub-core/fs/cpio.c grub-core/fs/cpio_be.c grub-core/fs/exfat.c grub-core/fs/ext2.c grub-core/fs/f2fs.c grub-core/fs/fat.c grub-core/fs/fshelp.c grub-core/fs/hfs.c grub-core/fs/hfsplus.c grub-core/fs/hfspluscomp.c grub-core/fs/iso9660.c grub-core/fs/jfs.c grub-core/fs/minix.c grub-core/fs/minix2.c grub-core/fs/minix2_be.c grub-core/fs/minix3.c grub-core/fs/minix3_be.c grub-core/fs/minix_be.c grub-core/fs/newc.c grub-core/fs/nilfs2.c grub-core/fs/ntfs.c grub-core/fs/ntfscomp.c grub-core/fs/odc.c grub-core/fs/reiserfs.c grub-core/fs/romfs.c grub-core/fs/sfs.c grub-core/fs/squash4.c grub-core/fs/tar.c grub-core/fs/udf.c grub-core/fs/ufs.c grub-core/fs/ufs2.c grub-core/fs/ufs_be.c grub-core/fs/xfs.c grub-core/fs/zfs/zfs.c grub-core/fs/zfs/zfs_fletcher.c grub-core/fs/zfs/zfs_lz4.c grub-core/fs/zfs/zfs_lzjb.c grub-core/fs/zfs/zfs_sha256.c grub-core/fs/zfs/zfscrypt.c grub-core/fs/zfs/zfsinfo.c grub-core/gfxmenu/font.c grub-core/io/bufio.c grub-core/io/gzio.c grub-core/io/lzopio.c grub-core/io/xzio.c grub-core/kern/arm/dl_helper.c grub-core/kern/arm64/dl_helper.c grub-core/kern/ia64/dl_helper.c grub-core/kern/loongarch64/dl_helper.c grub-core/lib/LzFind.c grub-core/lib/LzmaEnc.c grub-core/lib/adler32.c grub-core/lib/crc.c grub-core/lib/crc64.c grub-core/lib/datetime.c grub-core/lib/envblk.c grub-core/lib/hexdump.c grub-core/lib/minilzo/minilzo.c grub-core/lib/xzembed/xz_dec_bcj.c grub-core/lib/xzembed/xz_dec_lzma2.c grub-core/lib/xzembed/xz_dec_stream.c grub-core/lib/zstd/debug.c grub-core/lib/zstd/entropy_common.c grub-core/lib/zstd/error_private.c grub-core/lib/zstd/fse_decompress.c grub-core/lib/zstd/huf_decompress.c grub-core/lib/zstd/module.c grub-core/lib/zstd/xxhash.c grub-core/lib/zstd/zstd_common.c grub-core/lib/zstd/zstd_decompress.c grub-core/normal/charset.c grub-core/normal/misc.c grub-core/partmap/acorn.c grub-core/partmap/amiga.c grub-core/partmap/apple.c grub-core/partmap/bsdlabel.c grub-core/partmap/dfly.c grub-core/partmap/dvh.c grub-core/partmap/plan.c grub-core/partmap/sun.c grub-core/partmap/sunpc.c grub-core/script/argv.c grub-core/script/function.c grub-core/script/lexer.c grub-core/script/main.c grub-core/script/script.c grub-core/unidata.c grub-core/video/capture.c grub-core/video/colors.c grub-core/video/fb/fbblit.c grub-core/video/fb/fbfill.c grub-core/video/fb/fbutil.c grub-core/video/fb/video_fb.c grub-core/video/video.c 
+libgrubmods_a_SOURCES += grub-core/commands/blocklist.c grub-core/commands/ls.c grub-core/commands/macbless.c grub-core/commands/testload.c grub-core/commands/xnu_uuid.c grub-core/disk/dmraid_nvidia.c grub-core/disk/loopback.c grub-core/disk/lvm.c grub-core/disk/mdraid1x_linux.c grub-core/disk/mdraid_linux.c grub-core/disk/mdraid_linux_be.c grub-core/disk/raid5_recover.c grub-core/disk/raid6_recover.c grub-core/font/font.c grub-core/fs/affs.c grub-core/fs/afs.c grub-core/fs/bcachefs.c grub-core/fs/bfs.c grub-core/fs/btrfs.c grub-core/fs/cbfs.c grub-core/fs/cpio.c grub-core/fs/cpio_be.c grub-core/fs/exfat.c grub-core/fs/ext2.c grub-core/fs/f2fs.c grub-core/fs/fat.c grub-core/fs/fshelp.c grub-core/fs/hfs.c grub-core/fs/hfsplus.c grub-core/fs/hfspluscomp.c grub-core/fs/iso9660.c grub-core/fs/jfs.c grub-core/fs/minix.c grub-core/fs/minix2.c grub-core/fs/minix2_be.c grub-core/fs/minix3.c grub-core/fs/minix3_be.c grub-core/fs/minix_be.c grub-core/fs/newc.c grub-core/fs/nilfs2.c grub-core/fs/ntfs.c grub-core/fs/ntfscomp.c grub-core/fs/odc.c grub-core/fs/reiserfs.c grub-core/fs/romfs.c grub-core/fs/sfs.c grub-core/fs/squash4.c grub-core/fs/tar.c grub-core/fs/udf.c grub-core/fs/ufs.c grub-core/fs/ufs2.c grub-core/fs/ufs_be.c grub-core/fs/xfs.c grub-core/fs/zfs/zfs.c grub-core/fs/zfs/zfs_fletcher.c grub-core/fs/zfs/zfs_lz4.c grub-core/fs/zfs/zfs_lzjb.c grub-core/fs/zfs/zfs_sha256.c grub-core/fs/zfs/zfscrypt.c grub-core/fs/zfs/zfsinfo.c grub-core/gfxmenu/font.c grub-core/io/bufio.c grub-core/io/gzio.c grub-core/io/lzopio.c grub-core/io/xzio.c grub-core/kern/arm/dl_helper.c grub-core/kern/arm64/dl_helper.c grub-core/kern/ia64/dl_helper.c grub-core/kern/loongarch64/dl_helper.c grub-core/lib/LzFind.c grub-core/lib/LzmaEnc.c grub-core/lib/adler32.c grub-core/lib/crc.c grub-core/lib/crc64.c grub-core/lib/datetime.c grub-core/lib/envblk.c grub-core/lib/hexdump.c grub-core/lib/minilzo/minilzo.c grub-core/lib/xzembed/xz_dec_bcj.c grub-core/lib/xzembed/xz_dec_lzma2.c grub-core/lib/xzembed/xz_dec_stream.c grub-core/lib/zstd/debug.c grub-core/lib/zstd/entropy_common.c grub-core/lib/zstd/error_private.c grub-core/lib/zstd/fse_decompress.c grub-core/lib/zstd/huf_decompress.c grub-core/lib/zstd/module.c grub-core/lib/zstd/xxhash.c grub-core/lib/zstd/zstd_common.c grub-core/lib/zstd/zstd_decompress.c grub-core/normal/charset.c grub-core/normal/misc.c grub-core/partmap/acorn.c grub-core/partmap/amiga.c grub-core/partmap/apple.c grub-core/partmap/bsdlabel.c grub-core/partmap/dfly.c grub-core/partmap/dvh.c grub-core/partmap/plan.c grub-core/partmap/sun.c grub-core/partmap/sunpc.c grub-core/script/argv.c grub-core/script/function.c grub-core/script/lexer.c grub-core/script/main.c grub-core/script/script.c grub-core/unidata.c grub-core/video/capture.c grub-core/video/colors.c grub-core/video/fb/fbblit.c grub-core/video/fb/fbfill.c grub-core/video/fb/fbutil.c grub-core/video/fb/video_fb.c grub-core/video/video.c 
 nodist_libgrubmods_a_SOURCES += grub_script.tab.c grub_script.tab.h grub_script.yy.c grub_script.yy.h libgrub_a_init.c 
 libgrubmods_a_CFLAGS += $(AM_CFLAGS) $(CFLAGS_LIBRARY) -fno-builtin -Wno-undef -Wno-unused-but-set-variable 
 libgrubmods_a_CPPFLAGS += $(AM_CPPFLAGS) $(CPPFLAGS_LIBRARY) -I$(srcdir)/grub-core/lib/minilzo -I$(srcdir)/grub-core/lib/xzembed -I$(srcdir)/grub-core/lib/zstd -DMINILZO_HAVE_CONFIG_H 
Index: grub2-2.12/grub-core/fs/bcachefs.c
===================================================================
--- /dev/null
+++ grub2-2.12/grub-core/fs/bcachefs.c
@@ -0,0 +1,182 @@
+/* bcachefs.c - bcachefs filesystem.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007,2008,2009,2013 Free Software Foundation, Inc.
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This does not support reading bcachefs filesystems (yet); it exists
+ * solely to get its UUID.  If we want read support, we should probably
+ * use libbcachefs to do so.
+ */
+
+#include <stdio.h>
+
+#include <grub/archelp.h>
+#include <grub/disk.h>
+#include <grub/dl.h>
+#include <grub/fs.h>
+#include <grub/misc.h>
+#include <grub/types.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+
+#define GRUB_BCACHEFS_LABEL_SIZE 32
+#define GRUB_BCACHEFS_SB_SECTOR 8
+
+typedef grub_uint8_t grub_bcachefs_uuid_t[16];
+
+static const grub_bcachefs_uuid_t GRUB_BCACHEFS_MAGIC = {
+  0xc6, 0x85, 0x73, 0xf6, 0x66, 0xce, 0x90, 0xa9,
+  0xd9, 0x6a, 0x60, 0xcf, 0x80, 0x3d, 0xf7, 0xef
+};
+
+struct grub_bcachefs_checksum {
+  grub_uint64_t lo;
+  grub_uint64_t hi;
+} GRUB_PACKED;
+
+/* Adapted from struct bch_sb in bcachefs-tools.  All fields are little endian. */
+struct grub_bcachefs_superblock {
+  struct grub_bcachefs_checksum csum;
+  grub_uint16_t version;
+  grub_uint16_t version_min;
+  grub_uint16_t pad[2];
+  grub_bcachefs_uuid_t magic;
+  grub_bcachefs_uuid_t uuid;
+  grub_bcachefs_uuid_t user_uuid;
+  grub_uint8_t label[GRUB_BCACHEFS_LABEL_SIZE];
+  grub_uint64_t offset;
+  grub_uint64_t seq;
+
+  grub_uint16_t block_size;
+  grub_uint8_t dev_idx;
+  grub_uint8_t nr_devices;
+  grub_uint32_t u64s;
+
+  grub_uint64_t time_base_lo;
+  grub_uint32_t time_base_hi;
+  grub_uint32_t time_precision;
+
+  grub_uint64_t flags[7];
+  grub_uint64_t write_time;
+  grub_uint64_t features[2];
+  grub_uint64_t compat[2];
+
+  /* bch_sb_layout below (which we don't need), then the flexible data members */
+} GRUB_PACKED;
+
+static grub_err_t
+read_sblock (grub_disk_t disk, struct grub_bcachefs_superblock *sb)
+{
+  grub_err_t err;
+
+  err = grub_disk_read (disk, GRUB_BCACHEFS_SB_SECTOR, 0,
+			sizeof (*sb), sb);
+  if (err == GRUB_ERR_OUT_OF_RANGE)
+    return grub_error (GRUB_ERR_BAD_FS, "not a bcachefs filesystem");
+  if (err)
+    return err;
+
+  if (grub_memcmp ((char *) sb->magic, GRUB_BCACHEFS_MAGIC,
+		   sizeof (GRUB_BCACHEFS_MAGIC)) != 0)
+    return grub_error (GRUB_ERR_BAD_FS, "not a bcachefs filesystem");
+
+  return err;
+}
+
+static grub_err_t
+grub_bcachefs_dir (grub_device_t device, const char *path_in,
+	       grub_fs_dir_hook_t hook, void *hook_data)
+{
+  (void) device;
+  (void) path_in;
+  (void) hook;
+  (void) hook_data;
+  return GRUB_ERR_NOT_IMPLEMENTED_YET;
+}
+
+static grub_err_t
+grub_bcachefs_open (grub_file_t file, const char *name_in)
+{
+  (void) file;
+  (void) name_in;
+  return GRUB_ERR_NOT_IMPLEMENTED_YET;
+}
+
+static grub_ssize_t
+grub_bcachefs_read (grub_file_t file, char *buf, grub_size_t len)
+{
+  (void) file;
+  (void) buf;
+  (void) len;
+  return GRUB_ERR_NOT_IMPLEMENTED_YET;
+}
+
+static grub_err_t
+grub_bcachefs_close (grub_file_t file)
+{
+  (void) file;
+  return GRUB_ERR_NOT_IMPLEMENTED_YET;
+}
+
+static grub_err_t
+grub_bcachefs_uuid (grub_device_t device, char **uuid)
+{
+  grub_err_t err;
+  struct grub_bcachefs_superblock sb;
+
+  *uuid = NULL;
+  err = read_sblock (device->disk, &sb);
+  if (err == GRUB_ERR_BAD_FS)
+    {
+      grub_errno = GRUB_ERR_NONE;
+      return 0;
+    }
+  if (err)
+    {
+      grub_print_error ();
+      return 0;
+    }
+
+  *uuid = grub_xasprintf ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+			  sb.user_uuid[0], sb.user_uuid[1], sb.user_uuid[2], sb.user_uuid[3],
+			  sb.user_uuid[4], sb.user_uuid[5], sb.user_uuid[6], sb.user_uuid[7],
+			  sb.user_uuid[8], sb.user_uuid[9], sb.user_uuid[10], sb.user_uuid[11],
+			  sb.user_uuid[12], sb.user_uuid[13], sb.user_uuid[14], sb.user_uuid[15]);
+
+  return GRUB_ERR_NONE;
+}
+
+static struct grub_fs grub_bcachefs_fs = {
+  .name = "bcachefs",
+  .fs_dir = grub_bcachefs_dir,
+  .fs_open = grub_bcachefs_open,
+  .fs_read = grub_bcachefs_read,
+  .fs_close = grub_bcachefs_close,
+  .fs_uuid = grub_bcachefs_uuid,
+};
+
+GRUB_MOD_INIT (bcachefs)
+{
+  grub_fs_register (&grub_bcachefs_fs);
+}
+
+GRUB_MOD_FINI (bcachefs)
+{
+  grub_fs_unregister (&grub_bcachefs_fs);
+}
Index: grub2-2.12/Makefile.util.def
===================================================================
--- grub2-2.12.orig/Makefile.util.def
+++ grub2-2.12/Makefile.util.def
@@ -91,6 +91,7 @@ library = {
   common = grub-core/io/bufio.c;
   common = grub-core/fs/affs.c;
   common = grub-core/fs/afs.c;
+  common = grub-core/fs/bcachefs.c;
   common = grub-core/fs/bfs.c;
   common = grub-core/fs/btrfs.c;
   common = grub-core/fs/cbfs.c;
