installutils

package
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackageManifestRelativePath = "image_pkg_manifest_installroot.json"

	// NullDevice represents the /dev/null device used as a mount device for overlay images.
	NullDevice = "/dev/null"

	// CmdlineSELinuxSecurityArg is the "security" arg needed for enabling SELinux.
	CmdlineSELinuxSecurityArg = "security=selinux"

	// CmdlineSELinuxEnabledArg is the "selinux" arg needed for disabling SELinux.
	CmdlineSELinuxDisabledArg = "selinux=0"

	// CmdlineSELinuxEnabledArg is the "selinux" arg needed for enabling SELinux.
	CmdlineSELinuxEnabledArg = "selinux=1"

	// CmdlineSELinuxEnforcingArg is the arg required for forcing SELinux to be in enforcing mode.
	CmdlineSELinuxEnforcingArg = "enforcing=1"

	// CmdlineSELinuxPermissiveArg is the arg for SELinux to be in force-permissive mode.
	CmdlineSELinuxPermissiveArg = "enforcing=0"

	// CmdlineSELinuxSettings is the kernel command-line args for enabling SELinux.
	CmdlineSELinuxSettings = CmdlineSELinuxSecurityArg + " " + CmdlineSELinuxEnabledArg

	// CmdlineSELinuxForceEnforcing is the kernel command-line args for enabling SELinux and force it to be in
	// enforcing mode.
	CmdlineSELinuxForceEnforcing = CmdlineSELinuxSettings + " " + CmdlineSELinuxEnforcingArg

	// SELinuxConfigFile is the file path of the SELinux config file.
	SELinuxConfigFile = "/etc/selinux/config"

	// SELinuxConfigEnforcing is the string value to set SELinux to enforcing in the /etc/selinux/config file.
	SELinuxConfigEnforcing = "enforcing"

	// SELinuxConfigPermissive is the string value to set SELinux to permissive in the /etc/selinux/config file.
	SELinuxConfigPermissive = "permissive"

	// SELinuxConfigDisabled is the string value to set SELinux to disabled in the /etc/selinux/config file.
	SELinuxConfigDisabled = "disabled"

	// GrubCfgFile is the filepath of the grub config file.
	GrubCfgFile = "/boot/grub2/grub.cfg"

	// GrubDefFile is the filepath of the config file used by grub-mkconfig.
	GrubDefFile = "/etc/default/grub"

	// CombinedBootPartitionBootPrefix is the grub.cfg boot prefix used when the boot partition is the same as the
	// rootfs partition.
	CombinedBootPartitionBootPrefix = "/boot"
)

Variables

This section is empty.

Functions

func AddImageIDFile

func AddImageIDFile(installChrootRootDir string, buildNumber string) (err error)

AddImageIDFile adds image-id file in the /etc directory of the install root. The file contains the following fields: BUILD_NUMBER: The build number of the image IMAGE_BUILD_DATE: The date when the image is built in format YYYYMMDDHHMMSS IMAGE_UUID: The UUID of the image

func CallGrubMkconfig

func CallGrubMkconfig(installChroot safechroot.ChrootInterface) (err error)

func Chage

func Chage(installChroot safechroot.ChrootInterface, passwordExpirationInDays int64, username string) (err error)

chage works in the same way as invoking "chage -M passwordExpirationInDays username" i.e. it sets the maximum password expiration date.

func ClearSystemdState

func ClearSystemdState(installChroot *safechroot.Chroot, enableSystemdFirstboot bool) (err error)

ClearSystemdState clears the systemd state files that should be unique to each instance of the image. This is based on https://systemd.io/BUILDING_IMAGES/. Primarily, this function will ensure that /etc/machine-id is configured correctly, and that random seed and credential files are removed if they exist. - installChroot is the chroot to modify - enableSystemdFirstboot will set the machine-id file to "uninitialized" if true, and "" if false

func ConfigureDiskBootloader

func ConfigureDiskBootloader(bootType string, encryptionEnable bool, partitionSettings []configuration.PartitionSetting,
	kernelCommandLine configuration.KernelCommandLine, installChroot *safechroot.Chroot, diskDevPath string,
	mountPointMap map[string]string, encryptedRoot diskutils.EncryptedRootDevice, enableGrubMkconfig bool,
	includeLegacyGrubCfg bool,
) (err error)

func ConfigureDiskBootloaderWithRootMountIdType

