Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non conforming partition table #2668

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gabriel-samfira
Copy link
Member

@gabriel-samfira gabriel-samfira commented Feb 14, 2025

Fix non conforming partition table

This change removes the legacy_boot flag from the EFI system partition. We already have a BIOS boot partition which should offer compatibility with legacy bios systems.

How to use

Upload the image in a fresh OpenStack devstack deploy and boot.

Testing done

  • Downloaded the already existing image
  • Removed the legacy_boot flag
  • booted the image and it worked.
  • [x ] Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

/update-sdk

This change removes the legacy_boot flag from the EFI system partition.
We already have a BIOS boot partition which should offer compatibility with
legacy bios systems.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
Copy link
Contributor

@chewi chewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks straightforward, but I'll kick off a Jenkins run against it.

Copy link

github-actions bot commented Feb 14, 2025

Build action triggered: https://github.com/flatcar/scripts/actions/runs/13444442241

@gabriel-samfira
Copy link
Member Author

Let me also test it out manually. Will ping back once I confirm if it works.

@gabriel-samfira gabriel-samfira marked this pull request as draft February 15, 2025 10:24
@gabriel-samfira
Copy link
Member Author

Converted to draft. While using parted 3.6 (version 3.4 seemed to make the image unbootable - need to investigate) on an existing image did seem to make it work, generating a new image without the hybrid flag seems to:

  • Not set the bootable flag in the MBR
  • makes the CHS entry invalid ([0, 1, 0] instead or [0, 2, 0])

@chewi
Copy link
Contributor

chewi commented Feb 15, 2025

I'm surprised by your issues, but I can at least report that CI passed on all platforms except OpenStack and Equinix Metal. I believe those are actually down to availability issues. Brightbox worked, and that uses OpenStack too.

@gabriel-samfira
Copy link
Member Author

You need to run the tests on a fresh devstack deployment. The change that triggers issues in OpenStack was added in December.

The cgpt binary in https://github.com/flatcar/seismograph/tree/flatcar-master/src/cgpt is quite outdated. Newer versions of cgpt (like the one in ubuntu 24.04) can properly set CHS entries (along with other PMBR fields) by running:

cgpt boot -p path/to/raw.img

We then set the bootable flag in the PMBR either via fdisk or by simply flipping the bit at offset 447 in the disk to 0x80. We then have a proper bootable hybrid image that passes the OpenStack disk image tests.

@gabriel-samfira
Copy link
Member Author

to set the bootable flag via fdisk we can run:

echo -e "M\na\nw\n" | fdisk flatcar_production_openstack_image.raw

or we can do it via python in the disk_util module via something like:

def EnsurePMBRBootFlag(options, config=None, partitions=None):
  # Set bootable flag
  with open(options.disk_image, 'r+b') as fd:
    # Seek to partition table offset
    fd.seek(446)
    # Read the partition entry
    partition = fd.read(16)
    partition_data = struct.unpack('<B3BB3BII', partition)
    if partition_data[0] != 0x80:
        new_partition_data = struct.pack('<B3BB3BII', 0x80, *partition_data[1:])
        # Go back to offset of start of partition
        fd.seek(446)
        # write the modified partition data
        fd.write(new_partition_data)

This change pulls in the latest commit of seismograph.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
@gabriel-samfira gabriel-samfira marked this pull request as ready for review February 20, 2025 16:32
@gabriel-samfira
Copy link
Member Author

to set the bootable flag via fdisk we can run:

echo -e "M\na\nw\n" | fdisk flatcar_production_openstack_image.raw

or we can do it via python in the disk_util module via something like:

def EnsurePMBRBootFlag(options, config=None, partitions=None):
  # Set bootable flag
  with open(options.disk_image, 'r+b') as fd:
    # Seek to partition table offset
    fd.seek(446)
    # Read the partition entry
    partition = fd.read(16)
    partition_data = struct.unpack('<B3BB3BII', partition)
    if partition_data[0] != 0x80:
        new_partition_data = struct.pack('<B3BB3BII', 0x80, *partition_data[1:])
        # Go back to offset of start of partition
        fd.seek(446)
        # write the modified partition data
        fd.write(new_partition_data)

the boot flag is not needed. To pass the OpenStack Validation, the CHS values are enough.

@gabriel-samfira
Copy link
Member Author

seems to pass on OpenStack. @chewi could you kick off another test in the CI as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants