initrd/boot-v2.go

94 lines
1.7 KiB
Go
Raw Normal View History

2022-02-04 18:59:42 +00:00
package main
import (
"log"
"os"
"os/exec"
"gopkg.in/yaml.v3"
2022-04-04 08:29:28 +00:00
config "novit.tech/direktil/pkg/bootstrapconfig"
)
2022-02-04 18:59:42 +00:00
func bootV2() {
log.Print("-- boot v2 --")
2023-12-04 12:59:37 +00:00
kernelVersion := unameRelease()
log.Print("Linux version ", kernelVersion)
cfg := &config.Config{}
{
f, err := os.Open("/config.yaml")
if err != nil {
fatal("failed to open /config.yaml: ", err)
}
err = yaml.NewDecoder(f).Decode(cfg)
f.Close()
if err != nil {
fatal("failed to parse /config.yaml: ", err)
}
}
log.Print("config loaded")
2023-12-17 12:48:18 +00:00
log.Printf("\n\nanti-phishing code: %q\n", cfg.AntiPhishingCode)
auths = cfg.Auths
// mount kernel modules
2023-12-04 12:59:37 +00:00
if cfg.Modules == "" {
log.Print("NOT mounting modules (nothing specified)")
} else {
mountSquahfs(cfg.Modules, "/modules")
modulesSourcePath := "/modules/lib/modules/" + kernelVersion
if _, err := os.Stat(modulesSourcePath); err != nil {
fatal("invalid modules dir: ", err)
}
2023-12-04 12:59:37 +00:00
os.MkdirAll("/lib/modules", 0755)
if err := os.Symlink(modulesSourcePath, "/lib/modules/"+kernelVersion); err != nil {
fatal("failed to symlink modules: ", err)
}
}
// load basic modules
run("modprobe", "unix")
// devices init
err := exec.Command("udevd").Start()
if err != nil {
fatal("failed to start udevd: ", err)
}
log.Print("udevadm triggers")
run("udevadm", "trigger", "-c", "add", "-t", "devices")
run("udevadm", "trigger", "-c", "add", "-t", "subsystems")
log.Print("udevadm settle")
run("udevadm", "settle")
// networks
setupNetworks(cfg)
// Wireguard VPN
// TODO startVPN()
// SSH service
startSSH(cfg)
2023-12-17 12:48:18 +00:00
// dmcrypt blockdevs
setupCrypt(cfg.PreLVMCrypt, map[string]string{})
// LVM
setupLVM(cfg)
// bootstrap the system
bootstrap(cfg)
// finalize
finalizeBoot()
2022-02-04 18:59:42 +00:00
}