mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-06-27 08:36:59 +00:00
Also install fonts when installing grub (#144)
This commit is contained in:
parent
0afdf76278
commit
274701a3ac
@ -41,7 +41,6 @@ const (
|
|||||||
PersistentPartName = "persistent"
|
PersistentPartName = "persistent"
|
||||||
OEMLabel = "COS_OEM"
|
OEMLabel = "COS_OEM"
|
||||||
OEMPartName = "oem"
|
OEMPartName = "oem"
|
||||||
ISOLabel = "COS_LIVE"
|
|
||||||
MountBinary = "/usr/bin/mount"
|
MountBinary = "/usr/bin/mount"
|
||||||
EfiDevice = "/sys/firmware/efi"
|
EfiDevice = "/sys/firmware/efi"
|
||||||
LinuxFs = "ext4"
|
LinuxFs = "ext4"
|
||||||
@ -50,8 +49,6 @@ const (
|
|||||||
EfiFs = "vfat"
|
EfiFs = "vfat"
|
||||||
EfiSize = uint(64)
|
EfiSize = uint(64)
|
||||||
OEMSize = uint(64)
|
OEMSize = uint(64)
|
||||||
StateSize = uint(15360)
|
|
||||||
RecoverySize = uint(8192)
|
|
||||||
PersistentSize = uint(0)
|
PersistentSize = uint(0)
|
||||||
BiosSize = uint(1)
|
BiosSize = uint(1)
|
||||||
ImgSize = uint(3072)
|
ImgSize = uint(3072)
|
||||||
@ -66,7 +63,6 @@ const (
|
|||||||
EfiDir = "/run/cos/efi"
|
EfiDir = "/run/cos/efi"
|
||||||
RecoverySquashFile = "recovery.squashfs"
|
RecoverySquashFile = "recovery.squashfs"
|
||||||
IsoRootFile = "rootfs.squashfs"
|
IsoRootFile = "rootfs.squashfs"
|
||||||
IsoEFIPath = "/boot/uefi.img"
|
|
||||||
ActiveImgFile = "active.img"
|
ActiveImgFile = "active.img"
|
||||||
PassiveImgFile = "passive.img"
|
PassiveImgFile = "passive.img"
|
||||||
RecoveryImgFile = "recovery.img"
|
RecoveryImgFile = "recovery.img"
|
||||||
@ -80,8 +76,6 @@ const (
|
|||||||
AfterUpgradeChrootHook = "after-upgrade-chroot"
|
AfterUpgradeChrootHook = "after-upgrade-chroot"
|
||||||
AfterUpgradeHook = "after-upgrade"
|
AfterUpgradeHook = "after-upgrade"
|
||||||
BeforeUpgradeHook = "before-upgrade"
|
BeforeUpgradeHook = "before-upgrade"
|
||||||
LuetDefaultRepoURI = "quay.io/costoolkit/releases-green"
|
|
||||||
LuetDefaultRepoPrio = 90
|
|
||||||
TransitionImgFile = "transition.img"
|
TransitionImgFile = "transition.img"
|
||||||
RunningStateDir = "/run/initramfs/cos-state" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
|
RunningStateDir = "/run/initramfs/cos-state" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
|
||||||
RunningRecoveryStateDir = "/run/initramfs/isoscan" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
|
RunningRecoveryStateDir = "/run/initramfs/isoscan" // TODO: converge this constant with StateDir/RecoveryDir in dracut module from cos-toolkit
|
||||||
@ -89,7 +83,6 @@ const (
|
|||||||
PassiveImgName = "passive"
|
PassiveImgName = "passive"
|
||||||
RecoveryImgName = "recovery"
|
RecoveryImgName = "recovery"
|
||||||
GPT = "gpt"
|
GPT = "gpt"
|
||||||
BuildImgName = "elemental"
|
|
||||||
UsrLocalPath = "/usr/local"
|
UsrLocalPath = "/usr/local"
|
||||||
OEMPath = "/oem"
|
OEMPath = "/oem"
|
||||||
|
|
||||||
@ -98,10 +91,6 @@ const (
|
|||||||
SELinuxTargetedContextFile = SELinuxTargetedPath + "/contexts/files/file_contexts"
|
SELinuxTargetedContextFile = SELinuxTargetedPath + "/contexts/files/file_contexts"
|
||||||
SELinuxTargetedPolicyPath = SELinuxTargetedPath + "/policy"
|
SELinuxTargetedPolicyPath = SELinuxTargetedPath + "/policy"
|
||||||
|
|
||||||
// These paths are arbitrary but coupled to grub.cfg
|
|
||||||
IsoKernelPath = "/boot/kernel"
|
|
||||||
IsoInitrdPath = "/boot/initrd"
|
|
||||||
|
|
||||||
// Default directory and file fileModes
|
// Default directory and file fileModes
|
||||||
DirPerm = os.ModeDir | os.ModePerm
|
DirPerm = os.ModeDir | os.ModePerm
|
||||||
FilePerm = 0666
|
FilePerm = 0666
|
||||||
@ -132,15 +121,6 @@ func GetDefaultSquashfsCompressionOptions() []string {
|
|||||||
return []string{"-comp", "gzip"}
|
return []string{"-comp", "gzip"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuildDiskDefaultPackages() map[string]string {
|
|
||||||
return map[string]string{
|
|
||||||
"channel:system/grub2-efi-image": "efi",
|
|
||||||
"channel:system/grub2-config": "root",
|
|
||||||
"channel:system/grub2-artifacts": "root/grub2",
|
|
||||||
"channel:recovery/cos-img": "root/cOS",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetGrubFilePaths(arch string) []string {
|
func GetGrubFilePaths(arch string) []string {
|
||||||
var archPath string
|
var archPath string
|
||||||
switch arch {
|
switch arch {
|
||||||
@ -163,3 +143,13 @@ func GetFallBackEfi(arch string) string {
|
|||||||
return "bootx64.efi"
|
return "bootx64.efi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGrubFonts returns the default font files for grub
|
||||||
|
func GetGrubFonts() []string {
|
||||||
|
return []string{"ascii.pf2", "euro.pf2", "unicode.pf2"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGrubModules returns the default module files for grub
|
||||||
|
func GetGrubModules() []string {
|
||||||
|
return []string{"loopback.mod", "squash4.mod", "xzio.mod", "gzio.mod"}
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ type Client struct {
|
|||||||
|
|
||||||
func NewClient() *Client {
|
func NewClient() *Client {
|
||||||
client := grab.NewClient()
|
client := grab.NewClient()
|
||||||
|
client.UserAgent = "Mozilla/5.0 (X11; Linux i686; rv:109.0) Gecko/20100101 Firefox/117.0"
|
||||||
client.HTTPClient = &http.Client{Timeout: time.Second * constants.HTTPTimeout}
|
client.HTTPClient = &http.Client{Timeout: time.Second * constants.HTTPTimeout}
|
||||||
return &Client{client: client}
|
return &Client{client: client}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
|
|||||||
// as they were before. We now use the bundled grub.efi provided by the shim package
|
// as they were before. We now use the bundled grub.efi provided by the shim package
|
||||||
g.config.Logger.Infof("Generating grub files for efi on %s", target)
|
g.config.Logger.Infof("Generating grub files for efi on %s", target)
|
||||||
var foundModules bool
|
var foundModules bool
|
||||||
for _, m := range []string{"loopback.mod", "squash4.mod", "xzio.mod", "gzio.mod"} {
|
for _, m := range constants.GetGrubModules() {
|
||||||
err = fsutils.WalkDirFs(g.config.Fs, rootDir, func(path string, d fs.DirEntry, err error) error {
|
err = fsutils.WalkDirFs(g.config.Fs, rootDir, func(path string, d fs.DirEntry, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -160,6 +160,8 @@ func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyGrubFonts(g.config, rootDir, grubdir, systemgrub)
|
||||||
|
|
||||||
err = fsutils.MkdirAll(g.config.Fs, filepath.Join(cnst.EfiDir, "EFI/boot/"), cnst.DirPerm)
|
err = fsutils.MkdirAll(g.config.Fs, filepath.Join(cnst.EfiDir, "EFI/boot/"), cnst.DirPerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.config.Logger.Errorf("Error creating dirs: %s", err)
|
g.config.Logger.Errorf("Error creating dirs: %s", err)
|
||||||
@ -225,3 +227,36 @@ func (g Grub) SetPersistentVariables(grubEnvFile string, vars map[string]string)
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copyGrubFonts will try to finds and copy the needed grub fonts into the system
|
||||||
|
// rootdir is the dir where to search for the fonts
|
||||||
|
// bootdir is the base dir where they will be copied
|
||||||
|
func copyGrubFonts(cfg *agentConfig.Config, rootDir, bootDir, systemgrub string) {
|
||||||
|
for _, m := range constants.GetGrubFonts() {
|
||||||
|
var foundFont bool
|
||||||
|
_ = fsutils.WalkDirFs(cfg.Fs, rootDir, func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if d.Name() == m && strings.Contains(path, cfg.Arch) {
|
||||||
|
fileWriteName := filepath.Join(bootDir, fmt.Sprintf("%s/%s-efi/fonts/%s", systemgrub, cfg.Arch, m))
|
||||||
|
cfg.Logger.Debugf("Copying %s to %s", path, fileWriteName)
|
||||||
|
fileContent, err := cfg.Fs.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error reading %s: %s", path, err)
|
||||||
|
}
|
||||||
|
err = cfg.Fs.WriteFile(fileWriteName, fileContent, cnst.FilePerm)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error writing %s: %s", fileWriteName, err)
|
||||||
|
}
|
||||||
|
foundFont = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if !foundFont {
|
||||||
|
// Not a real error as to fail install but a big warning
|
||||||
|
cfg.Logger.Warnf("did not find grub font %s under %s", m, rootDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user