diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-10-13 15:45:24 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-10-13 16:16:11 +0200 |
| commit | 5462d47034cc5042a99e5df59da5c2677d5a9536 (patch) | |
| tree | f381bd18db082b7b2ea53418a81823bab420e040 /pkg/build/linux_linux.go | |
| parent | 2184365ea0e7d540acef17470dab3dc7ef93a27a (diff) | |
pkg/build: support linux kernel in more locations
Support all of /vmlinuz, /bzImage, /boot/vmlinuz, boot/bzImage.
Diffstat (limited to 'pkg/build/linux_linux.go')
| -rw-r--r-- | pkg/build/linux_linux.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/build/linux_linux.go b/pkg/build/linux_linux.go index 0a59f3fd7..b46356db3 100644 --- a/pkg/build/linux_linux.go +++ b/pkg/build/linux_linux.go @@ -51,7 +51,7 @@ func embedLinuxKernel(params Params, kernelPath string) error { return fmt.Errorf("mount(%vp1, %v) failed: %v", loopFile, mountDir, err) } defer unix.Unmount(mountDir, 0) - if err := osutil.CopyFile(kernelPath, filepath.Join(mountDir, "vmlinuz")); err != nil { + if err := copyKernel(mountDir, kernelPath); err != nil { return err } if params.SysctlFile != "" { @@ -65,6 +65,18 @@ func embedLinuxKernel(params Params, kernelPath string) error { return osutil.CopyFile(imageFile, filepath.Join(params.OutputDir, "image")) } +func copyKernel(mountDir, kernelPath string) error { + // Try several common locations where the kernel can be. + for _, targetPath := range []string{"boot/vmlinuz", "boot/bzImage", "vmlinuz", "bzImage"} { + fullPath := filepath.Join(mountDir, filepath.FromSlash(targetPath)) + if !osutil.IsExist(fullPath) { + continue + } + return osutil.CopyFile(kernelPath, fullPath) + } + return fmt.Errorf("did not find kernel in the template image") +} + func linuxSetupLoop(imageFile string) (int, string, error) { image, err := unix.Open(imageFile, unix.O_RDWR, 0) if err != nil { |
