-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
94 lines (83 loc) · 2.21 KB
/
init.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strings"
"syscall"
)
var (
cmdline []string
debug bool = false
)
func init() {
var err error
if _, err := os.Stat("/proc"); err != nil {
err = os.Mkdir("/proc", 0755)
if err != nil {
fmt.Printf("failed to create /proc: %s\n", err.Error())
}
}
err = syscall.Mount("proc", "/proc", "proc", 0, "")
if err != nil {
fmt.Printf("failed to mount /proc: %s\n", err.Error())
os.Exit(1)
}
buf, err := ioutil.ReadFile("/proc/cmdline")
if err != nil {
fmt.Printf("failed to read /proc/cmdline: %s\n", err)
os.Exit(1)
}
cmdline = strings.Split(strings.TrimSpace(string(buf)), " ")
debug = cmdlineBool("debug")
if _, err := os.Stat("/sys"); err != nil {
err = os.Mkdir("/sys", 0755)
if err != nil {
fmt.Printf("failed to create /sys: %s\n", err.Error())
}
}
err = syscall.Mount("sys", "/sys", "sysfs", 0, "")
if err != nil {
fmt.Printf("failed to mount /sys: %s\n", err.Error())
os.Exit(1)
}
if _, err = os.Stat("/dev"); err != nil {
err = os.Mkdir("/dev", 0755)
if err != nil {
fmt.Printf("failed to create /dev: %s\n", err.Error())
os.Exit(1)
}
}
err = syscall.Mount("devtmpfs", "/dev", "devtmpfs", 0, "mode=0755")
if err != nil {
fmt.Printf("failed to mount /dev: %s\n", err.Error())
os.Exit(1)
}
if _, err := os.Stat("/dev/pts"); err != nil {
err = os.Mkdir("/dev/pts", 0755)
if err != nil {
fmt.Printf("failed to create /dev/pts: %s\n", err.Error())
}
}
err = syscall.Mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620")
if err != nil {
fmt.Printf("failed to mount /dev/pts: %s\n", err.Error())
os.Exit(1)
}
if _, err := os.Stat("/mnt"); err != nil {
err = os.Mkdir("/mnt", 0755)
if err != nil {
fmt.Printf("failed to create /mnt: %s\n", err.Error())
}
}
/*
cmd := exec.Command("/bin/busybox", "--help", "|", "/bin/busybox", "grep", "'Currently defined functions:'", "-A300", "|", "/bin/busybox", "grep", "-v", "'Currently defined functions:'", "|", "/bin/busybox", "tr", ",", "'\n'", "|", "/bin/busybox", "xargs", "-n1", "/bin/busybox", "ln", "-s", "busybox")
cmd.Dir = "/bin"
err = cmd.Run()
if err != nil {
fmt.Printf(err.Error())
}
*/
runtime.GOMAXPROCS(runtime.NumCPU())
}