Skip to content

Commit 25c8b05

Browse files
achilleas-kmvo5
authored andcommitted
bib: set filesystem type for all filesystems to match rootfs
Iterate over each Mountable in the partition table (each filesystem) and change the filesystem type to match the rootfs, with two exceptions: - /boot/efi is never changed - /boot is not changed when rootfs is btrfs Do this *after* the partition table with the customizations has been generated, so that all filesystems in the final partition table are properly set. This also fixes osbuild#407.
1 parent dd39459 commit 25c8b05

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

cmd/bootc-image-builder/image.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,37 @@ func updateFilesystemSizes(fsCustomizations []blueprint.FilesystemCustomization,
173173
return updated
174174
}
175175

176-
// setRootfsType sets the filesystem type for the mountable entity with target
177-
// '/'.
178-
func setRootfsType(pt *disk.PartitionTable, rootfs string) error {
176+
// setFSTypes sets the filesystem types for all mountable entities to match the
177+
// selected rootfs type.
178+
// If rootfs is 'btrfs', the function will keep '/boot' to its default.
179+
func setFSTypes(pt *disk.PartitionTable, rootfs string) error {
179180
if rootfs == "" {
180181
return fmt.Errorf("root filesystem type is empty")
181182
}
182-
rootMountable := pt.FindMountable("/")
183-
if rootMountable == nil {
184-
// this should be caught by tests and never actually happen but let's
185-
// print the entire partition table in case it does due to a
186-
// programming mistake or bug to make troubleshooting easier
187-
return fmt.Errorf("internal partition table does not define a root filesystem: %+v", pt)
188-
}
189-
rootFsEntity, isfs := rootMountable.(*disk.Filesystem)
190-
if !isfs {
191-
return fmt.Errorf("the root mountable disk entity of the base partition table is not an ordinary filesystem but %T", rootMountable)
192-
}
193-
rootFsEntity.Type = rootfs
194-
return nil
183+
184+
return pt.ForEachMountable(func(mnt disk.Mountable, _ []disk.Entity) error {
185+
switch mnt.GetMountpoint() {
186+
case "/boot/efi":
187+
// never change the efi partition's type
188+
return nil
189+
case "/boot":
190+
// change only if we're not doing btrfs
191+
if rootfs == "btrfs" {
192+
return nil
193+
}
194+
fallthrough
195+
default:
196+
switch elem := mnt.(type) {
197+
case *disk.Filesystem:
198+
elem.Type = rootfs
199+
case *disk.BtrfsSubvolume:
200+
// nothing to do
201+
default:
202+
return fmt.Errorf("the mountable disk entity for %q of the base partition table is not an ordinary filesystem but %T", mnt.GetMountpoint(), mnt)
203+
}
204+
return nil
205+
}
206+
})
195207
}
196208

197209
func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
@@ -270,14 +282,15 @@ func manifestForDiskImage(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest
270282
return nil, err
271283
}
272284
fsCustomizations := updateFilesystemSizes(customizations.GetFilesystems(), c.RootfsMinsize)
273-
if err := setRootfsType(&basept, c.RootFSType); err != nil {
274-
return nil, fmt.Errorf("error setting root filesystem type: %w", err)
275-
}
276285

277286
pt, err := disk.NewPartitionTable(&basept, fsCustomizations, DEFAULT_SIZE, partitioningMode, nil, rng)
278287
if err != nil {
279288
return nil, err
280289
}
290+
291+
if err := setFSTypes(pt, c.RootFSType); err != nil {
292+
return nil, fmt.Errorf("error setting root filesystem type: %w", err)
293+
}
281294
img.PartitionTable = pt
282295

283296
// For the bootc-disk image, the filename is the basename and the extension

0 commit comments

Comments
 (0)