From d421c3c377da392cd091736348b834291892d86a Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 8 Apr 2022 14:29:42 +0000 Subject: pkg/build: detect fs type automatically in embedLinuxKernel() Now it's assumed to always be ext4, which is actually not always the case. Try to mount ext4, then try vfat. --- pkg/build/linux_linux.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'pkg/build/linux_linux.go') diff --git a/pkg/build/linux_linux.go b/pkg/build/linux_linux.go index adf830ea9..e0a36f34d 100644 --- a/pkg/build/linux_linux.go +++ b/pkg/build/linux_linux.go @@ -47,7 +47,7 @@ func embedLinuxKernel(params Params, kernelPath string) error { if err := osutil.MkdirAll(mountDir); err != nil { return err } - if err := unix.Mount(loopFile+"p1", mountDir, "ext4", 0, ""); err != nil { + if err := tryMount(loopFile+"p1", mountDir); err != nil { return fmt.Errorf("mount(%vp1, %v) failed: %v", loopFile, mountDir, err) } defer unix.Unmount(mountDir, 0) @@ -65,6 +65,22 @@ func embedLinuxKernel(params Params, kernelPath string) error { return osutil.CopyFile(imageFile, filepath.Join(params.OutputDir, "image")) } +func tryMount(device, mountDir string) error { + var err error +loop: + for _, fsType := range []string{"ext4", "vfat"} { + err = unix.Mount(device, mountDir, fsType, 0, "") + switch err { + case syscall.EINVAL: + // Most likely it just an invalid superblock error - try another fstype. + continue + case nil: + break loop + } + } + return err +} + 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", "Image.gz"} { -- cgit mrf-deployment