Bug#631853: grub-install: allowable targets for embedding are unnecessarily restrictive
Jeffrey Sheinberg
jeff at bsrd.net
Mon Jun 27 19:40:30 UTC 2011
Package: grub-pc
Version: 1.98+20100804-14
Severity: normal
Hi,
This bug report applies to the common MBR partition tables, not to the newer
and less common GUID Partition Tables (GPT).
Here is the usage of grub-install that prompted this bug report,
# grub-install /dev/sda7
/usr/sbin/grub-setup: warn: Attempting to install GRUB to a partition
instead of the MBR. This is a BAD idea..
/usr/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be
installed in this setup by using blocklists. However, blocklists are
UNRELIABLE and their use is discouraged..
/usr/sbin/grub-setup: error: if you really want blocklists, use --force.
--> exit status 1
I hold that if grub can be installed to the MBR using embedding, then in
addition, grub can also be installed to any logical partition using
embedding.
In the standard MBR partition table, the first partition that follows
the MBR actually starts at some offset from the MBR sector. This offset
is usually the number of sectors per track for legacy partition tables,
which is commonly 63 sectors, or is 2048 sectors for modern partition
tables.
This unused space created by the offset from the MBR to the start of the
first partition is where grub is embedded to, when grub is installed to
the MBR.
The beginning of each logical partition is also offset from the
pseudo-MBR that is used to define the location and size of each logical
partition. This pseudo-MBR is by definition a linked list, beginning
with the extended partition that contains the logical partitions, and
then repeatedly occuring at the beginning of each successive logical
partition, where it defines the size and start of each logical partition
in turn.
As it currently stands, when grub is installed to a logical partition
via blocklists, grub's boot.img file is stored in the partition's boot
partition block, which is the first sector of that logical partition.
What I am proposing is that grub's core.img can be embedded in the
unused space which is part of each logical partition, that is, the
unused space from the the end of the pseudo-MBR to just prior to the
partition's boot partition block.
I will briefly give a concrete example of my proposal by using the
following partition table listings of my disk /dev/sda, as generated by
fdisk and cfdisk, respectively,
-- Fdisk Listing --
Device Boot Start End Blocks Id System
/dev/sda1 2048 8482319 4240136 b W95 FAT32
/dev/sda2 * 8482320 16964639 4241160 7 HPFS/NTFS
/dev/sda3 16964640 153324359 68179860 7 HPFS/NTFS
/dev/sda4 153324360 976768064 411721852+ f W95 Ext'd (LBA)
/dev/sda5 153326408 358827839 102750716 7 HPFS/NTFS
/dev/sda6 358829888 375663959 8417036 82 Linux swap / Solaris
/dev/sda7 375666008 396741239 10537616 83 Linux
/dev/sda8 396743288 417818519 10537616 83 Linux
/dev/sda9 417820568 438895799 10537616 83 Linux
/dev/sda10 438897848 459973079 10537616 83 Linux
/dev/sda11 459975128 481050359 10537616 83 Linux
/dev/sda12 481052408 502127639 10537616 83 Linux
/dev/sda13 502129688 638487359 68178836 83 Linux
/dev/sda14 638489408 843990839 102750716 83 Linux
-- Cfdisk Listing --
First Last
# Type Sector Sector Offset Length Filesystem Type (ID) Flag
-- ------- ----------- ----------- ------ ----------- -------------------- ----
None 0 2047* 0# 2048*Unusable None
1 Primary 2048* 8482319 0 8480272*W95 FAT32 (0B) None
2 Primary 8482320 16964639 0 8482320 HPFS/NTFS (07) Boot
3 Primary 16964640 153324359 0 136359720 HPFS/NTFS (07) None
4 Primary 153324360 976768064 0 823443705 W95 Ext'd (LBA) (0F) None
5 Logical 153324360 358827839 2048# 205503480 HPFS/NTFS (07) None
6 Logical 358827840 375663959 2048# 16836120 Linux swap / So (82) None
7 Logical 375663960 396741239 2048# 21077280 Linux (83) None
8 Logical 396741240 417818519 2048# 21077280 Linux (83) None
9 Logical 417818520 438895799 2048# 21077280 Linux (83) None
10 Logical 438895800 459973079 2048# 21077280 Linux (83) None
11 Logical 459973080 481050359 2048# 21077280 Linux (83) None
12 Logical 481050360 502127639 2048# 21077280 Linux (83) None
13 Logical 502127640 638487359 2048# 136359720 Linux (83) None
14 Logical 638487360 843990839 2048# 205503480 Linux (83) None
Logical 843990840 976768064 0 132777225 Free Space None
I will use /dev/sda7, where the grub-install originally failed,
According to cfdisk, the pseudo-MBR is located at sector 375663960,
which is 1 sector after the end of partition sda6.
According to fdisk, the boot partition block is located at sector
375666008, which is 2048 sectors after sector 375663960.
Therefore, grub's core.img can be placed anywhere in the unused space
located from sector 375663961 (375663960+1) to sector 375666007 (375666008-1),
while grub's boot.img would be placed in its usual location within the boot
partition block at sector 375666008.
For best efficiency with modern disks with 4k physical sectors, grub's
core.img should begin at an LBA (512 byte sector) that is on an 8 (LBA)
sector boundary.
I close with one additional observation - with grub-legacy it is currently
possible to embed grub-legacy within a logical partition as described above,
by using /bin/dd and the expert's grub install command.
However, I can find no such work-around available to embed grub-pc within a
logical partition.
Thanks,
Jeffrey Sheinberg
-- Package-specific info:
*********************** WARNING grub-setup left core.img in filesystem
*********************** BEGIN /proc/mounts
/dev/sda7 / ext3 rw,relatime,grpid,data=ordered,jqfmt=vfsv0,usrjquota=aquota.user 0 0
/dev/sda8 /fs/dc ext3 rw,relatime,grpid,data=ordered,jqfmt=vfsv0,usrjquota=aquota.user 0 0
/dev/sda9 /fs/dh ext3 rw,relatime,grpid,data=ordered,jqfmt=vfsv0,usrjquota=aquota.user 0 0
*********************** END /proc/mounts
*********************** BEGIN /boot/grub/device.map
(hd0) /dev/disk/by-id/ata-WDC_WD5000AAKS-75V0A0_WD-WCAWF0177971
(hd1) /dev/disk/by-id/ata-WDC_WD5000AAKS-00V1A0_WD-WMAWF1203364
(hd2) /dev/disk/by-id/usb-Kingston_DataTraveler_2.0_899801162008011514259E4E-0:0
*********************** END /boot/grub/device.map
*********************** BEGIN /boot/grub/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}
function load_video {
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
}
terminal_input console
terminal_output console
set timeout=29
play 480 440 1
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
### END /etc/grub.d/05_debian_theme ###
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Debian GNU/Linux, with Linux 2.6.38-bpo.2-amd64' --class debian --class gnu-linux --class gnu --class os {
insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set d19e208c-a52b-4988-b9d1-faf76e0ae559
echo 'Loading Linux 2.6.38-bpo.2-amd64 ...'
linux /boot/vmlinuz-2.6.38-bpo.2-amd64 root=/dev/sda7 ro
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.38-bpo.2-amd64
}
menuentry 'Debian GNU/Linux, with Linux 2.6.32-5-amd64' --class debian --class gnu-linux --class gnu --class os {
insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set d19e208c-a52b-4988-b9d1-faf76e0ae559
echo 'Loading Linux 2.6.32-5-amd64 ...'
linux /boot/vmlinuz-2.6.32-5-amd64 root=/dev/sda7 ro
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.32-5-amd64
}
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###
### BEGIN /etc/grub.d/20_memtest86 ###
menuentry "Memory test (memtest86)" {
linux16 /boot/memtest86.bin
}
### END /etc/grub.d/20_memtest86 ###
### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set d19e208c-a52b-4988-b9d1-faf76e0ae559
linux16 /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set d19e208c-a52b-4988-b9d1-faf76e0ae559
linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
menuentry "Memory test (memtest86+, experimental multiboot)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set d19e208c-a52b-4988-b9d1-faf76e0ae559
multiboot /boot/memtest86+_multiboot.bin
}
menuentry "Memory test (memtest86+, serial console 115200, experimental multiboot)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos7)'
search --no-floppy --fs-uuid --set d19e208c-a52b-4988-b9d1-faf76e0ae559
multiboot /boot/memtest86+_multiboot.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###
### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Debian GNU/Linux, with Linux 2.6.32-5-amd64 (on /dev/sda10)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos10)'
search --no-floppy --fs-uuid --set e3fd53ab-0f8c-422c-b99e-cabfcad65068
linux /boot/vmlinuz-2.6.32-5-amd64 root=/dev/sda7 ro
initrd /boot/initrd.img-2.6.32-5-amd64
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-5-686 (on /dev/sda10)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos10)'
search --no-floppy --fs-uuid --set e3fd53ab-0f8c-422c-b99e-cabfcad65068
linux /boot/vmlinuz-2.6.32-5-686 root=/dev/sda7 ro
initrd /boot/initrd.img-2.6.32-5-686
}
menuentry "Windows 7 (loader) (on /dev/sda2)" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 9a0286ed0286cda7
chainloader +1
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-5-amd64 (on /dev/sdb10)" {
insmod part_msdos
insmod ext2
set root='(hd1,msdos10)'
search --no-floppy --fs-uuid --set e6730c78-dd18-482c-b693-bd5996d3fe78
linux /boot/vmlinuz-2.6.32-5-amd64 root=/dev/sda7 ro
initrd /boot/initrd.img-2.6.32-5-amd64
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-5-686 (on /dev/sdb10)" {
insmod part_msdos
insmod ext2
set root='(hd1,msdos10)'
search --no-floppy --fs-uuid --set e6730c78-dd18-482c-b693-bd5996d3fe78
linux /boot/vmlinuz-2.6.32-5-686 root=/dev/sda7 ro
initrd /boot/initrd.img-2.6.32-5-686
}
menuentry "Windows 7 (loader) (on /dev/sdb2)" {
insmod part_msdos
insmod ntfs
set root='(hd1,msdos2)'
search --no-floppy --fs-uuid --set 9a0286ed0286cda7
chainloader +1
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-5-amd64 (on /dev/sdb7)" {
insmod part_msdos
insmod ext2
set root='(hd1,msdos7)'
search --no-floppy --fs-uuid --set 0d9545e8-22a8-4cb5-ad88-aadf1785c121
linux /boot/vmlinuz-2.6.32-5-amd64 root=/dev/sda7 ro
initrd /boot/initrd.img-2.6.32-5-amd64
}
menuentry "Debian GNU/Linux, with Linux 2.6.32-5-686 (on /dev/sdb7)" {
insmod part_msdos
insmod ext2
set root='(hd1,msdos7)'
search --no-floppy --fs-uuid --set 0d9545e8-22a8-4cb5-ad88-aadf1785c121
linux /boot/vmlinuz-2.6.32-5-686 root=/dev/sda7 ro
initrd /boot/initrd.img-2.6.32-5-686
}
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/41_custom ###
if [ -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
*********************** END /boot/grub/grub.cfg
-- System Information:
Debian Release: 6.0.2
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 'stable')
Architecture: i386 (x86_64)
Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash
Versions of packages grub-pc depends on:
ii debconf [debconf-2.0] 1.5.36.1 Debian configuration management sy
ii grub-common 1.98+20100804-14 GRand Unified Bootloader, version
ii libc6 2.11.2-10 Embedded GNU C Library: Shared lib
ii libdevmapper1.02.1 2:1.02.48-5 The Linux Kernel Device Mapper use
ii ucf 3.0025+nmu1 Update Configuration File: preserv
grub-pc recommends no packages.
Versions of packages grub-pc suggests:
pn desktop-base <none> (no description available)
-- debconf information:
grub2/kfreebsd_cmdline:
grub2/device_map_regenerated:
* grub2/linux_cmdline:
* grub-pc/install_devices_empty: true
grub-pc/install_devices_failed: false
* grub-pc/chainload_from_menu.lst: true
grub-pc/kopt_extracted: true
* grub-pc/install_devices:
grub-pc/postrm_purge_boot_grub: false
grub-pc/install_devices_failed_upgrade: true
grub-pc/disk_description:
grub2/kfreebsd_cmdline_default: quiet
grub-pc/partition_description:
grub-pc/install_devices_disks_changed:
* grub2/linux_cmdline_default:
grub-pc/mixed_legacy_and_grub2: true
More information about the Pkg-grub-devel
mailing list