github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/switch_root/switch_root_linux.go (about) 1 // Copyright 2012-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 //go:build linux 6 // +build linux 7 8 package main 9 10 import ( 11 "flag" 12 "fmt" 13 "log" 14 "os" 15 16 "github.com/mvdan/u-root-coreutils/pkg/mount" 17 ) 18 19 var ( 20 help = flag.Bool("h", false, "Help") 21 version = flag.Bool("V", false, "Version") 22 ) 23 24 func usage() string { 25 return "switch_root [-h] [-V]\nswitch_root newroot init" 26 } 27 28 func main() { 29 flag.Parse() 30 31 if len(flag.Args()) == 0 { 32 fmt.Println(usage()) 33 os.Exit(0) 34 } 35 36 if *help { 37 fmt.Println(usage()) 38 os.Exit(0) 39 } 40 41 if *version { 42 fmt.Println("Version XX") 43 os.Exit(0) 44 } 45 46 newRoot := flag.Args()[0] 47 init := flag.Args()[1] 48 49 if err := mount.SwitchRoot(newRoot, init); err != nil { 50 log.Fatalf("switch_root failed %v\n", err) 51 } 52 }