diff --git a/pkg/distro/rhel9/images.go b/pkg/distro/rhel9/images.go index 88e86f82d9..6387a46243 100644 --- a/pkg/distro/rhel9/images.go +++ b/pkg/distro/rhel9/images.go @@ -476,6 +476,11 @@ func edgeRawImage(workload workload.Workload, } img.PartitionTable = pt + customServiceFile := createFilesystemMounpointService(customizations) + if customServiceFile != nil { + img.Files = append(img.Files, customServiceFile) + } + img.Filename = t.Filename() img.Compression = t.compression @@ -533,6 +538,11 @@ func edgeSimplifiedInstallerImage(workload workload.Workload, } rawImg.PartitionTable = pt + customServiceFile := createFilesystemMounpointService(customizations) + if customServiceFile != nil { + rawImg.Files = append(rawImg.Files, customServiceFile) + } + rawImg.Filename = t.Filename() // 92+ only @@ -698,3 +708,25 @@ func initialSetupKickstart() *fsnode.File { } return file } + +// fixes: https://github.com/osbuild/images/issues/352 +// Creates a unit file that create mountpoints if it doesnot exits. +// This ensures that the filesystem created using image builder continues to work after upgrade. +func createFilesystemMounpointService(customizations *blueprint.Customizations) *fsnode.File { + mntpnts := customizations.GetFilesystems() + if mntpnts != nil { + customServiceUnit := "[Unit]\nDescription=Create mountpoints if does not exists\nDefaultDependencies=no\n" + customService := "[Service]\nType=oneshot\nRemainAfterExit=yes\nExecStartPre=chattr -i /\nExecStopPost=chattr +i /\nExecStart=mkdir -p" + for _, mountpoint := range mntpnts { + customServiceUnit = customServiceUnit + "ConditionPathExists=|!" + mountpoint.Mountpoint + "\n" + customService = customService + " " + mountpoint.Mountpoint + } + finalCustomService := customServiceUnit + customService + "\n" + "[Install]\nWantedBy=remote-fs.target\n" + file, err := fsnode.NewFile("/etc/systemd/system/create-mountpoints.service", nil, nil, nil, []byte(finalCustomService)) + if err != nil { + panic(err) + } + return file + } + return nil +} diff --git a/pkg/distro/rhel9/imagetype.go b/pkg/distro/rhel9/imagetype.go index 3589b69809..14d24baa2a 100644 --- a/pkg/distro/rhel9/imagetype.go +++ b/pkg/distro/rhel9/imagetype.go @@ -239,6 +239,10 @@ func (t *imageType) Manifest(bp *blueprint.Blueprint, cw.Services = services.Enabled cw.DisabledServices = services.Disabled } + //enable custom-service that creates mountpoints , refer func: createFilesystemMounpointService + if filesystemCustomization := bp.Customizations.GetFilesystems(); filesystemCustomization != nil { + cw.Services = append(cw.Services, "create-mountpoints.service") + } w = cw }