[parted-devel] map gpt partitions to msdos primary entries

Jim Meyering jim at meyering.net
Mon May 14 19:26:05 UTC 2007


Olaf Hering <olh at suse.de> wrote:
> This patch adds a new 'set X map_gpt_to_msdos Y' function.
> Using it will break the EFI spec (I cant verify it because the EFI spec
> is not free).
>
> On Apple systems with Intel hardware it is sometimes required to install
> EFI unaware systems, such as Windows, grub or lilo. With this change,
> parted will not destroy the existing primary partitions.
> But, parted does some checks to make sure the LBA mapping in the
> individual partitions match the existing gpt partitions. If they differ,
> the msdos entry will be removed.
>
> One issue remains: the msdos partition types. gpt types can not be
> mapped 1 to 1 to msdos partition types. I added a simple mapping to
> (hopefully) let grub recognize the partition as readable.
>
>
> This patch needes testing on Apple systems.
> I do not have any DOS compatbile hardware.
>
> Example usage:
>
> sudo parted -s /dev/sdb mklabel gpt
> sudo parted -s /dev/sdb mkpart primary 17k 1G
> sudo parted -s /dev/sdb mkpart primary 2G 3G
> sudo parted -s /dev/sdb set 1 map_gpt_to_msdos 2
> sudo parted -s /dev/sdb set 1 boot on
> sudo parted -s /dev/sdb set 1 boot off

Thanks for the example.
However, would you please phrase those examples in terms of a
test script that we can add to the growing suite?

For example, it would be good to demonstrate that commands like these fail:

    sudo parted -s /dev/sdb set 1 map_gpt_to_msdos 1
    sudo parted -s /dev/sdb set 1 map_gpt_to_msdos 5

and that they give a sensible diagnostic (e.g., invalid partition number,
must be in range [2..4]).

You can use this as a starting point:

# First, use dd to create a file of the required size, e.g., just 4MB.
# (note I changed partition sizes below, so the file needn't be as large
# as in your example above).  BTW, you don't need to run this as root.
# Just use a regular file as $dev.  See tests/t*.sh for examples.
dev=loop-file
N=4M
test_expect_success \
    'create a file large enough to hold our file system' \
    'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'

test_expect_success \
    'setup for test' \
    'parted -s $dev mklabel gpt &&
     parted -s $dev mkpart primary 17k 1M &&
     parted -s $dev mkpart primary 2M 3M'
test_expect_failure \
    'verify that "set 1 map_gpt_to_msdos N" fails when N is invalid' \
    'parted -s $dev set 1 map_gpt_to_msdos 1 > out 2> err'
test_expect_success 'expect no stdout' '$compare out /dev/null'
test_expect_success 'check for expected diagnostic on stderr' \
    'echo "ERROR: 1: invalid partition number; must be in range [2..4]" > exp &&
     $compare err exp'

Then do something similar (use dd to zero out the file again, and repeat
the above verbatim, but with a valid partition number, and expect no
stderr output) but with a pre-existing primary partition, between 1M and
2M, and after the parted commands, ensure that the original partition
table entry is not modified.

test_expect_success \
    'zero out test file' \
    'dd if=/dev/zero of=$dev bs=$N count=1 2> /dev/null'

# Create an msdos partition table, and at least one partition to be preserved
# FIXME:

test_expect_success \
    'setup for test' \
    'parted -s $dev mklabel gpt &&
     parted -s $dev mkpart primary 17k 1M &&
     parted -s $dev mkpart primary 2M 3M'
test_expect_failure \
    'verify that "set 1 map_gpt_to_msdos N" fails when N is invalid' \
    'parted -s $dev set 1 map_gpt_to_msdos 2 > out 2>&1'
test_expect_success 'expect no stdout' '$compare out /dev/null'

# Finally, ensure that the original partition table entry is untouched
# FIXME:



More information about the parted-devel mailing list