github.com/shaardie/u-root@v4.0.1-0.20190127173353-f24a1c26aa2e+incompatible/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 "github.com/u-root/u-root/pkg/uroot/util" 12 "golang.org/x/sys/unix" 13 ) 14 15 // FileLoad loads the given kernel as the new kernel with the given ramfs and 16 // cmdline. 17 // 18 // The kexec_file_load(2) syscall is x86-64 bit only. 19 func FileLoad(kernel, ramfs *os.File, cmdline string) error { 20 var flags int 21 var ramfsfd int 22 if ramfs != nil { 23 ramfsfd = int(ramfs.Fd()) 24 } else { 25 flags |= unix.KEXEC_FILE_NO_INITRAMFS 26 } 27 28 if rsdp, _ := util.GetRSDP(); rsdp != "" { 29 cmdline += " acpi_rsdp=" + rsdp 30 } 31 32 if err := unix.KexecFileLoad(int(kernel.Fd()), ramfsfd, cmdline, flags); err != nil { 33 return fmt.Errorf("sys_kexec(%d, %d, %s, %x) = %v", kernel.Fd(), ramfsfd, cmdline, flags, err) 34 } 35 return nil 36 }