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

Allow custom path for grub.cfg #144

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion kexec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ the kexec action can mount the newly created Operating System and find it's kern
paths should relate to the paths "inside" the newly provisioned OS along with the `CMD_LINE`
that will be required to boot the new OS successfully. To discover these things you may need to
examine the `/boot` folder in the newly written OS and look in the `/boot/grub/grub.cfg` to
understand the `CMD_LINE`.
understand the `CMD_LINE`. Sometimes `/boot/grub/grub.cfg` will exist as `/grub/grub.cfg` on a
partition that is mounted as `/boot`. If this happens, use `GRUBCFG_PATH` with `grub/grub.cfg`.

```yaml
actions:
Expand Down
9 changes: 7 additions & 2 deletions kexec/cmd/kexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var kexecCmd = &cobra.Command{
kernelPath := os.Getenv("KERNEL_PATH")
initrdPath := os.Getenv("INITRD_PATH")
cmdLine := os.Getenv("CMD_LINE")
grubCfgPath := os.Getenv("GRUBCFG_PATH")

// These two strings contain the updated paths including the mountAction path
var kernelMountPath, initrdMountPath string
Expand All @@ -39,6 +40,10 @@ var kexecCmd = &cobra.Command{
log.Fatalf("No Block Device speified with Environment Variable [BLOCK_DEVICE]")
}

if grubCfgPath == "" {
grubCfgPath = "boot/grub/grub.cfg"
}

// Create the /mountAction mountpoint (no folders exist previously in scratch container)
err := os.Mkdir(mountAction, os.ModeDir)
if err != nil {
Expand All @@ -55,13 +60,13 @@ var kexecCmd = &cobra.Command{
// If we specify no kernelPath then we will fallback to autodetect and ignore the initrd and cmdline that may be passed
// by environment variables
if kernelPath == "" {
grubFile, err := ioutil.ReadFile(fmt.Sprintf("%s/boot/grub/grub.cfg", mountAction))
grubFile, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", mountAction, grubCfgPath))
if err != nil {
log.Fatal(err)
}
bootConfig := grub.GetDefaultConfig(string(grubFile))
if bootConfig == nil {
log.Fatal("No Kernel configuration passed in [KERNEL_PATH] and unable to parse [/boot/grub/grub.conf]")
log.Fatalf("No Kernel configuration passed in [KERNEL_PATH] and unable to parse [/%s]", grubCfgPath)
}
log.Infof("Loaded boot config: %#v", bootConfig)
kernelMountPath = filepath.Join(mountAction, bootConfig.Kernel)
Expand Down