func ConfigureDiskBootloaderWithRootMountIdType(bootType string, encryptionEnable bool,
	rootMountIdentifier configuration.MountIdentifier, kernelCommandLine configuration.KernelCommandLine,
	installChroot *safechroot.Chroot, diskDevPath string, mountPointMap map[string]string,
	encryptedRoot diskutils.EncryptedRootDevice, enableGrubMkconfig bool, includeLegacyGrubCfg bool,
) (err error)

func ConfigureUserPrimaryGroupMembership

func ConfigureUserPrimaryGroupMembership(installChroot safechroot.ChrootInterface, username string, primaryGroup string,
) (err error)

func ConfigureUserSecondaryGroupMembership

func ConfigureUserSecondaryGroupMembership(installChroot safechroot.ChrootInterface, username string, secondaryGroups []string,
) (err error)

func ConfigureUserStartupCommand

func ConfigureUserStartupCommand(installChroot safechroot.ChrootInterface, username string, startupCommand string) (err error)

func CreateInstallRoot

func CreateInstallRoot(installRoot string, mountPointMap, mountPointToFsTypeMap,
	mountPointToMountArgsMap map[string]string, mountPointToOverlayMap map[string]*Overlay,
) (mountList []string, err error)

CreateInstallRoot walks through the map of mountpoints and mounts the partitions into installroot - installRoot is the destination path to mount these partitions - mountPointMap is the map of mountpoint to partition device path - mountPointToFsTypeMap is the map of mountpoint to the file type - mountPointToMountArgsMap is the map of mountpoint to the parameters sent to - mountPointToOverlayMap is the map of mountpoint to the overlay structure containing the base image

func CreateMountPointPartitionMap

func CreateMountPointPartitionMap(partDevPathMap, partIDToFsTypeMap map[string]string, partitionSettings []configuration.PartitionSetting) (mountPointDevPathMap, mountPointToFsTypeMap, mountPointToMountArgsMap map[string]string, diffDiskBuild bool)

CreateMountPointPartitionMap creates a map between the mountpoint supplied in the config file and the device path of the partition - partDevPathMap is a map of partition IDs to partition device paths - partIDToFsTypeMap is a map of partition IDs to filesystem type - config is the SystemConfig from a config file Output - mountPointDevPathMap is a map of mountpoint to partition device path - mountPointToFsTypeMap is a map of mountpoint to filesystem type - mountPointToMountArgsMap is a map of mountpoint to mount arguments to be passed on a call to mount - diffDiskBuild is a flag that denotes whether this is a diffdisk build or not

func DaysSinceUnixEpoch

func DaysSinceUnixEpoch() int64

func DestroyInstallRoot

func DestroyInstallRoot(installRoot string, mountList []string, mountPointMap map[string]string,
	mountPointToOverlayMap map[string]*Overlay,
) (err error)

DestroyInstallRoot unmounts each of the installroot mountpoints in order, ensuring that the root mountpoint is last - installRoot is the path to the root where the mountpoints exist - mountPointMap is the map of mountpoints to partition device paths - mountPointToOverlayMap is the map of mountpoints to overlay devices

func EnableEmittingProgress

func EnableEmittingProgress()

EnableEmittingProgress enables progress updates on stdout, such as percent complete and the current action.

func ExtractPartitionArtifacts

func ExtractPartitionArtifacts(setupChrootDirPath, workDirPath string, diskIndex int, disk configuration.Disk, systemConfig configuration.SystemConfig, partIDToDevPathMap map[string]string, mountPointToOverlayMap map[string]*Overlay) (err error)

ExtractPartitionArtifacts scans through the SystemConfig and generates all the partition-based artifacts specified. - setupChrootDirPath is the path to the setup root dir where the build takes place - workDirPath is the directory to place the artifacts - diskIndex is the index of the disk this is added to the parition artifact generated - disk configuration settings for the disk - systemConfig system configration corresponding to the disk configuration - partIDToDevPathMap is a map of partition IDs to partition device paths - mountPointToOverlayMap is a map of mountpoints to the overlay details for this mount if any

func FormatMountIdentifier

func FormatMountIdentifier(identifier configuration.MountIdentifier, device string) (identifierString string, err error)

FormatMountIdentifier finds the requested identifier type for the given device, and formats it for use

ie "UUID=12345678-abcd..."

func GetPartLabel

func GetPartLabel(device string) (stdout string, err error)

GetPartLabel queries the PARTLABEL of the given partition - device is the device path of the desired partition

func GetPartUUID

func GetPartUUID(device string) (stdout string, err error)

GetPartUUID queries the PARTUUID of the given partition - device is the device path of the desired partition

func GetRequiredPackagesForInstall

func GetRequiredPackagesForInstall() []*pkgjson.PackageVer

