Skip to content

Updates ro inclusion with conditionals for IoT version - #1352

Closed
djach7 wants to merge 1 commit into
osbuild:mainfrom
djach7:iot-ro-follow-up
Closed

djach7 wants to merge 1 commit into
osbuild:mainfrom
djach7:iot-ro-follow-up

Conversation

@djach7

@djach7 djach7 commented Mar 24, 2025 •

Copy link
Copy Markdown
Contributor

Updates IoT fstab to only include ro in versions 42 and above.

Follow up to this PR: #1346

Fix for this issue: fedora-iot/iot-distro#81

Going to start this out as a draft to confirm that this is the only location ro is needed.

@djach7
djach7 force-pushed the iot-ro-follow-up branch from 0e1cd21 to 149c146 Compare March 25, 2025 14:27
@djach7
djach7 marked this pull request as ready for review March 25, 2025 14:27
@djach7
djach7 requested a review from a team as a code owner March 25, 2025 14:27
Comment on lines +253 to +256
if common.VersionGreaterThanOrEqual(d.osVersion, "42") {
rootPartition := &iotBasePartitionTables[arch.ARCH_X86_64.String()].Partitions[2]
rootPartition.Payload.(*disk.Filesystem).FSTabOptions += ",ro"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For this kind of change we make partition table functions that are parameterised on the OS version.

See for example these RHEL 9 partition tables: https://github.com/osbuild/images/blob/c25ea613b3b81c2e6640e945c638cbe08b58818a/pkg/distro/rhel/rhel9/partition_tables.go#L13

Can you change this to work the same way? I.e., change iotBasePartitionTables to be a function with an imageType argument that the function can read to determine which partition table to return (based on architecture) and what modifications to make.

This also saves us from any potential side effects of modifying the partition table globals for one Fedora version and generating the wrong manifest for another Fedora version with the modified partition table.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep I should be able to do that 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@achilleas-k Struggling with how to extract an image struct or something similar to .ImageType out of Fedora, I can't find any functions that perform a similar duty in the Fedora package (https://pkg.go.dev/github.com/osbuild/[email protected]/pkg/distro/fedora). Does using functions from the Distro package make sense instead (https://pkg.go.dev/github.com/osbuild/images/pkg/distro)? I was thinking maybe I could use distro.Arch in some way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's not needed. The Fedora imageType struct is local to the fedora package and so are the partition tables. So the function conversion can be done like this:

diff --git a/pkg/distro/fedora/partition_tables.go b/pkg/distro/fedora/partition_tables.go
index de4bb4044..c16ccf0cd 100644
--- a/pkg/distro/fedora/partition_tables.go
+++ b/pkg/distro/fedora/partition_tables.go
@@ -355,99 +355,102 @@ var minimalrawPartitionTables = distro.BasePartitionTableMap{
 	},
 }
 
