forked from rancher/k3os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (42 loc) · 1.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
// Copyright 2019 Rancher Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import (
"os"
"path/filepath"
"github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/reexec"
"github.com/rancher/k3os/pkg/cli/app"
"github.com/rancher/k3os/pkg/enterchroot"
"github.com/rancher/k3os/pkg/transferroot"
"github.com/sirupsen/logrus"
)
func main() {
reexec.Register("/init", initrd) // mode=live
reexec.Register("/sbin/init", initrd) // mode=local
reexec.Register("enter-root", enterchroot.Enter)
if !reexec.Init() {
app := app.New()
args := []string{app.Name}
path := filepath.Base(os.Args[0])
if path != app.Name && app.Command(path) != nil {
args = append(args, path)
}
args = append(args, os.Args[1:]...)
// this will bomb if the app has any non-defaulted, required flags
err := app.Run(args)
if err != nil {
logrus.Fatal(err)
}
}
}
func initrd() {
enterchroot.DebugCmdline = "k3os.debug"
transferroot.Relocate()
if err := mount.Mount("", "/", "none", "rw,remount"); err != nil {
logrus.Errorf("failed to remount root as rw: %v", err)
}
if err := enterchroot.Mount("./k3os/data", os.Args, os.Stdout, os.Stderr); err != nil {
logrus.Fatalf("failed to enter root: %v", err)
}
}