Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also install fonts when installing grub #144

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const (
PersistentPartName = "persistent"
OEMLabel = "COS_OEM"
OEMPartName = "oem"
ISOLabel = "COS_LIVE"
MountBinary = "/usr/bin/mount"
EfiDevice = "/sys/firmware/efi"
LinuxFs = "ext4"
Expand All @@ -50,8 +49,6 @@ const (
EfiFs = "vfat"
EfiSize = uint(64)
OEMSize = uint(64)
StateSize = uint(15360)
RecoverySize = uint(8192)
PersistentSize = uint(0)
BiosSize = uint(1)
ImgSize = uint(3072)
Expand All @@ -66,7 +63,6 @@ const (
EfiDir = "/run/cos/efi"
RecoverySquashFile = "recovery.squashfs"
IsoRootFile = "rootfs.squashfs"
IsoEFIPath = "/boot/uefi.img"
ActiveImgFile = "active.img"
PassiveImgFile = "passive.img"
RecoveryImgFile = "recovery.img"
Expand All @@ -80,16 +76,13 @@ const (
AfterUpgradeChrootHook = "after-upgrade-chroot"
AfterUpgradeHook = "after-upgrade"
BeforeUpgradeHook = "before-upgrade"
LuetDefaultRepoURI = "quay.io/costoolkit/releases-green"
LuetDefaultRepoPrio = 90
TransitionImgFile = "transition.img"
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
ActiveImgName = "active"
PassiveImgName = "passive"
RecoveryImgName = "recovery"
GPT = "gpt"
BuildImgName = "elemental"
UsrLocalPath = "/usr/local"
OEMPath = "/oem"

Expand All @@ -98,10 +91,6 @@ const (
SELinuxTargetedContextFile = SELinuxTargetedPath + "/contexts/files/file_contexts"
SELinuxTargetedPolicyPath = SELinuxTargetedPath + "/policy"

// These paths are arbitrary but coupled to grub.cfg
IsoKernelPath = "/boot/kernel"
IsoInitrdPath = "/boot/initrd"

// Default directory and file fileModes
DirPerm = os.ModeDir | os.ModePerm
FilePerm = 0666
Expand Down Expand Up @@ -132,15 +121,6 @@ func GetDefaultSquashfsCompressionOptions() []string {
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 {
var archPath string
switch arch {
Expand All @@ -163,3 +143,13 @@ func GetFallBackEfi(arch string) string {
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"}
}
1 change: 1 addition & 0 deletions pkg/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Client struct {

func NewClient() *Client {
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}
return &Client{client: client}
}
Expand Down
37 changes: 36 additions & 1 deletion pkg/utils/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
g.config.Logger.Infof("Generating grub files for efi on %s", target)
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 {
if err != nil {
return err
Expand All @@ -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)
if err != nil {
g.config.Logger.Errorf("Error creating dirs: %s", err)
Expand Down Expand Up @@ -225,3 +227,36 @@ func (g Grub) SetPersistentVariables(grubEnvFile string, vars map[string]string)
}
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) {
jimmykarily marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}
}