-var iotBasePartitionTables = distro.BasePartitionTableMap{
-	arch.ARCH_X86_64.String(): disk.PartitionTable{
-		UUID:        "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
-		Type:        disk.PT_GPT,
-		StartOffset: 8 * datasizes.MebiByte,
-		Partitions: []disk.Partition{
-			{
-				Size: 501 * datasizes.MebiByte,
-				Type: disk.EFISystemPartitionGUID,
-				UUID: disk.EFISystemPartitionUUID,
-				Payload: &disk.Filesystem{
-					Type:         "vfat",
-					UUID:         disk.EFIFilesystemUUID,
-					Mountpoint:   "/boot/efi",
-					Label:        "EFI-SYSTEM",
-					FSTabOptions: "umask=0077,shortname=winnt",
-					FSTabFreq:    0,
-					FSTabPassNo:  2,
+func iotBasePartitionTables(t *imageType) disk.PartitionTable {
+	archName := t.arch.name
+	return distro.BasePartitionTableMap{
+		arch.ARCH_X86_64.String(): disk.PartitionTable{
+			UUID:        "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
+			Type:        disk.PT_GPT,
+			StartOffset: 8 * datasizes.MebiByte,
+			Partitions: []disk.Partition{
+				{
+					Size: 501 * datasizes.MebiByte,
+					Type: disk.EFISystemPartitionGUID,
+					UUID: disk.EFISystemPartitionUUID,
+					Payload: &disk.Filesystem{
+						Type:         "vfat",
+						UUID:         disk.EFIFilesystemUUID,
+						Mountpoint:   "/boot/efi",
+						Label:        "EFI-SYSTEM",
+						FSTabOptions: "umask=0077,shortname=winnt",
+						FSTabFreq:    0,
+						FSTabPassNo:  2,
+					},
 				},
-			},
-			{
-				Size: 1 * datasizes.GibiByte,
-				Type: disk.FilesystemDataGUID,
-				UUID: disk.DataPartitionUUID,
-				Payload: &disk.Filesystem{
-					Type:         "ext4",
-					Mountpoint:   "/boot",
-					Label:        "boot",
-					FSTabOptions: "defaults",
-					FSTabFreq:    1,
-					FSTabPassNo:  2,
+				{
+					Size: 1 * datasizes.GibiByte,
+					Type: disk.FilesystemDataGUID,
+					UUID: disk.DataPartitionUUID,
+					Payload: &disk.Filesystem{
+						Type:         "ext4",
+						Mountpoint:   "/boot",
+						Label:        "boot",
+						FSTabOptions: "defaults",
+						FSTabFreq:    1,
+						FSTabPassNo:  2,
+					},
 				},
-			},
-			{
-				Size: 2569 * datasizes.MebiByte,
-				Type: disk.FilesystemDataGUID,
-				UUID: disk.RootPartitionUUID,
-				Payload: &disk.Filesystem{
-					Type:         "ext4",
-					Label:        "root",
-					Mountpoint:   "/",
-					FSTabOptions: "defaults,ro",
-					FSTabFreq:    1,
-					FSTabPassNo:  1,
+				{
+					Size: 2569 * datasizes.MebiByte,
+					Type: disk.FilesystemDataGUID,
+					UUID: disk.RootPartitionUUID,
+					Payload: &disk.Filesystem{
+						Type:         "ext4",
+						Label:        "root",
+						Mountpoint:   "/",
+						FSTabOptions: "defaults,ro",
+						FSTabFreq:    1,
+						FSTabPassNo:  1,
+					},
 				},
 			},
 		},
-	},
-	arch.ARCH_AARCH64.String(): disk.PartitionTable{
-		UUID:        "0xc1748067",
-		Type:        disk.PT_DOS,
-		StartOffset: 8 * datasizes.MebiByte,
-		Partitions: []disk.Partition{
-			{
-				Size:     501 * datasizes.MebiByte,
-				Type:     disk.FAT16BDOSID,
-				Bootable: true,
-				Payload: &disk.Filesystem{
-					Type:         "vfat",
-					UUID:         disk.EFIFilesystemUUID,
-					Mountpoint:   "/boot/efi",
-					Label:        "EFI-SYSTEM",
-					FSTabOptions: "umask=0077,shortname=winnt",
-					FSTabFreq:    0,
-					FSTabPassNo:  2,
+		arch.ARCH_AARCH64.String(): disk.PartitionTable{
+			UUID:        "0xc1748067",
+			Type:        disk.PT_DOS,
+			StartOffset: 8 * datasizes.MebiByte,
+			Partitions: []disk.Partition{
+				{
+					Size:     501 * datasizes.MebiByte,
+					Type:     disk.FAT16BDOSID,
+					Bootable: true,
+					Payload: &disk.Filesystem{
+						Type:         "vfat",
+						UUID:         disk.EFIFilesystemUUID,
+						Mountpoint:   "/boot/efi",
+						Label:        "EFI-SYSTEM",
+						FSTabOptions: "umask=0077,shortname=winnt",
+						FSTabFreq:    0,
+						FSTabPassNo:  2,
+					},
 				},
-			},
-			{
-				Size: 1 * datasizes.GibiByte,
-				Type: disk.FilesystemLinuxDOSID,
-				Payload: &disk.Filesystem{
-					Type:         "ext4",
-					Mountpoint:   "/boot",
-					Label:        "boot",
-					FSTabOptions: "defaults",
-					FSTabFreq:    1,
-					FSTabPassNo:  2,
+				{
+					Size: 1 * datasizes.GibiByte,
+					Type: disk.FilesystemLinuxDOSID,
+					Payload: &disk.Filesystem{
+						Type:         "ext4",
+						Mountpoint:   "/boot",
+						Label:        "boot",
+						FSTabOptions: "defaults",
+						FSTabFreq:    1,
+						FSTabPassNo:  2,
+					},
 				},
-			},
-			{
-				Size: 2569 * datasizes.MebiByte,
-				Type: disk.FilesystemLinuxDOSID,
-				Payload: &disk.Filesystem{
-					Type:         "ext4",
-					Label:        "root",
-					Mountpoint:   "/",
-					FSTabOptions: "defaults",
-					FSTabFreq:    1,
-					FSTabPassNo:  1,
+				{
+					Size: 2569 * datasizes.MebiByte,
+					Type: disk.FilesystemLinuxDOSID,
+					Payload: &disk.Filesystem{
+						Type:         "ext4",
+						Label:        "root",
+						Mountpoint:   "/",
+						FSTabOptions: "defaults",
+						FSTabFreq:    1,
+						FSTabPassNo:  1,
+					},
 				},
 			},
 		},
-	},
+	}[archName]
 }
 
 var iotSimplifiedInstallerPartitionTables = distro.BasePartitionTableMap{

and then the fstab options can be modified based on the distro version after that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, looking at it now, it looks like it's going to be a bigger change than I originally though, because we would have to change the type of the partition table property on Fedora's imageType to a function (like in RHEL).

Maybe it's better if we leave it for a follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I just force pushed to bring the branch up to date. Thanks for the detailed rundown, I think I understand a little better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fwiw, converting to a function (like in the rhel image types) is done in #1362 and with the YAML-ification all of partition_table.go is going away so doing something short term here seems fine. How urgent is this work? Alternatively we could update 1362 for conditionals and then do this change in the YAML instead of in code.

With this requirement pr 1362 will need conditionals in the YAML which is fine and we also need it in RHEL but it does mean the PR there will get bigger. So if we need this change soon we should probably do something short term here. If it can wait a few days we can tweak 1362 to have conditionals and do it in the yaml.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fwiw, I pushed support for conditional overrides into #1362, it looks like this for this specific use-case:

  iot_raw_image:
    partition_table:
      <<: *iot_base_partition_tables
    partition_table_override:
      condition:
        version_greater_or_equal:
          "42":
            - select_partition: 2
              fstab_options: "defaults,ro"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for making these changes in the yaml, I don't think this is super urgent. Would you like me to wait on this until the yaml changes come out?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just approved the partition table yaml-ification PR, so maybe let's do it there, yeah.

@achilleas-k achilleas-k left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@djach7
djach7 force-pushed the iot-ro-follow-up branch from 149c146 to d949a53 Compare March 26, 2025 20:34

func mkIotRawImgType(d distribution) imageType {
if common.VersionGreaterThanOrEqual(d.osVersion, "42") {
rootPartition := &iotBasePartitionTables[arch.ARCH_X86_64.String()].Partitions[2]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Quick question @djach7 - only x86_64 or should we also update aarch64 for ro?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We do need it, I've been slacking on aarch I apologize. I'll update/rewrite this to account for that too. I think I'm going to change this into an iterator that steps through each partition, I'm not sure if I can be confident that the root partition will always be at [2].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like #1362 (review) might get merged soon, - that branch includes this change now via the new partition_override yaml.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I'll hold back on this for now then.

mvo5 added a commit to mvo5/images that referenced this pull request Mar 27, 2025
mvo5 added a commit to mvo5/images that referenced this pull request Mar 27, 2025
mvo5 added a commit to mvo5/images that referenced this pull request Mar 27, 2025
mvo5 added a commit to mvo5/images that referenced this pull request Mar 27, 2025
@djach7
djach7 marked this pull request as draft March 27, 2025 13:36
@djach7

djach7 commented Mar 27, 2025

Copy link
Copy Markdown
Contributor Author

Making this a draft until I get the aarch changes added today

@supakeen

Copy link
Copy Markdown
Member

Spoke to @djach7, we'll close this one in favor of the #1362 which now includes this change.

@supakeen supakeen closed this Mar 27, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Mar 27, 2025
nagyist pushed a commit to nagyist/golang.oapi-codegen that referenced this pull request Oct 8, 2026
Originally added in f77bd7b, we wanted
to pin the version to ensure that we were targeting the latest version
of Go 1.21.

However, there's no real value here, and as noted in [0] it can be
causing issues for some users.

There's nothing explicitly in Go 1.21.x that we need to pin to, just
that we need support for Go 1.21, so we can use Speakeasy's
`openapi-overlay` library.

Therefore we can relax the patch-version requirement, which will
alleviate issues for consumers.

This makes sure that we have _at a minimum_ a version of Go 1.21, and
makes `go mod tidy` happy.

[0]: osbuild/image-builder#1352
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.

4 participants