Skip to content

Commit

Permalink
rhel9/images:Custom service to create mountpoints
Browse files Browse the repository at this point in the history
Filesystem customization  mountpoints does not persists any upgrade
due to the property of ostree which only persists data on /var and /etc.
This feature will ingest the filesystem customization and create a unit
file which is stored in /etc/systemd/system and can create the required
mountpoints if it does not exist.
fixes: osbuild#352

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
  • Loading branch information
say-paul committed Feb 21, 2024
1 parent cb9318a commit 118da52
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ func edgeRawImage(workload workload.Workload,
return nil, err
}
img.PartitionTable = pt
customServiceFile := createFilesystemMounpointService(customizations)
if customServiceFile != nil {
img.Files = append(img.Files, customServiceFile)
}

img.Filename = t.Filename()
img.Compression = t.compression
Expand Down Expand Up @@ -550,6 +554,11 @@ func edgeSimplifiedInstallerImage(workload workload.Workload,
rawImg.KernelOptionsAppend = append(rawImg.KernelOptionsAppend, kopts.Append)
}

customServiceFile := createFilesystemMounpointService(customizations)
if customServiceFile != nil {
rawImg.Files = append(rawImg.Files, customServiceFile)
}

img := image.NewOSTreeSimplifiedInstaller(rawImg, customizations.InstallationDevice)
img.ExtraBasePackages = packageSets[installerPkgsKey]
// img.Workload = workload
Expand Down Expand Up @@ -713,3 +722,27 @@ 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"
ExecStartPre := "/bin/sh -c 'if [ -z \"$(grep -Uq composefs /run/ostree-booted)\" ]; then chattr -i /; fi'"
ExecStopPost := "/bin/sh -c 'if [ -z \"$(grep -Uq composefs /run/ostree-booted)\" ]; then chattr +i /; fi'"
customService := "[Service]\nType=oneshot\nRemainAfterExit=yes\nExecStartPre=" + ExecStartPre + "\nExecStopPost=" + ExecStopPost + "\nExecStart=mkdir -p"
for _, mountpoint := range mntpnts {
customServiceUnit = customServiceUnit + "ConditionPathExists=|!" + mountpoint.Mountpoint + "\n"
customService = customService + " " + mountpoint.Mountpoint
}
finalCustomService := customServiceUnit + customService + "\n" + "[Install]\nWantedBy=local-fs.target\n"
file, err := fsnode.NewFile("/etc/systemd/system/osbuild-ostree-mountpoints.service", nil, nil, nil, []byte(finalCustomService))
if err != nil {
panic(err)
}
return file
}
return nil
}
4 changes: 4 additions & 0 deletions pkg/distro/rhel9/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "osbuild-ostree-mountpoints.service")
}
w = cw
}

Expand Down

0 comments on commit 118da52

Please sign in to comment.