From d0407197ba7cea0b5cdeb67012180fb5d87f0e19 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 29 Jan 2021 13:02:28 +0100 Subject: pkg/build: add a new way of building linux images Add a new, simpler procedure: working bootable image is accepted as an input and we only replace the kernel in it. This just looks much saner and the right way to do it (instead of assembling the image from bits and shelling out to mkfs, fdisk, grub, etc). The new way also works inside of containers much better. --- pkg/build/linux.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'pkg/build/linux.go') diff --git a/pkg/build/linux.go b/pkg/build/linux.go index f08455c39..be2341311 100644 --- a/pkg/build/linux.go +++ b/pkg/build/linux.go @@ -31,20 +31,20 @@ func (linux linux) build(params *Params) error { return err } kernelPath := filepath.Join(params.KernelDir, filepath.FromSlash(kernelBin(params.TargetArch))) - if fileInfo, err := os.Stat(params.UserspaceDir); err == nil && !fileInfo.IsDir() && params.VMType == "qemu" { + if fileInfo, err := os.Stat(params.UserspaceDir); err == nil && fileInfo.IsDir() { + // The old way of assembling the image from userspace dir. + // It should be removed once all syzbot instances are switched. + return linux.createImage(params, kernelPath) + } + if params.VMType == "qemu" { // If UserspaceDir is a file (image) and we use qemu, we just copy image and kernel to the output dir // assuming that qemu will use injected kernel boot. In this mode we also assume password/key-less ssh. - // In future it would be good to switch to accepting complete disk image always and just replacing - // kernel in it for GCE VMs (assembling image from userspace files in createImage isn't reasonable). if err := osutil.CopyFile(kernelPath, filepath.Join(params.OutputDir, "kernel")); err != nil { return err } return osutil.CopyFile(params.UserspaceDir, filepath.Join(params.OutputDir, "image")) } - if err := linux.createImage(params, kernelPath); err != nil { - return err - } - return nil + return embedLinuxKernel(params, kernelPath) } func (linux linux) sign(params *Params) (string, error) { -- cgit mrf-deployment