github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/integration/testcmd/kexec/uinit/kexec.go (about) 1 // Copyright 2018 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 main 6 7 import ( 8 "fmt" 9 "log" 10 "os" 11 12 "golang.org/x/sys/unix" 13 14 "github.com/u-root/u-root/pkg/cmdline" 15 "github.com/u-root/u-root/pkg/sh" 16 ) 17 18 // Mount a vfat volume and kexec the kernel within. 19 func main() { 20 if err := os.MkdirAll("/testdata", 0755); err != nil { 21 log.Fatal(err) 22 } 23 sh.RunOrDie("mount", "-r", "-t", "vfat", "/dev/sda1", "/testdata") 24 25 // Get and increment the counter. 26 kExecCounter, ok := cmdline.Flag("kexeccounter") 27 if !ok { 28 kExecCounter = "0" 29 } 30 fmt.Printf("KEXECCOUNTER=%s\n", kExecCounter) 31 32 if kExecCounter == "0" { 33 cmdLine := cmdline.FullCmdLine() + " kexeccounter=1" 34 log.Print("cmdline: ", cmdLine) 35 sh.RunOrDie("kexec", 36 "-i", "/testdata/initramfs.cpio", 37 "-c", cmdLine, 38 "/testdata/bzImage") 39 } else { 40 unix.Reboot(unix.LINUX_REBOOT_CMD_POWER_OFF) 41 } 42 }