GetRequiredPackagesForInstall returns the list of packages required for the tooling to install an image

func GetUUID

func GetUUID(device string) (stdout string, err error)

GetUUID queries the UUID of the given partition - device is the device path of the desired partition

func InstallBootloader

func InstallBootloader(installChroot *safechroot.Chroot, encryptEnabled bool, bootType, bootUUID, bootPrefix,
	bootDevPath string,
) (err error)

InstallBootloader installs the proper bootloader for this type of image - installChroot is a pointer to the install Chroot object - bootType indicates the type of boot loader to add. - bootUUID is the UUID of the boot partition Note: this boot partition could be different than the boot partition specified in the main grub config. This boot partition specifically indicates where to find the main grub cfg

func InstallGrubDefaults

func InstallGrubDefaults(installRoot, rootDevice, bootUUID, bootPrefix string,
	encryptedRoot diskutils.EncryptedRootDevice, kernelCommandLine configuration.KernelCommandLine,
	isBootPartitionSeparate bool, includeLegacyCfg bool,
) (err error)

InstallGrubDefaults installs the main grub config to the rootfs partition - installRoot is the base install directory - rootDevice holds the root partition - bootUUID is the UUID for the boot partition - bootPrefix is the path to the /boot grub configs based on the mountpoints (i.e., if /boot is a separate partition from the rootfs partition, bootPrefix=""). - encryptedRoot holds the encrypted root information if encrypted root is enabled - kernelCommandLine contains additional kernel parameters which may be optionally set - readOnlyRoot holds the dm-verity read-only root partition information if dm-verity is enabled. - isBootPartitionSeparate is a boolean value which is true if the /boot partition is separate from the root partition - includeLegacyCfg specifies if the legacy grub.cfg from Azure Linux should also be added. Note: this boot partition could be different than the boot partition specified in the bootloader. This boot partition specifically indicates where to find the kernel, config files, and initrd

func InstallGrubEnv

func InstallGrubEnv(installRoot string) (err error)

InstallGrubEnv installs an empty grubenv f

func KernelPackages

func KernelPackages(config configuration.Config) []*pkgjson.PackageVer

KernelPackages returns a list of kernel packages obtained from KernelOptions in the config's SystemConfigs

func OverlayUnmount

func OverlayUnmount(mountPointToOverlayMap map[string]*Overlay) (err error)

OverlayUnmount unmounts the overlay devices that are stored in the map, It ignores the errors and returns the last error. - mountPointToOverlayMap is the map of mountpoints to overlay devices

func PackageNamesFromConfig

func PackageNamesFromConfig(config configuration.Config) (packageList []*pkgjson.PackageVer, err error)

PackageNamesFromConfig takes the union of top level package names for every system configuration in a top level config file. - config is the config file to proccess

func PackageNamesFromSingleSystemConfig

func PackageNamesFromSingleSystemConfig(systemConfig configuration.SystemConfig) (finalPkgList []string, err error)

PackageNamesFromSingleSystemConfig goes through the "PackageLists" and "Packages" fields in the "SystemConfig" object, extracting from packageList JSONs and packages listed in config itself to create one comprehensive package list. NOTE: the package list contains the versions restrictions for the packages, if present, in the form "[package][condition][version]".

Example: gcc=9.1.0

- systemConfig is the systemconfig field from the config file Since kernel is not part of the packagelist, it is added separately from KernelOptions.

func PopulateInstallRoot

func PopulateInstallRoot(installChroot *safechroot.Chroot, packagesToInstall []string,
	config configuration.SystemConfig, mountList []string, installMap, mountPointToFsTypeMap, mountPointToMountArgsMap,
	partIDToDevPathMap, partIDToFsTypeMap map[string]string, encryptedRoot diskutils.EncryptedRootDevice,
	diffDiskBuild bool,
) (err error)

PopulateInstallRoot fills the installroot with packages and configures the image for boot - installChroot is a pointer to the install Chroot object - packagesToInstall is a slice of packages to install - config is the systemconfig field from the config file - installMap is a map of mountpoints to physical device paths - mountPointToFsTypeMap is a map of mountpoints to filesystem type - mountPointToMountArgsMap is a map of mountpoints to mount options - partIDToDevPathMap is a map of partition IDs to physical device paths - partIDToFsTypeMap is a map of partition IDs to filesystem type - encryptedRoot stores information about the encrypted root device if root encryption is enabled - diffDiskBuild is a flag that denotes whether this is a diffdisk build or not

func ReportAction

func ReportAction(status string)

