gptsync
PATCH 1/1 gptsync
Hello, this is a common way to boot non GPT-aware OS on GPT systems. For this protective MBR is replaced by a so-called hybrid mbr where first partition entry is a protective entry and the rest contains legal partitions. So here is the syntax:
gptsync DISK [PARTITIONSPEC1] [PARTITIONSPEC2] [PARTITIONSPEC3] PARTITIONSPEC says which partitions have to be shown to legacy OS. It always begins with the partition number. Then optionally goes one of the following:
nothing. Autodetect partition type, not active partition
"+". Like preceding but make partition active
"-TYPE". Use TYPE type as MBR partition type
"+TYPE". Like preceding but make partition active
commands/gptsync.c new file +240 -0
@@ -0,0 +1,240 @@ +/* gptsync.c - fill the mbr based on gpt entries */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2003,2005,2007,2008 Free Software Foundation, Inc. +* +* GRUB 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. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/command.h> +#include <grub/dl.h> +#include <grub/device.h> +#include <grub/disk.h> +#include <grub/pc_partition.h> +#include <grub/partition.h> +#include <grub/misc.h> +#include <grub/mm.h> +#include <grub/fs.h> + +/* Convert a LBA address to a CHS address in the INT 13 format. */ +/* Taken from grub1. */ +/* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63. +Is it a problem? +*/ +static void +lba_to_chs (grub_disk_addr_t lba,grub_uint8_t *cl,grub_uint8_t *ch, +grub_uint8_t *dh) +{ +int cylinder, head, sector; +int sectors =63 , heads =255 , cylinders =1024 ; + + sector = lba % sectors +1 ; + head = (lba / sectors) % heads; + cylinder = lba / (sectors * heads); + +if (cylinder >= cylinders) + { + *cl = *ch = *dh =0xff ; +return ; + } + + *cl = sector | ((cylinder &0x300 ) >>2 ); + *ch = cylinder &0xFF ; + *dh = head; +} + + +static grub_err_t +grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)), +int argc,char **args) +{ +grub_device_t dev; +struct grub_pc_partition_mbr mbr; +struct grub_partition *partition; +grub_disk_addr_t first_sector; +int numactive =0 ; + +if (argc <1 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"device name required" ); +if (argc >4 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"only 3 partitions can be " +"in hybrid MBR" ); + +if (args[0 ][0 ] =='(' && args[0 ][grub_strlen (args[0 ]) -1 ] ==')' ) + { + args[0 ][grub_strlen (args[0 ]) -1 ] =0 ; + dev =grub_device_open (args[0 ] +1 ); + args[0 ][grub_strlen (args[0 ]) -1 ] =')' ; + } +else + dev =grub_device_open (args[0 ]); + +if (! dev) +return grub_errno; + +if (! dev->disk) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"not a disk" ); + } + +/* Read the protective MBR. */ +if (grub_disk_read (dev->disk,0 ,0 ,sizeof (mbr), (char *) &mbr)) + { +grub_device_close (dev); +return grub_errno; + } + +/* Check if it is valid. */ +if (mbr.signature !=grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE )) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_PART_TABLE ,"no signature" ); + } + +/* Make sure the MBR is a protective MBR and not a normal MBR. */ +if (mbr.entries[0 ].type !=GRUB_PC_PARTITION_TYPE_GPT_DISK ) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_PART_TABLE ,"no GPT partition map found" ); + } + +int i; + first_sector = dev->disk->total_sectors; +for (i =1 ; i < argc; i++) + { +char *separator, csep =0 ; +grub_uint8_t type; + separator =grub_strchr (args[i],'+' ); +if (! separator) + separator =grub_strchr (args[i],'-' ); +if (separator) + { + csep = *separator; + *separator =0 ; + } + partition =grub_partition_probe (dev->disk, args[i]); +if (separator) + *separator = csep; +if (! partition) + { + +grub_device_close (dev); +return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"no such partition" ); + } + +if (first_sector > partition->start -1 ) + first_sector = partition->start -1 ; + +if (separator && *(separator +1 )) + type =grub_strtoul (separator +1 ,0 ,0 ); +else + { +grub_fs_t fs =0 ; + dev->disk->partition = partition; + fs =grub_fs_probe (dev); + +/* Unknown filesystem isn't fatal. */ +if (grub_errno ==GRUB_ERR_UNKNOWN_FS ) + { + fs =0 ; + grub_errno =GRUB_ERR_NONE ; + } + +if (fs &&grub_strcmp (fs->name,"ntfs" ) ==0 ) + type =GRUB_PC_PARTITION_TYPE_NTFS ; +else if (fs &&grub_strcmp (fs->name,"fat" ) ==0 ) +/* FIXME: detect FAT16. */ + type =GRUB_PC_PARTITION_TYPE_FAT32_LBA ; +else +/* FIXME: detect more types. */ + type =GRUB_PC_PARTITION_TYPE_EXT2FS ; + + dev->disk->partition =0 ; + } + + mbr.entries[i].flag = (csep =='+' ) ?0x80 :0 ; +if (csep =='+' ) + { + numactive++; +if (numactive ==2 ) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_ARGUMENT , +"only one partition can be active" ); + } + } + mbr.entries[i].type = type; + mbr.entries[i].start =grub_cpu_to_le32 (partition->start); +lba_to_chs (partition->start, + &(mbr.entries[i].start_sector), + &(mbr.entries[i].start_cylinder), + &(mbr.entries[i].start_head)); +lba_to_chs (partition->start + partition->len, + &(mbr.entries[i].end_sector), + &(mbr.entries[i].end_cylinder), + &(mbr.entries[i].end_head)); + mbr.entries[i].length =grub_cpu_to_le32 (partition->len); +grub_free (partition); + } +for (; i <4 ; i++) +grub_memset (&(mbr.entries[i]),0 ,sizeof (mbr.entries[i])); + +/* The protective partition. */ + mbr.entries[0 ].flag =0 ; + mbr.entries[0 ].type =GRUB_PC_PARTITION_TYPE_GPT_DISK ; + mbr.entries[0 ].start =grub_cpu_to_le32 (1 ); +lba_to_chs (1 , + &(mbr.entries[0 ].start_sector), + &(mbr.entries[0 ].start_cylinder), + &(mbr.entries[0 ].start_head)); +lba_to_chs (first_sector, + &(mbr.entries[0 ].end_sector), + &(mbr.entries[0 ].end_cylinder), + &(mbr.entries[0 ].end_head)); + mbr.entries[0 ].length =grub_cpu_to_le32 (first_sector); + + mbr.signature =grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE ); + +if (grub_disk_write (dev->disk,0 ,0 ,sizeof (mbr), (char *) &mbr)) + { +grub_device_close (dev); +return grub_errno; + } + +grub_printf ("New MBR is written to '%s'\n" , args[0 ]); + +return GRUB_ERR_NONE ; +} + + +static grub_command_t cmd; + +GRUB_MOD_INIT (gptsync) +{ + (void ) mod;/* To stop warning. */ + cmd =grub_register_command ("gptsync" , grub_cmd_gptsync, +"gptsync DEVICE [PARTITION[+/-[TYPE]]] ..." , +"Fill hybrid MBR of GPT drive DEVICE. " +"specified partitions will be a part " +"of hybrid mbr. Up to 3 partitions are " +"allowed. TYPE is an MBR type. " +"+ means that partition is active. " +"Only one partition can be active" ); +} + +GRUB_MOD_FINI (gptsync) +{ +grub_unregister_command (cmd); +}
conf/i386-coreboot.rmk +1 -0
@@ -59,6 +59,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/echo.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ + commands/gptsync.c \ lib/hexdump.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c \ \
conf/i386-ieee1275.rmk +1 -1
@@ -59,7 +59,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/halt.c commands/reboot.c \ - commands/i386/cpuid.c \ + commands/gptsync.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
conf/i386-pc.rmk +1 -1
@@ -123,7 +123,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \ - commands/i386/cpuid.c \ + commands/gptsync.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c disk/scsi.c \ fs/fshelp.c \ \
conf/powerpc-ieee1275.rmk +2 -1
@@ -43,7 +43,8 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ commands/search.c commands/handler.c commands/test.c \ commands/ls.c commands/blocklist.c commands/hexdump.c \ - lib/hexdump.c commands/halt.c commands/reboot.c \ + lib/hexdump.c commands/halt.c commands/reboot.c \ + commands/gptsync.c \ disk/loopback.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
include/grub/pc_partition.h +1 -0
@@ -35,6 +35,7 @@#define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4#define GRUB_PC_PARTITION_TYPE_EXTENDED 5#define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6 +#define GRUB_PC_PARTITION_TYPE_NTFS 7#define GRUB_PC_PARTITION_TYPE_FAT32 0xb#define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc#define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
Hi,
Compiled with rev 2121, --with-platform=efi but got no gptsync module. It could be a useful tool for macs, I would like to try it.
Quoted 21 lines · Vladimir Serbinenko
Hello, this is a common way to boot non GPT-aware OS on GPT systems. For this protective MBR is replaced by a so-called hybrid mbr where first partition entry is a protective entry and the rest contains legal partitions. So here is the syntax:
gptsync DISK [PARTITIONSPEC1] [PARTITIONSPEC2] [PARTITIONSPEC3] PARTITIONSPEC says which partitions have to be shown to legacy OS. It always begins with the partition number. Then optionally goes one of the following:
nothing. Autodetect partition type, not active partition "+". Like preceding but make partition active
"-TYPE". Use TYPE type as MBR partition type
"+TYPE". Like preceding but make partition active_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Cros (pxw)
My bad. Part of the patch was missing. Here is a corrected version with sanity checks for 2TB limit and some CHS fixes
Quoted 34 lines · Peter Cros
Hi,
Compiled with rev 2121, --with-platform=efi but got no gptsync module. It could be a useful tool for macs, I would like to try it.Quoted 15 lines · Vladimir Serbinenko
Hello, this is a common way to boot non GPT-aware OS on GPT systems. For this protective MBR is replaced by a so-called hybrid mbr where first partition entry is a protective entry and the rest contains legal partitions. So here is the syntax:
gptsync DISK [PARTITIONSPEC1] [PARTITIONSPEC2] [PARTITIONSPEC3] PARTITIONSPEC says which partitions have to be shown to legacy OS. It always begins with the partition number. Then optionally goes one of the following:
nothing. Autodetect partition type, not active partition "+". Like preceding but make partition active
"-TYPE". Use TYPE type as MBR partition type
"+TYPE". Like preceding but make partition activeQuoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel--
Cros (pxw)
Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
commands/gptsync.c new file +252 -0
@@ -0,0 +1,252 @@ +/* gptsync.c - fill the mbr based on gpt entries */ +/* XXX: I don't know what to do if sector size isn't 512 bytes */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2009 Free Software Foundation, Inc. +* +* GRUB 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. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/command.h> +#include <grub/dl.h> +#include <grub/device.h> +#include <grub/disk.h> +#include <grub/pc_partition.h> +#include <grub/partition.h> +#include <grub/misc.h> +#include <grub/mm.h> +#include <grub/fs.h> + +/* Convert a LBA address to a CHS address in the INT 13 format. */ +/* Taken from grub1. */ +/* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63. +Is it a problem? +*/ +static void +lba_to_chs (int lba,grub_uint8_t *cl,grub_uint8_t *ch, +grub_uint8_t *dh) +{ +int cylinder, head, sector; +int sectors =63 , heads =255 , cylinders =1024 ; + + sector = lba % sectors +1 ; + head = (lba / sectors) % heads; + cylinder = lba / (sectors * heads); + +if (cylinder >= cylinders) + { + *cl = *ch = *dh =0xff ; +return ; + } + + *cl = sector | ((cylinder &0x300 ) >>2 ); + *ch = cylinder &0xFF ; + *dh = head; +} + +static grub_err_t +grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)), +int argc,char **args) +{ +grub_device_t dev; +struct grub_pc_partition_mbr mbr; +struct grub_partition *partition; +grub_disk_addr_t first_sector; +int numactive =0 ; + +if (argc <1 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"device name required" ); +if (argc >4 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"only 3 partitions can be " +"in hybrid MBR" ); + +if (args[0 ][0 ] =='(' && args[0 ][grub_strlen (args[0 ]) -1 ] ==')' ) + { + args[0 ][grub_strlen (args[0 ]) -1 ] =0 ; + dev =grub_device_open (args[0 ] +1 ); + args[0 ][grub_strlen (args[0 ]) -1 ] =')' ; + } +else + dev =grub_device_open (args[0 ]); + +if (! dev) +return grub_errno; + +if (! dev->disk) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"not a disk" ); + } + +/* Read the protective MBR. */ +if (grub_disk_read (dev->disk,0 ,0 ,sizeof (mbr), (char *) &mbr)) + { +grub_device_close (dev); +return grub_errno; + } + +/* Check if it is valid. */ +if (mbr.signature !=grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE )) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_PART_TABLE ,"no signature" ); + } + +/* Make sure the MBR is a protective MBR and not a normal MBR. */ +if (mbr.entries[0 ].type !=GRUB_PC_PARTITION_TYPE_GPT_DISK ) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_PART_TABLE ,"no GPT partition map found" ); + } + +int i; + first_sector = dev->disk->total_sectors; +for (i =1 ; i < argc; i++) + { +char *separator, csep =0 ; +grub_uint8_t type; + separator =grub_strchr (args[i],'+' ); +if (! separator) + separator =grub_strchr (args[i],'-' ); +if (separator) + { + csep = *separator; + *separator =0 ; + } + partition =grub_partition_probe (dev->disk, args[i]); +if (separator) + *separator = csep; +if (! partition) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"no such partition" ); + } + +if (partition->start + partition->len >0xffffffff ) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_OUT_OF_RANGE , +"only partitions resding in the first 2TB " +"can be presen in hybrid MBR" ); + } + + +if (first_sector > partition->start) + first_sector = partition->start; + +if (separator && *(separator +1 )) + type =grub_strtoul (separator +1 ,0 ,0 ); +else + { +grub_fs_t fs =0 ; + dev->disk->partition = partition; + fs =grub_fs_probe (dev); + +/* Unknown filesystem isn't fatal. */ +if (grub_errno ==GRUB_ERR_UNKNOWN_FS ) + { + fs =0 ; + grub_errno =GRUB_ERR_NONE ; + } + +if (fs &&grub_strcmp (fs->name,"ntfs" ) ==0 ) + type =GRUB_PC_PARTITION_TYPE_NTFS ; +else if (fs &&grub_strcmp (fs->name,"fat" ) ==0 ) +/* FIXME: detect FAT16. */ + type =GRUB_PC_PARTITION_TYPE_FAT32_LBA ; +else +/* FIXME: detect more types. */ + type =GRUB_PC_PARTITION_TYPE_EXT2FS ; + + dev->disk->partition =0 ; + } + + mbr.entries[i].flag = (csep =='+' ) ?0x80 :0 ; +if (csep =='+' ) + { + numactive++; +if (numactive ==2 ) + { +grub_device_close (dev); +return grub_error (GRUB_ERR_BAD_ARGUMENT , +"only one partition can be active" ); + } + } + mbr.entries[i].type = type; + mbr.entries[i].start =grub_cpu_to_le32 (partition->start); +lba_to_chs (partition->start, + &(mbr.entries[i].start_sector), + &(mbr.entries[i].start_cylinder), + &(mbr.entries[i].start_head)); +lba_to_chs (partition->start + partition->len -1 , + &(mbr.entries[i].end_sector), + &(mbr.entries[i].end_cylinder), + &(mbr.entries[i].end_head)); + mbr.entries[i].length =grub_cpu_to_le32 (partition->len); +grub_free (partition); + } +for (; i <4 ; i++) +grub_memset (&(mbr.entries[i]),0 ,sizeof (mbr.entries[i])); + +/* The protective partition. */ +if (first_sector >0xffffffff ) + first_sector =0xffffffff ; +else + first_sector--; + mbr.entries[0 ].flag =0 ; + mbr.entries[0 ].type =GRUB_PC_PARTITION_TYPE_GPT_DISK ; + mbr.entries[0 ].start =grub_cpu_to_le32 (1 ); +lba_to_chs (1 , + &(mbr.entries[0 ].start_sector), + &(mbr.entries[0 ].start_cylinder), + &(mbr.entries[0 ].start_head)); +lba_to_chs (first_sector, + &(mbr.entries[0 ].end_sector), + &(mbr.entries[0 ].end_cylinder), + &(mbr.entries[0 ].end_head)); + mbr.entries[0 ].length =grub_cpu_to_le32 (first_sector); + + mbr.signature =grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE ); + +if (grub_disk_write (dev->disk,0 ,0 ,sizeof (mbr), (char *) &mbr)) + { +grub_device_close (dev); +return grub_errno; + } + +grub_printf ("New MBR is written to '%s'\n" , args[0 ]); + +return GRUB_ERR_NONE ; +} + + +static grub_command_t cmd; + +GRUB_MOD_INIT (gptsync) +{ + (void ) mod;/* To stop warning. */ + cmd =grub_register_command ("gptsync" , grub_cmd_gptsync, +"gptsync DEVICE [PARTITION[+/-[TYPE]]] ..." , +"Fill hybrid MBR of GPT drive DEVICE. " +"specified partitions will be a part " +"of hybrid mbr. Up to 3 partitions are " +"allowed. TYPE is an MBR type. " +"+ means that partition is active. " +"Only one partition can be active" ); +} + +GRUB_MOD_FINI (gptsync) +{ +grub_unregister_command (cmd); +}
conf/common.rmk +6 -1
@@ -343,7 +343,12 @@ pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ loopback.mod fs_uuid.mod configfile.mod echo.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \ - pcpart.mod memrw.mod boot.mod + pcpart.mod memrw.mod boot.mod gptsync.mod + +# For gptsync.mod. +gptsync_mod_SOURCES = commands/gptsync.c +gptsync_mod_CFLAGS = $(COMMON_CFLAGS) +gptsync_mod_LDFLAGS = $(COMMON_LDFLAGS) # For boot.mod. boot_mod_SOURCES = commands/boot.c
conf/i386-coreboot.rmk +1 -0
@@ -59,6 +59,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/echo.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ + commands/gptsync.c \ lib/hexdump.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c \ \
conf/i386-ieee1275.rmk +1 -1
@@ -59,7 +59,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/halt.c commands/reboot.c \ - commands/i386/cpuid.c \ + commands/gptsync.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
conf/i386-pc.rmk +1 -1
@@ -123,7 +123,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \ - commands/i386/cpuid.c \ + commands/gptsync.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c disk/scsi.c \ fs/fshelp.c \ \
conf/powerpc-ieee1275.rmk +2 -1
@@ -43,7 +43,8 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ commands/search.c commands/handler.c commands/test.c \ commands/ls.c commands/blocklist.c commands/hexdump.c \ - lib/hexdump.c commands/halt.c commands/reboot.c \ + lib/hexdump.c commands/halt.c commands/reboot.c \ + commands/gptsync.c \ disk/loopback.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
include/grub/pc_partition.h +1 -0
@@ -35,6 +35,7 @@#define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4#define GRUB_PC_PARTITION_TYPE_EXTENDED 5#define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6 +#define GRUB_PC_PARTITION_TYPE_NTFS 7#define GRUB_PC_PARTITION_TYPE_FAT32 0xb#define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc#define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
Hi,
I have been playing with grub gptsync, on apple intel mac with GUID partitioned 8 GB usb stick, 8 partitions. #1 is the standard fat32 EFI system part for macs.
I am comparing with the gptsync utility from linux, or rEFIt gptsync, currently used for macs booting pc-bios bootloader.
It is working to allow selection of GPT partions for MBR 2, 3, 4 but some of the numbers look wrong. I have not tried setting flags.
grub gptsync is not handling MBR partition table 1 the same way as current linux or refit gptsync, which puts GPT partition 1 (EFI system FAT32) in MBR part1.
GPT Partions are
(512 byte sectors)
Current GPT partition table:
# Start LBA End LBA Type 1 40 409639 EFI System (FAT) 2 409640 2395367 Mac OS X HFS+ 3 2395368 4573255 Mac OS X HFS+ 4 4835400 7141399 Mac OS X HFS+ 5 7403544 9965767 Mac OS X HFS+ 6 10227912 13046359 Mac OS X HFS+ 7 13308504 15642623 Mac OS X HFS+ 8 15904768 15949783 Mac OS X HFS+
There seems to be agreement about start and end on MBR table partitions 2 3 4, using grub> gptsync (hd0) 2 3 4.
Other bytes differ (type, flags).
This is after grub> gptsync (hd0) 2 3 4
(MBR part1 was initially set by linux gptsync)
pxw@im81:~$ sudo hexdump -Cn80 -s432 /dev/sdb [sudo] password for pxw: 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001c0 02 00 ee 7f 0e 19 01 00 00 00 27 40 06 00 00 7f |..........'@....| 000001d0 0f 19 83 1a 2d 95 28 40 06 00 c0 4c 1e 00 00 1a |....-.(@...L....| 000001e0 2e 95 83 ab 57 1c e8 8c 24 00 60 3b 21 00 00 fc |....W...$.`;!...| 000001f0 59 2c 83 87 63 bc 48 c8 49 00 d0 2f 23 00 55 aa |Y,..c.H.I../#.U.| 00000200
Then as seen in linux gptsync,
Current MBR partition table:
# A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 409640 2395367 83 Linux 3 2395368 4573255 83 Linux 4 4835400 7141399 83 Linux
Status: MBR table must be updated.
Proposed new MBR partition table:
# A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 * 409640 2395367 af Mac OS X HFS+ 3 2395368 4573255 af Mac OS X HFS+ 4 4835400 7141399 af Mac OS X HFS+
May I update the MBR as printed above? [y/N] y
Yes
pxw@im81:~$ sudo hexdump -Cn80 -s432 /dev/sdb 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe |................| 000001c0 ff ff ee fe ff ff 01 00 00 00 27 40 06 00 80 fe |..........'@....| 000001d0 ff ff af fe ff ff 28 40 06 00 c0 4c 1e 00 00 fe |......(@...L....| 000001e0 ff ff af fe ff ff e8 8c 24 00 60 3b 21 00 00 fe |........$.`;!...| 000001f0 ff ff af fe ff ff 48 c8 49 00 d0 2f 23 00 55 aa |......H.I../#.U.| 00000200
Signature · 1 line
Cros (pxw)
Quoted 9 lines · Peter Cros
Hi,
I have been playing with grub gptsync, on apple intel mac with GUID partitioned 8 GB usb stick, 8 partitions. #1 is the standard fat32 EFI system part for macs.
I am comparing with the gptsync utility from linux, or rEFIt gptsync, currently used for macs booting pc-bios bootloader.
Quoted 7 lines
It is working to allow selection of GPT partions for MBR 2, 3, 4 but some of the numbers look wrong. I have not tried setting flags.
grub gptsync is not handling MBR partition table 1 the same way as current linux or refit gptsync, which puts GPT partition 1 (EFI system FAT32) in MBR part1.
I don't understand what you mean. I will not do any special treatment for EFI system partition. As far as I'm concerned it's just a partition. I don't think it's a problem since user can ask which partitions to put in MBR
Quoted 47 lines
GPT Partions are
(512 byte sectors)
Current GPT partition table:# Start LBA End LBA Type 1 40 409639 EFI System (FAT) 2 409640 2395367 Mac OS X HFS+ 3 2395368 4573255 Mac OS X HFS+ 4 4835400 7141399 Mac OS X HFS+ 5 7403544 9965767 Mac OS X HFS+ 6 10227912 13046359 Mac OS X HFS+ 7 13308504 15642623 Mac OS X HFS+ 8 15904768 15949783 Mac OS X HFS+There seems to be agreement about start and end on MBR table partitions 2 3 4, using grub> gptsync (hd0) 2 3 4.
Other bytes differ (type, flags).This is after grub> gptsync (hd0) 2 3 4
(MBR part1 was initially set by linux gptsync)pxw@im81:~$ sudo hexdump -Cn80 -s432 /dev/sdb [sudo] password for pxw: 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001c0 02 00 ee 7f 0e 19 01 00 00 00 27 40 06 00 00 7f |..........'@....| 000001d0 0f 19 83 1a 2d 95 28 40 06 00 c0 4c 1e 00 00 1a |....-.(@...L....| 000001e0 2e 95 83 ab 57 1c e8 8c 24 00 60 3b 21 00 00 fc |....W...$.`;!...| 000001f0 59 2c 83 87 63 bc 48 c8 49 00 d0 2f 23 00 55 aa |Y,..c.H.I../#.U.| 00000200Then as seen in linux gptsync,
Current MBR partition table:
# A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 409640 2395367 83 Linux 3 2395368 4573255 83 Linux 4 4835400 7141399 83 LinuxStatus: MBR table must be updated.
Quoted 9 lines
Proposed new MBR partition table:
# A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 * 409640 2395367 af Mac OS X HFS+ 3 2395368 4573255 af Mac OS X HFS+ 4 4835400 7141399 af Mac OS X HFS+May I update the MBR as printed above? [y/N] y
Yes
Here there are 2 differences. First partition type for hfs+ isn't autodetected, I will fix this, just I thought it ws unnecessary AFAIK every OS which understands HFS+ understands GPT. The second thing is that none of partiion is active. Here you have just to tell which partition is active. You can have the same behavior as OSX gptsync with command gptsync hd0 2+0xaf 3-0xaf 4-0xaf
Once I add hfs+ autodetect it will be enough to do
gptsync hd0 2+ 3 4
Quoted 27 lines
pxw@im81:~$ sudo hexdump -Cn80 -s432 /dev/sdb 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe |................| 000001c0 ff ff ee fe ff ff 01 00 00 00 27 40 06 00 80 fe |..........'@....| 000001d0 ff ff af fe ff ff 28 40 06 00 c0 4c 1e 00 00 fe |......(@...L....| 000001e0 ff ff af fe ff ff e8 8c 24 00 60 3b 21 00 00 fe |........$.`;!...| 000001f0 ff ff af fe ff ff 48 c8 49 00 d0 2f 23 00 55 aa |......H.I../#.U.| 00000200--
Cros (pxw)_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
There appears to be a small bug there.
For example -
gptsync (hd0) 4 2 3
will write data for GPT partition 4 2 3 to MBR partition table 2 3 4 but also GPT partition 1 to MBR partition 1 (which is actually what happens now for intel mac.)
And similarly for other selections will write the next lower gpt partition number to MBR partition 1 slot.
I don't think it is compatible with current MBR/GPT hybrid partitioning on intel macs for grub-pc booting.
Quoted 123 lines · Vladimir Serbinenko
Quoted 9 lines · Peter Cros
Hi,
I have been playing with grub gptsync, on apple intel mac with GUID partitioned 8 GB usb stick, 8 partitions. #1 is the standard fat32 EFI system part for macs.
I am comparing with the gptsync utility from linux, or rEFIt gptsync, currently used for macs booting pc-bios bootloader.
Quoted 7 lines
It is working to allow selection of GPT partions for MBR 2, 3, 4 but some of the numbers look wrong. I have not tried setting flags.
grub gptsync is not handling MBR partition table 1 the same way as current linux or refit gptsync, which puts GPT partition 1 (EFI system FAT32) in MBR part1.
I don't understand what you mean. I will not do any special treatment for EFI system partition. As far as I'm concerned it's just a partition. I don't think it's a problem since user can ask which partitions to put in MBR
Quoted 47 lines
GPT Partions are
(512 byte sectors)
Current GPT partition table:# Start LBA End LBA Type 1 40 409639 EFI System (FAT) 2 409640 2395367 Mac OS X HFS+ 3 2395368 4573255 Mac OS X HFS+ 4 4835400 7141399 Mac OS X HFS+ 5 7403544 9965767 Mac OS X HFS+ 6 10227912 13046359 Mac OS X HFS+ 7 13308504 15642623 Mac OS X HFS+ 8 15904768 15949783 Mac OS X HFS+There seems to be agreement about start and end on MBR table partitions 2 3 4, using grub> gptsync (hd0) 2 3 4.
Other bytes differ (type, flags).This is after grub> gptsync (hd0) 2 3 4
(MBR part1 was initially set by linux gptsync)pxw@im81:~$ sudo hexdump -Cn80 -s432 /dev/sdb [sudo] password for pxw: 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001c0 02 00 ee 7f 0e 19 01 00 00 00 27 40 06 00 00 7f |..........'@....| 000001d0 0f 19 83 1a 2d 95 28 40 06 00 c0 4c 1e 00 00 1a |....-.(@...L....| 000001e0 2e 95 83 ab 57 1c e8 8c 24 00 60 3b 21 00 00 fc |....W...$.`;!...| 000001f0 59 2c 83 87 63 bc 48 c8 49 00 d0 2f 23 00 55 aa |Y,..c.H.I../#.U.| 00000200Then as seen in linux gptsync,
Current MBR partition table:
# A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 409640 2395367 83 Linux 3 2395368 4573255 83 Linux 4 4835400 7141399 83 LinuxStatus: MBR table must be updated.
Quoted 9 lines
Proposed new MBR partition table:
# A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 * 409640 2395367 af Mac OS X HFS+ 3 2395368 4573255 af Mac OS X HFS+ 4 4835400 7141399 af Mac OS X HFS+May I update the MBR as printed above? [y/N] y
YesHere there are 2 differences. First partition type for hfs+ isn't autodetected, I will fix this, just I thought it ws unnecessary AFAIK every OS which understands HFS+ understands GPT. The second thing is that none of partiion is active. Here you have just to tell which partition is active. You can have the same behavior as OSX gptsync with command gptsync hd0 2+0xaf 3-0xaf 4-0xaf
Once I add hfs+ autodetect it will be enough to do
gptsync hd0 2+ 3 4Quoted 21 lines
pxw@im81:~$ sudo hexdump -Cn80 -s432 /dev/sdb 000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe |................| 000001c0 ff ff ee fe ff ff 01 00 00 00 27 40 06 00 80 fe |..........'@....| 000001d0 ff ff af fe ff ff 28 40 06 00 c0 4c 1e 00 00 fe |......(@...L....| 000001e0 ff ff af fe ff ff e8 8c 24 00 60 3b 21 00 00 fe |........$.`;!...| 000001f0 ff ff af fe ff ff 48 c8 49 00 d0 2f 23 00 55 aa |......H.I../#.U.| 00000200--
Cros (pxw)Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 1 line
Cros (pxw)
Quoted 2 lines · Peter Cros
I don't think it is compatible with current MBR/GPT hybrid ?partitioning on intel macs for grub-pc booting.
well, it doesn't necessarily order the partitions in the same way as e.g. rEFIt gptsync does, but that's because this GRUB implementation gives you more control! You can even pick different MBR-partition-configurations, before booting different OSes.
Quoted 3 lines · Vladimir Serbinenko
Here there are 2 differences. First partition type for hfs+ isn't autodetected, I will fix this, just I thought it ws unnecessary AFAIK every OS which understands HFS+ understands GPT.
At least Mac OS X 10.3 and earlier don't understand GPT, and it actually makes a difference with Apple's "target disk mode"! And there may be a few other combinations.
-Isaac
Quoted 10 lines · Isaac Dupree
Quoted 1 line · Peter Cros
I don't think it is compatible with current MBR/GPT hybrid ?partitioning
on
Quoted 1 line
intel macs for grub-pc booting.
well, it doesn't necessarily order the partitions in the same way as e.g. rEFIt gptsync does, but that's because this GRUB implementation gives you more
control! You can even pick different MBR-partition-configurations, before booting different OSes.
Yes it was written with such possibility in mind. I don't see why grub2 will enforce mbr partitions to be sorted since mbr doesn't require such thing. If you ask grub2 to put partitions in reverse order it does it. As to partition in zeroth slot it spans across the space before the first MBR partition and is so called protective partition and is required for some tools including grub2 itself to recognise gpt disk as such.
About compatibiliy: hybrid MBR is against specifications - it's a trick to boot legacy OS. So the only compatibility you can speak about is the ability to boot a legacy OS of your choice.
Quoted 5 lines
Quoted 2 lines · Vladimir Serbinenko
Here there are 2 differences. First partition type for hfs+ isn't autodetected, I will fix this, just I thought it ws unnecessary AFAIK
Quoted 8 lines
every
Quoted 1 line
OS which understands HFS+ understands GPT.
At least Mac OS X 10.3 and earlier don't understand GPT, and it actually makes
a difference with Apple's "target disk mode"! And there may be a few other combinations.
Ok
Quoted 10 lines
-Isaac
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
HFS autodetect added. With changelog this time. Should already be suitable for inclusion
Quoted 34 lines · Vladimir Serbinenko
Quoted 10 lines · Isaac Dupree
Quoted 1 line · Peter Cros
I don't think it is compatible with current MBR/GPT hybrid ?partitioning
on
Quoted 1 line
intel macs for grub-pc booting.
well, it doesn't necessarily order the partitions in the same way as e.g. rEFIt gptsync does, but that's because this GRUB implementation gives you more
control! You can even pick different MBR-partition-configurations, before booting different OSes.Yes it was written with such possibility in mind. I don't see why grub2 will enforce mbr partitions to be sorted since mbr doesn't require such thing. If you ask grub2 to put partitions in reverse order it does it. As to partition in zeroth slot it spans across the space before the first MBR partition and is so called protective partition and is required for some tools including grub2 itself to recognise gpt disk as such. About compatibiliy: hybrid MBR is against specifications - it's a trick to boot legacy OS. So the only compatibility you can speak about is the ability to boot a legacy OS of your choice.
Quoted 8 lines
Quoted 2 lines · Vladimir Serbinenko
Here there are 2 differences. First partition type for hfs+ isn't autodetected, I will fix this, just I thought it ws unnecessary AFAIK
every
Quoted 1 line
OS which understands HFS+ understands GPT.
Quoted 20 lines
Quoted 6 lines
At least Mac OS X 10.3 and earlier don't understand GPT, and it actually makes
a difference with Apple's "target disk mode"! And there may be a few other
combinations.Ok
Quoted 10 lines
-Isaac
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
ChangeLog +18 -0
@@ -1,3 +1,21 @@ +2009-04-21 Vladimir Serbinenko <[email protected]> + + gptsync + + * commands/gptsync.c: new file + * conf/common.rmk (pkglib_MODULES): add gptsync.mod + (gptsync_mod_SOURCES): new variable + (gptsync_mod_CFLAGS): likewise + (gptsync_mod_LDFLAGS): likewise + * include/grub/pc_partition.h (GRUB_PC_PARTITION_TYPE_NTFS): + new definition + (GRUB_PC_PARTITION_TYPE_HFS): likewise + * conf/i386-coreboot.rmk (grub_emu_SOURCES): add commands/gptsync.c + * conf/i386-ieee1275.rmk: likewise + * conf/i386-pc.rmk: likewise + * conf/powerpc-ieee1275.rmk: likewise + + 2009-04-19 Vladimir Serbinenko <[email protected]> Correct GPT definition
commands/gptsync.c new file +255 -0
255 lines not on this page · raw message
conf/common.rmk +6 -1
@@ -343,7 +343,12 @@ pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \ loopback.mod fs_uuid.mod configfile.mod echo.mod \ terminfo.mod test.mod blocklist.mod hexdump.mod \ read.mod sleep.mod loadenv.mod crc.mod parttool.mod \ - pcpart.mod memrw.mod boot.mod + pcpart.mod memrw.mod boot.mod gptsync.mod + +# For gptsync.mod. +gptsync_mod_SOURCES = commands/gptsync.c +gptsync_mod_CFLAGS = $(COMMON_CFLAGS) +gptsync_mod_LDFLAGS = $(COMMON_LDFLAGS) # For boot.mod. boot_mod_SOURCES = commands/boot.c
conf/i386-coreboot.rmk +1 -0
@@ -59,6 +59,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/echo.c commands/help.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ + commands/gptsync.c \ lib/hexdump.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c \ \
conf/i386-ieee1275.rmk +1 -1
@@ -59,7 +59,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/halt.c commands/reboot.c \ - commands/i386/cpuid.c \ + commands/gptsync.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
conf/i386-pc.rmk +1 -1
@@ -123,7 +123,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/handler.c commands/ls.c commands/test.c \ commands/search.c commands/blocklist.c commands/hexdump.c \ lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c \ - commands/i386/cpuid.c \ + commands/gptsync.c commands/i386/cpuid.c \ disk/host.c disk/loopback.c disk/scsi.c \ fs/fshelp.c \ \
conf/powerpc-ieee1275.rmk +2 -1
@@ -43,7 +43,8 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \ commands/configfile.c commands/help.c \ commands/search.c commands/handler.c commands/test.c \ commands/ls.c commands/blocklist.c commands/hexdump.c \ - lib/hexdump.c commands/halt.c commands/reboot.c \ + lib/hexdump.c commands/halt.c commands/reboot.c \ + commands/gptsync.c \ disk/loopback.c \ \ fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
include/grub/pc_partition.h +2 -0
@@ -35,6 +35,7 @@#define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4#define GRUB_PC_PARTITION_TYPE_EXTENDED 5#define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6 +#define GRUB_PC_PARTITION_TYPE_NTFS 7#define GRUB_PC_PARTITION_TYPE_FAT32 0xb#define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc#define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
@@ -48,6 +49,7 @@#define GRUB_PC_PARTITION_TYPE_FREEBSD 0xa5#define GRUB_PC_PARTITION_TYPE_OPENBSD 0xa6#define GRUB_PC_PARTITION_TYPE_NETBSD 0xa9 +#define GRUB_PC_PARTITION_TYPE_HFS 0xaf#define GRUB_PC_PARTITION_TYPE_GPT_DISK 0xee#define GRUB_PC_PARTITION_TYPE_LINUX_RAID 0xfd
Commited
Quoted 62 lines · Vladimir Serbinenko
HFS autodetect added. With changelog this time. Should already be suitable for inclusion
Quoted 55 lines · Vladimir Serbinenko
Quoted 11 lines · Isaac Dupree
Quoted 1 line · Peter Cros
I don't think it is compatible with current MBR/GPT hybrid
?partitioning on
Quoted 1 line
intel macs for grub-pc booting.
well, it doesn't necessarily order the partitions in the same way as e.g. rEFIt gptsync does, but that's because this GRUB implementation gives you more
control! You can even pick different MBR-partition-configurations, before
booting different OSes.Yes it was written with such possibility in mind. I don't see why grub2 will enforce mbr partitions to be sorted since mbr doesn't require such thing. If you ask grub2 to put partitions in reverse order it does it. As to partition in zeroth slot it spans across the space before the first MBR partition and is so called protective partition and is required for some tools including grub2 itself to recognise gpt disk as such. About compatibiliy: hybrid MBR is against specifications - it's a trick to boot legacy OS. So the only compatibility you can speak about is the ability to boot a legacy OS of your choice.
Quoted 5 lines
Quoted 2 lines · Vladimir Serbinenko
Here there are 2 differences. First partition type for hfs+ isn't autodetected, I will fix this, just I thought it ws unnecessary AFAIK
Quoted 9 lines
every
Quoted 1 line
OS which understands HFS+ understands GPT.
At least Mac OS X 10.3 and earlier don't understand GPT, and it actually makes
a difference with Apple's "target disk mode"! And there may be a few other
combinations.Ok
Quoted 10 lines
-Isaac
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoted 5 lines · Vladimir Serbinenko
About compatibiliy: hybrid MBR is against specifications - it's a trick to boot legacy OS. So the only compatibility you can speak about is the ability to boot a legacy OS of your choice.
Quoted 1 line
That is exactly what I was referring to.
The ability to control the ordering of partitions was attractive, not a problem.
I will leave it there thanks.
Signature · 1 line
Cros (pxw)