Received: from list by lists.gnu.org with archive (Exim 4.71) id 1XjlGT-0002VV-O2 for mharc-grub-devel@gnu.org; Thu, 30 Oct 2014 04:39:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjlGI-0002UQ-Rx for grub-devel@gnu.org; Thu, 30 Oct 2014 04:39:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XjlG9-0006Ng-QR for grub-devel@gnu.org; Thu, 30 Oct 2014 04:39:18 -0400 Received: from mail-pd0-x233.google.com ([2607:f8b0:400e:c02::233]:50416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjlG9-0006Na-Jh for grub-devel@gnu.org; Thu, 30 Oct 2014 04:39:09 -0400 Received: by mail-pd0-f179.google.com with SMTP id g10so4743789pdj.10 for ; Thu, 30 Oct 2014 01:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=6GO5XKChKuS3hkf7qnckI5YSO86OT0wMu3r9dqZK+IU=; b=clzJ0x0YYXWnio118yX5rhA4NvfTq8oFPISMP2uDWJQoMO+4UGwvfCDeFBLGq9eGvb 3JAGIg8yOgo3glMvds+lZhIf+qec4mll9HqFtfCT1pAqjHXg4K3trmn16JNmiAJMv7yS PvXaxERpc8N2enX5hIMV1QXNKJaWFPo+xyw3OzQy9OTd6HltvZLVFH3H/Gy9nAeAW/0K nlbPiW1NckzRV666ZEIpOKRW7QP+/xEAxU293R+ZJWbF47WSFmGuUlQyybTg/RT9ggus dFV1ZjDlA8+WHsMxQrjByg5/oQ8PKP35pSW9aczc9YuUEiPJUg8ynHyetIsOolPLTDSp 8aew== X-Received: by 10.70.43.168 with SMTP id x8mr15724234pdl.107.1414658348039; Thu, 30 Oct 2014 01:39:08 -0700 (PDT) Received: from linux-dsax.tai.apac.novell.com ([130.57.30.250]) by mx.google.com with ESMTPSA id cl1sm6371643pbb.92.2014.10.30.01.39.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 01:39:07 -0700 (PDT) Sender: =?UTF-8?B?5by15paH6I+v?= Date: Thu, 30 Oct 2014 16:32:43 +0800 From: Michael Chang To: grub-devel@gnu.org Subject: workaround install boot on btrfs with windows partition scheme Message-ID: <20141030083243.GA7083@linux-dsax.tai.apac.novell.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5vNYLRcllDrimb99" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::233 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: Thu, 30 Oct 2014 08:39:28 -0000 --5vNYLRcllDrimb99 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Many shipped Windows created it's first partition aligned in 63 (cylinder) and therefore can't offer enough room for core.img. Even worse the partitions has been created as logical. > sudo /sbin/fdisk -l Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0001c622 Device Boot Start End Blocks Id System /dev/sda1 63 2056319 1028128+ b W95 FAT32 /dev/sda2 * 2058240 125829119 61885440 f W95 Ext'd (LBA) /dev/sda5 2060288 5302271 1620992 82 Linux swap / Solaris /dev/sda6 5304320 47247359 20971520 83 Linux /dev/sda7 47249408 125804543 39277568 83 Linux This leaves us currently no option to succeed in installation if boot is on btrfs, or any other filesystems that block lists can't be used and core.img must be embedded in order to be reliably addressed. The attached patch try to workaround this scenario by placing the core.img in filesystem's (btrfs) bootloader embedding area if available to overcome the too small MBR gap which gets loaded by boot.img placed in MBR. Please kindly review the patch or suggests for how to fix this scenario sanely. Thanks. Michael --5vNYLRcllDrimb99 Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="grub2-setup-try-fs-embed-if-mbr-gap-too-small.patch" Index: grub-2.02~beta2/util/setup.c =================================================================== --- grub-2.02~beta2.orig/util/setup.c +++ grub-2.02~beta2/util/setup.c @@ -501,8 +501,44 @@ SETUP (const char *dir, err = grub_util_ldm_embed (dest_dev->disk, &nsec, maxsec, GRUB_EMBED_PCBIOS, §ors); else if (ctx.dest_partmap) - err = ctx.dest_partmap->embed (dest_dev->disk, &nsec, maxsec, - GRUB_EMBED_PCBIOS, §ors); + { + err = ctx.dest_partmap->embed (dest_dev->disk, &nsec, maxsec, + GRUB_EMBED_PCBIOS, §ors); +#ifdef GRUB_SETUP_BIOS + if (err == GRUB_ERR_OUT_OF_RANGE + && strcmp (ctx.dest_partmap->name, "msdos") == 0 + && dest_dev->disk->id == root_dev->disk->id + && dest_dev->disk->dev->id == root_dev->disk->dev->id) + { + grub_fs_t root_fs; + + root_fs = grub_fs_probe (root_dev); + if (root_fs && root_fs->embed) + { + grub_disk_addr_t *fs_sectors; + unsigned int fs_nsec; + + fs_sectors = NULL; + fs_nsec = core_sectors; + err = root_fs->embed (root_dev, &fs_nsec, maxsec, + GRUB_EMBED_PCBIOS, &fs_sectors); + if (!err && fs_nsec >= core_sectors) + { + grub_util_info ("Your msdos embedding area is too small, will use file system embedding area instead"); + sectors = fs_sectors; + nsec = fs_nsec; + ctx.container = root_dev->disk->partition; + core_dev = root_dev; + } + else + { + if (fs_sectors) + grub_free (fs_sectors); + } + } + } +#endif + } else err = fs->embed (dest_dev, &nsec, maxsec, GRUB_EMBED_PCBIOS, §ors); @@ -584,7 +620,7 @@ SETUP (const char *dir, /* Write the core image onto the disk. */ for (i = 0; i < nsec; i++) - grub_disk_write (dest_dev->disk, sectors[i], 0, + grub_disk_write (core_dev->disk, sectors[i], 0, GRUB_DISK_SECTOR_SIZE, core_img + i * GRUB_DISK_SECTOR_SIZE); --5vNYLRcllDrimb99--