ReportAction emits the current action being performed on stdout, only if EnableEmittingProgress was invoked with true. It also prints the output to the log at debug level regardless of EnableEmittingProgress.

func ReportActionf

func ReportActionf(format string, args ...interface{})

ReportActionf emits the formatted current action being performed on stdout, only if EnableEmittingProgress was invoked with true. It also prints the output to the log at debug level regardless of EnableEmittingProgress

func ReportPercentComplete

func ReportPercentComplete(progress int)

ReportPercentComplete emits the current percent complete on stdout, only if EnableEmittingProgress was invoked with true.

func RunFinalizeImageScripts

func RunFinalizeImageScripts(installChroot *safechroot.Chroot, config configuration.SystemConfig) (err error)

func RunPreInstallScripts

func RunPreInstallScripts(config configuration.SystemConfig) (err error)

func SELinuxConfigure

func SELinuxConfigure(selinuxMode configuration.SELinux, installChroot *safechroot.Chroot,
	mountPointToFsTypeMap map[string]string, isRootFS bool,
) (err error)

SELinuxConfigure pre-configures SELinux file labels and configuration files

func SELinuxRelabelFiles

func SELinuxRelabelFiles(installChroot safechroot.ChrootInterface, mountPointToFsTypeMap map[string]string, isRootFS bool,
) (err error)

func SELinuxUpdateConfig

func SELinuxUpdateConfig(selinuxMode configuration.SELinux, installChroot safechroot.ChrootInterface) (err error)

func SelectKernelPackage

func SelectKernelPackage(systemConfig configuration.SystemConfig, isLiveInstall bool) (kernelPkg string, err error)

SelectKernelPackage selects the kernel to use for the current installation based on the KernelOptions field of the system configuration.

func TdnfInstall

func TdnfInstall(packageName, installRoot string) (packagesInstalled int, err error)

TdnfInstall installs a package into the current environment without calculating progress

func TdnfInstallPriorityPackage

func TdnfInstallPriorityPackage(priorityPackageName, installRoot string, packagesToInstall []string, currentPackagesInstalled, totalPackages int, reportProgress bool,
) (packagesInstalled int, updatedPackagesToInstall []string, err error)

TdnfInstallPriorityPackage installs a specific package, removing it from the list of packages to install in future steps. This is useful for installing requirements for actual tooling operations that need to be installed before other packages.

func TdnfInstallWithProgress

func TdnfInstallWithProgress(packageName, installRoot string, currentPackagesInstalled, totalPackages int, reportProgress bool) (packagesInstalled int, err error)

TdnfInstallWithProgress installs a package in the current environment while optionally reporting progress

func UpdateFstab

func UpdateFstab(installRoot string, partitionSettings []configuration.PartitionSetting, mountList []string,
	mountPointMap, mountPointToFsTypeMap, mountPointToMountArgsMap, partIDToDevPathMap, partIDToFsTypeMap map[string]string,
	hidepidEnabled bool,
) (err error)

func UpdateFstabFile

func UpdateFstabFile(fullFstabPath string, partitionSettings []configuration.PartitionSetting, mountList []string,
	mountPointMap, mountPointToFsTypeMap, mountPointToMountArgsMap, partIDToDevPathMap, partIDToFsTypeMap map[string]string,
	hidepidEnabled bool,
) (err error)

func UpdatePartitionMapWithOverlays

func UpdatePartitionMapWithOverlays(partDevPathMap, partIDToFsTypeMap, mountPointDevPathMap, mountPointToFsTypeMap, mountPointToMountArgsMap map[string]string, config configuration.SystemConfig) (mountPointToOverlayMap map[string]*Overlay, err error)

UpdatePartitionMapWithOverlays Creates Overlay map and updates the partition map with required parameters. - partDevPathMap is a map of partition IDs to partition device paths - partIDToFsTypeMap is a map of partition IDs to filesystem type - mountPointDevPathMap is a map of mountpoint to partition device path - mountPointToFsTypeMap is a map of mountpoint to filesystem type - mountPointToMountArgsMap is a map of mountpoint to mount arguments to be passed on a call to mount - config is the SystemConfig from a config file Output - mountPointToOverlayMap is a map of mountpoint to overlay data

Types

type Overlay

type Overlay struct {
	DevicePath string
	// contains filtered or unexported fields
}

Overlay Struct representing an overlay mount

func NewOverlay

func NewOverlay(devicePath string) Overlay

NewOverlay Creates the overlay struct

type PackageList

type PackageList struct {
	Packages []string `json:"packages"`
}

PackageList represents the list of packages to install into an image

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL