github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/pkg/kexec/kexec_linux_amd64.go (about)

     1  // Copyright 2015-2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package kexec
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  // FileLoad loads the given kernel as the new kernel with the given ramfs and
    15  // cmdline.
    16  //
    17  // The kexec_file_load(2) syscall is x86-64 bit only.
    18  func FileLoad(kernel, ramfs *os.File, cmdline string) error {
    19  	var flags int
    20  	var ramfsfd int
    21  	if ramfs != nil {
    22  		ramfsfd = int(ramfs.Fd())
    23  	} else {
    24  		flags |= unix.KEXEC_FILE_NO_INITRAMFS
    25  	}
    26  
    27  	if err := unix.KexecFileLoad(int(kernel.Fd()), ramfsfd, cmdline, flags); err != nil {
    28  		return fmt.Errorf("sys_kexec(%d, %d, %s, %x) = %v", kernel.Fd(), ramfsfd, cmdline, flags, err)
    29  	}
    30  	return nil
    31  }