Skip to content

Commit a233f61

Browse files
authored
Allow custom path for grub.cfg (#144)
## Description Add the ability to specify custom location for `grub.cfg`. ## Why is this needed Ubuntu 24.04 cloud image mounts the `/boot` partition. The default `/boot/grub/grub.cfg` location is invalid when we mount the partition. The location when there is a `/boot` partition is `grub/grub.cfg`. Fixes: #142 ## How Has This Been Tested? - Tested on code vagrant with libvirt from https://github.com/tinkerbell/playground/blob/main/stack/docs/quickstarts/VAGRANTLVIRT.md - Test case 1 - Drop-in change with `jammy`. No `GRUBCFG_PATH`. I was able to ssh into `[email protected]`. - Test case 2 - Drop-in change with `noble`. No `GRUBCFG_PATH`. I was NOT able to ssh into `[email protected]`. Expected to fail as `noble` uses a `/boot` partition. - Test case 3 - Drop-in change with `noble`. The value for `GRUBCFG_PATH` was set to `grub/grub.cfg`. The value for `BLOCK_DEVICE` was set to `{{ formatPartition ( index .Hardware.Disks 0 ) 16 }}`. I was able to ssh into `[email protected]`. ## How are existing users impacted? What migration steps/scripts do we need? It uses the default value of `boot/grub/grub.cfg` for `GRUBCFG_PATH` if not specified. Existing users are not impacted. ## Checklist: I have: - [X] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade More info on Ubuntu 24.04 cloud image partition - https://bugs.launchpad.net/cloud-images/+bug/2072929
2 parents 30dc512 + 6d018d4 commit a233f61

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

kexec/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ the kexec action can mount the newly created Operating System and find it's kern
1313
paths should relate to the paths "inside" the newly provisioned OS along with the `CMD_LINE`
1414
that will be required to boot the new OS successfully. To discover these things you may need to
1515
examine the `/boot` folder in the newly written OS and look in the `/boot/grub/grub.cfg` to
16-
understand the `CMD_LINE`.
16+
understand the `CMD_LINE`. Sometimes `/boot/grub/grub.cfg` will exist as `/grub/grub.cfg` on a
17+
partition that is mounted as `/boot`. If this happens, use `GRUBCFG_PATH` with `grub/grub.cfg`.
1718

1819
```yaml
1920
actions:

kexec/cmd/kexec.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var kexecCmd = &cobra.Command{
3131
kernelPath := os.Getenv("KERNEL_PATH")
3232
initrdPath := os.Getenv("INITRD_PATH")
3333
cmdLine := os.Getenv("CMD_LINE")
34+
grubCfgPath := os.Getenv("GRUBCFG_PATH")
3435

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

43+
if grubCfgPath == "" {
44+
grubCfgPath = "boot/grub/grub.cfg"
45+
}
46+
4247
// Create the /mountAction mountpoint (no folders exist previously in scratch container)
4348
err := os.Mkdir(mountAction, os.ModeDir)
4449
if err != nil {
@@ -55,13 +60,13 @@ var kexecCmd = &cobra.Command{
5560
// If we specify no kernelPath then we will fallback to autodetect and ignore the initrd and cmdline that may be passed
5661
// by environment variables
5762
if kernelPath == "" {
58-
grubFile, err := ioutil.ReadFile(fmt.Sprintf("%s/boot/grub/grub.cfg", mountAction))
63+
grubFile, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", mountAction, grubCfgPath))
5964
if err != nil {
6065
log.Fatal(err)
6166
}
6267
bootConfig := grub.GetDefaultConfig(string(grubFile))
6368
if bootConfig == nil {
64-
log.Fatal("No Kernel configuration passed in [KERNEL_PATH] and unable to parse [/boot/grub/grub.conf]")
69+
log.Fatalf("No Kernel configuration passed in [KERNEL_PATH] and unable to parse [/%s]", grubCfgPath)
6570
}
6671
log.Infof("Loaded boot config: %#v", bootConfig)
6772
kernelMountPath = filepath.Join(mountAction, bootConfig.Kernel)

0 commit comments

Comments
 (0)