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 can create the required mountpoints if it doesnot exist.
fixes: osbuild#352

Signed-off-by: Sayan Paul <[email protected]>
  • Loading branch information
say-paul authored and achilleas-k committed Feb 9, 2024
1 parent 4162456 commit 81df27d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/distro/rhel9/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,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

Expand Down Expand Up @@ -537,6 +542,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
Expand Down Expand Up @@ -702,3 +712,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=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
}
6 changes: 6 additions & 0 deletions pkg/distro/rhel9/imagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ 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 t.name == "edge-simplified-installer" || t.name == "edge-raw-image" || t.name == "edge-ami" || t.name == "edge-vsphere" {
if filesystemCustomization := bp.Customizations.GetFilesystems(); filesystemCustomization != nil {
cw.Services = append(cw.Services, "osbuild-ostree-mountpoints.service")
}
}
w = cw
}

Expand Down

0 comments on commit 81df27d

Please sign in to comment.