aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build/linux_linux.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2022-04-08 14:29:42 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2022-04-08 18:59:03 +0200
commitd421c3c377da392cd091736348b834291892d86a (patch)
tree1b6a4bcf5199fc974f815575fc69e2f8cebfddf4 /pkg/build/linux_linux.go
parent15be3cba18ad18776c6558e25792768113164e9d (diff)
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.
Diffstat (limited to 'pkg/build/linux_linux.go')
-rw-r--r--pkg/build/linux_linux.go18
1 files changed, 17 insertions, 1 deletions
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"} {