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