From eeebf0ae0f027758eba05c1cfa9b2ebec3238f56 Mon Sep 17 00:00:00 2001 From: niusmallnan Date: Sun, 30 Sep 2018 14:30:25 +0800 Subject: [PATCH] Mount the boot partition when booting Also update StateDir and OemDir for better clarity --- cmd/control/install.go | 36 +-- cmd/control/install/install.go | 4 +- cmd/init/init.go | 7 +- cmd/power/power.go | 2 +- config/schema.go | 368 ++++++++++++++-------------- config/types.go | 9 +- os-config.tpl.yml | 2 + pkg/init/cloudinit/cloudinit.go | 2 +- pkg/init/configfiles/configfiles.go | 2 +- pkg/init/fsmount/fsmount.go | 30 ++- pkg/init/switchroot/root.go | 6 +- pkg/sysinit/sysinit.go | 2 +- 12 files changed, 244 insertions(+), 226 deletions(-) diff --git a/cmd/control/install.go b/cmd/control/install.go index 1d497346..9678a947 100644 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -560,20 +560,20 @@ func layDownOS(image, installType, cloudConfig, device, partition, statedir, kap kernelArgs = kernelArgs + " console=" + CONSOLE if kappend == "" { - preservedAppend, _ := ioutil.ReadFile(filepath.Join(baseName, install.BootDir+"append")) + preservedAppend, _ := ioutil.ReadFile(filepath.Join(baseName, config.BootDir, "append")) kappend = string(preservedAppend) } else { - ioutil.WriteFile(filepath.Join(baseName, install.BootDir+"append"), []byte(kappend), 0644) + ioutil.WriteFile(filepath.Join(baseName, config.BootDir, "append"), []byte(kappend), 0644) } if installType == "amazon-ebs-pv" { menu := install.BootVars{ BaseName: baseName, - BootDir: install.BootDir, + BootDir: config.BootDir, Timeout: 0, Fallback: 0, // need to be conditional on there being a 'rollback'? Entries: []install.MenuEntry{ - install.MenuEntry{"RancherOS-current", install.BootDir, VERSION, kernelArgs, kappend}, + install.MenuEntry{"RancherOS-current", config.BootDir, VERSION, kernelArgs, kappend}, }, } install.PvGrubConfig(menu) @@ -587,7 +587,7 @@ func layDownOS(image, installType, cloudConfig, device, partition, statedir, kap log.Debugf("installRancher done") if kexec { - power.Kexec(false, filepath.Join(baseName, install.BootDir), kernelArgs+" "+kappend) + power.Kexec(false, filepath.Join(baseName, config.BootDir), kernelArgs+" "+kappend) } return nil @@ -801,7 +801,7 @@ func setBootable(device, diskType string) error { func upgradeBootloader(device, baseName, diskType string) error { log.Debugf("start upgradeBootloader") - grubDir := filepath.Join(baseName, install.BootDir+"grub") + grubDir := filepath.Join(baseName, config.BootDir, "grub") if _, err := os.Stat(grubDir); os.IsNotExist(err) { log.Debugf("%s does not exist - no need to upgrade bootloader", grubDir) // we've already upgraded @@ -809,12 +809,12 @@ func upgradeBootloader(device, baseName, diskType string) error { return nil } // deal with systems which were previously upgraded, then rolled back, and are now being re-upgraded - grubBackup := filepath.Join(baseName, install.BootDir+"grub_backup") + grubBackup := filepath.Join(baseName, config.BootDir, "grub_backup") if err := os.RemoveAll(grubBackup); err != nil { log.Errorf("RemoveAll (%s): %s", grubBackup, err) return err } - backupSyslinuxDir := filepath.Join(baseName, install.BootDir+"syslinux_backup") + backupSyslinuxDir := filepath.Join(baseName, config.BootDir, "syslinux_backup") if _, err := os.Stat(backupSyslinuxDir); !os.IsNotExist(err) { backupSyslinuxLdlinuxSys := filepath.Join(backupSyslinuxDir, "ldlinux.sys") if _, err := os.Stat(backupSyslinuxLdlinuxSys); !os.IsNotExist(err) { @@ -837,7 +837,7 @@ func upgradeBootloader(device, baseName, diskType string) error { return err } - syslinuxDir := filepath.Join(baseName, install.BootDir+"syslinux") + syslinuxDir := filepath.Join(baseName, config.BootDir, "syslinux") // it seems that v0.5.0 didn't have a syslinux dir, while 0.7 does if _, err := os.Stat(syslinuxDir); !os.IsNotExist(err) { if err := os.Rename(syslinuxDir, backupSyslinuxDir); err != nil { @@ -858,15 +858,15 @@ func upgradeBootloader(device, baseName, diskType string) error { cfg = strings.Replace(cfg, "current", "previous", -1) // TODO consider removing the APPEND line - as the global.cfg should have the same result - ioutil.WriteFile(filepath.Join(baseName, install.BootDir, "linux-current.cfg"), []byte(cfg), 0644) + ioutil.WriteFile(filepath.Join(baseName, config.BootDir, "linux-current.cfg"), []byte(cfg), 0644) lines := strings.Split(cfg, "\n") for _, line := range lines { line = strings.TrimSpace(line) if strings.HasPrefix(line, "APPEND") { - log.Errorf("write new (%s) %s", filepath.Join(baseName, install.BootDir, "global.cfg"), err) + log.Errorf("write new (%s) %s", filepath.Join(baseName, config.BootDir, "global.cfg"), err) // TODO: need to append any extra's the user specified - ioutil.WriteFile(filepath.Join(baseName, install.BootDir, "global.cfg"), []byte(cfg), 0644) + ioutil.WriteFile(filepath.Join(baseName, config.BootDir, "global.cfg"), []byte(cfg), 0644) break } } @@ -927,7 +927,7 @@ func installSyslinux(device, baseName, diskType string) error { } } - sysLinuxDir := filepath.Join(baseName, install.BootDir, "syslinux") + sysLinuxDir := filepath.Join(baseName, config.BootDir, "syslinux") if err := os.MkdirAll(sysLinuxDir, 0755); err != nil { log.Errorf("MkdirAll(%s)): %s", sysLinuxDir, err) //return err @@ -985,12 +985,12 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) { log.Debugf("installRancher") // detect if there already is a linux-current.cfg, if so, move it to linux-previous.cfg, - currentCfg := filepath.Join(baseName, install.BootDir, "linux-current.cfg") + currentCfg := filepath.Join(baseName, config.BootDir, "linux-current.cfg") if _, err := os.Stat(currentCfg); !os.IsNotExist(err) { existingCfg := filepath.Join(DIST, "linux-current.cfg") // only remove previous if there is a change to the current if different(currentCfg, existingCfg) { - previousCfg := filepath.Join(baseName, install.BootDir, "linux-previous.cfg") + previousCfg := filepath.Join(baseName, config.BootDir, "linux-previous.cfg") if _, err := os.Stat(previousCfg); !os.IsNotExist(err) { if err := os.Remove(previousCfg); err != nil { return currentCfg, err @@ -1012,7 +1012,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) { if file.Name() == "global.cfg" { overwrite = false } - if err := dfs.CopyFileOverwrite(filepath.Join(DIST, file.Name()), filepath.Join(baseName, install.BootDir), file.Name(), overwrite); err != nil { + if err := dfs.CopyFileOverwrite(filepath.Join(DIST, file.Name()), filepath.Join(baseName, config.BootDir), file.Name(), overwrite); err != nil { log.Errorf("copy %s: %s", file.Name(), err) //return err } @@ -1020,7 +1020,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) { // the general INCLUDE syslinuxcfg isolinuxFile := filepath.Join(DIST, "isolinux", "isolinux.cfg") - syslinuxDir := filepath.Join(baseName, install.BootDir, "syslinux") + syslinuxDir := filepath.Join(baseName, config.BootDir, "syslinux") if err := dfs.CopyFileOverwrite(isolinuxFile, syslinuxDir, "syslinux.cfg", true); err != nil { log.Errorf("copy global syslinux.cfgS%s: %s", "syslinux.cfg", err) //return err @@ -1030,7 +1030,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) { } // The global.cfg INCLUDE - useful for over-riding the APPEND line - globalFile := filepath.Join(filepath.Join(baseName, install.BootDir), "global.cfg") + globalFile := filepath.Join(baseName, config.BootDir, "global.cfg") if _, err := os.Stat(globalFile); !os.IsNotExist(err) { err := ioutil.WriteFile(globalFile, []byte("APPEND "+kappend), 0644) if err != nil { diff --git a/cmd/control/install/install.go b/cmd/control/install/install.go index 3b2bb2a1..125c2203 100644 --- a/cmd/control/install/install.go +++ b/cmd/control/install/install.go @@ -11,8 +11,6 @@ import ( "github.com/rancher/os/pkg/util" ) -const BootDir = "boot/" - type MenuEntry struct { Name, BootDir, Version, KernelArgs, Append string } @@ -53,7 +51,7 @@ func MountDevice(baseName, device, partition string, raw bool) (string, string, } if d != "" { partition = d - baseName = filepath.Join(baseName, BootDir) + baseName = filepath.Join(baseName, config.BootDir) } else { if dev := util.ResolveDevice(cfg.Rancher.State.Dev); dev != "" { // try the rancher.state.dev setting diff --git a/cmd/init/init.go b/cmd/init/init.go index c881575f..fb018e66 100644 --- a/cmd/init/init.go +++ b/cmd/init/init.go @@ -48,16 +48,17 @@ func RunInit() error { {"set env", env.Init}, {"preparefs", prepare.FS}, {"save init cmdline", prepare.SaveCmdline}, - {"mount OEM", fsmount.OEM}, + {"mount OEM", fsmount.MountOem}, {"debug save cfg", debug.PrintAndLoadConfig}, {"load modules", modules.LoadModules}, {"recovery console", recovery.LoadRecoveryConsole}, {"cloud-init", cloudinit.CloudInit}, {"b2d env", b2d.B2D}, - {"mount and bootstrap", fsmount.MountAndBootstrap}, + {"mount STATE and bootstrap", fsmount.MountStateAndBootstrap}, {"read cfg and log files", configfiles.ReadConfigFiles}, {"switchroot", switchroot.SwitchRoot}, - {"mount OEM2", fsmount.OEM}, + {"mount OEM2", fsmount.MountOem}, + {"mount BOOT", fsmount.MountBoot}, {"write cfg and log files", configfiles.WriteConfigFiles}, {"hypervisor Env", hypervisor.Env}, {"b2d Env", b2d.Env}, diff --git a/cmd/power/power.go b/cmd/power/power.go index 851a85ff..f4495a66 100644 --- a/cmd/power/power.go +++ b/cmd/power/power.go @@ -178,7 +178,7 @@ func reboot(name string, force bool, code uint) { return } defer util.Unmount(baseName) - Kexec(previouskexecFlag, filepath.Join(baseName, install.BootDir), kexecAppendFlag) + Kexec(previouskexecFlag, filepath.Join(baseName, config.BootDir), kexecAppendFlag) return } diff --git a/config/schema.go b/config/schema.go index f6f2b490..47a55412 100644 --- a/config/schema.go +++ b/config/schema.go @@ -1,209 +1,211 @@ package config var schema = `{ - "type": "object", - "additionalProperties": false, + "type": "object", + "additionalProperties": false, - "properties": { - "ssh_authorized_keys": {"$ref": "#/definitions/list_of_strings"}, - "write_files": { - "type": "array", - "items": {"$ref": "#/definitions/file_config"} - }, - "hostname": {"type": "string"}, - "mounts": {"type": "array"}, - "rancher": {"$ref": "#/definitions/rancher_config"}, - "runcmd": {"type": "array"}, - "bootcmd": {"type": "array"} - }, + "properties": { + "ssh_authorized_keys": {"$ref": "#/definitions/list_of_strings"}, + "write_files": { + "type": "array", + "items": {"$ref": "#/definitions/file_config"} + }, + "hostname": {"type": "string"}, + "mounts": {"type": "array"}, + "rancher": {"$ref": "#/definitions/rancher_config"}, + "runcmd": {"type": "array"}, + "bootcmd": {"type": "array"} + }, - "definitions": { - "rancher_config": { - "id": "#/definitions/rancher_config", - "type": "object", - "additionalProperties": false, + "definitions": { + "rancher_config": { + "id": "#/definitions/rancher_config", + "type": "object", + "additionalProperties": false, - "properties": { - "console": {"type": "string"}, - "environment": {"type": "object"}, - "cloud_init_services": {"type": "object"}, - "services": {"type": "object"}, - "bootstrap": {"type": "object"}, - "autoformat": {"type": "object"}, - "bootstrap_docker": {"$ref": "#/definitions/docker_config"}, - "cloud_init": {"$ref": "#/definitions/cloud_init_config"}, - "debug": {"type": "boolean"}, - "rm_usr": {"type": "boolean"}, - "no_sharedroot": {"type": "boolean"}, - "log": {"type": "boolean"}, - "force_console_rebuild": {"type": "boolean"}, - "recovery": {"type": "boolean"}, - "disable": {"$ref": "#/definitions/list_of_strings"}, - "services_include": {"type": "object"}, - "modules": {"$ref": "#/definitions/list_of_strings"}, - "network": {"$ref": "#/definitions/network_config"}, - "default_network": {"type": "object"}, - "repositories": {"type": "object"}, - "ssh": {"$ref": "#/definitions/ssh_config"}, - "state": {"$ref": "#/definitions/state_config"}, - "system_docker": {"$ref": "#/definitions/docker_config"}, - "upgrade": {"$ref": "#/definitions/upgrade_config"}, - "docker": {"$ref": "#/definitions/docker_config"}, - "registry_auths": {"type": "object"}, - "defaults": {"$ref": "#/definitions/defaults_config"}, - "resize_device": {"type": "string"}, - "sysctl": {"type": "object"}, - "restart_services": {"type": "array"}, - "hypervisor_service": {"type": "boolean"}, - "shutdown_timeout": {"type": "integer"}, - "preload_wait": {"type": "boolean"} - } - }, + "properties": { + "console": {"type": "string"}, + "environment": {"type": "object"}, + "cloud_init_services": {"type": "object"}, + "services": {"type": "object"}, + "bootstrap": {"type": "object"}, + "autoformat": {"type": "object"}, + "bootstrap_docker": {"$ref": "#/definitions/docker_config"}, + "cloud_init": {"$ref": "#/definitions/cloud_init_config"}, + "debug": {"type": "boolean"}, + "rm_usr": {"type": "boolean"}, + "no_sharedroot": {"type": "boolean"}, + "log": {"type": "boolean"}, + "force_console_rebuild": {"type": "boolean"}, + "recovery": {"type": "boolean"}, + "disable": {"$ref": "#/definitions/list_of_strings"}, + "services_include": {"type": "object"}, + "modules": {"$ref": "#/definitions/list_of_strings"}, + "network": {"$ref": "#/definitions/network_config"}, + "default_network": {"type": "object"}, + "repositories": {"type": "object"}, + "ssh": {"$ref": "#/definitions/ssh_config"}, + "state": {"$ref": "#/definitions/state_config"}, + "system_docker": {"$ref": "#/definitions/docker_config"}, + "upgrade": {"$ref": "#/definitions/upgrade_config"}, + "docker": {"$ref": "#/definitions/docker_config"}, + "registry_auths": {"type": "object"}, + "defaults": {"$ref": "#/definitions/defaults_config"}, + "resize_device": {"type": "string"}, + "sysctl": {"type": "object"}, + "restart_services": {"type": "array"}, + "hypervisor_service": {"type": "boolean"}, + "shutdown_timeout": {"type": "integer"}, + "preload_wait": {"type": "boolean"} + } + }, - "file_config": { - "id": "#/definitions/file_config", - "type": "object", - "additionalProperties": false, + "file_config": { + "id": "#/definitions/file_config", + "type": "object", + "additionalProperties": false, - "properties": { - "encoding": {"type": "string"}, - "container": {"type": "string"}, - "content": {"type": "string"}, - "owner": {"type": "string"}, - "path": {"type": "string"}, - "permissions": {"type": "string"} - } - }, + "properties": { + "encoding": {"type": "string"}, + "container": {"type": "string"}, + "content": {"type": "string"}, + "owner": {"type": "string"}, + "path": {"type": "string"}, + "permissions": {"type": "string"} + } + }, - "network_config": { - "id": "#/definitions/network_config", - "type": "object", - "additionalProperties": false, + "network_config": { + "id": "#/definitions/network_config", + "type": "object", + "additionalProperties": false, - "properties": { - "pre_cmds": {"$ref": "#/definitions/list_of_strings"}, - "dns": {"type": "object"}, - "interfaces": {"type": "object"}, - "post_cmds": {"$ref": "#/definitions/list_of_strings"}, - "http_proxy": {"type": "string"}, - "https_proxy": {"type": "string"}, - "no_proxy": {"type": "string"} - } - }, + "properties": { + "pre_cmds": {"$ref": "#/definitions/list_of_strings"}, + "dns": {"type": "object"}, + "interfaces": {"type": "object"}, + "post_cmds": {"$ref": "#/definitions/list_of_strings"}, + "http_proxy": {"type": "string"}, + "https_proxy": {"type": "string"}, + "no_proxy": {"type": "string"} + } + }, - "upgrade_config": { - "id": "#/definitions/upgrade_config", - "type": "object", - "additionalProperties": false, + "upgrade_config": { + "id": "#/definitions/upgrade_config", + "type": "object", + "additionalProperties": false, - "properties": { - "url": {"type": "string"}, - "image": {"type": "string"}, - "rollback": {"type": "string"} - } - }, + "properties": { + "url": {"type": "string"}, + "image": {"type": "string"}, + "rollback": {"type": "string"} + } + }, - "docker_config": { - "id": "#/definitions/docker_config", - "type": "object", - "additionalProperties": false, + "docker_config": { + "id": "#/definitions/docker_config", + "type": "object", + "additionalProperties": false, - "properties": { - "engine": {"type": "string"}, - "tls": {"type": "boolean"}, - "tls_args": {"$ref": "#/definitions/list_of_strings"}, - "args": {"$ref": "#/definitions/list_of_strings"}, - "extra_args": {"$ref": "#/definitions/list_of_strings"}, - "server_cert": {"type": "string"}, - "server_key": {"type": "string"}, - "ca_cert": {"type": "string"}, - "ca_key": {"type": "string"}, - "environment": {"$ref": "#/definitions/list_of_strings"}, - "storage_context": {"type": "string"}, - "exec": {"type": ["boolean", "null"]}, - "bridge": {"type": "string"}, - "bip": {"type": "string"}, - "config_file": {"type": "string"}, - "containerd": {"type": "string"}, - "debug": {"type": ["boolean", "null"]}, - "exec_root": {"type": "string"}, - "group": {"type": "string"}, - "graph": {"type": "string"}, - "host": {"type": "array"}, - "live_restore": {"type": ["boolean", "null"]}, - "log_driver": {"type": "string"}, - "log_opts": {"type": "object"}, - "pid_file": {"type": "string"}, - "registry_mirror": {"type": "string"}, - "restart": {"type": ["boolean", "null"]}, - "selinux_enabled": {"type": ["boolean", "null"]}, - "storage_driver": {"type": "string"}, - "userland_proxy": {"type": ["boolean", "null"]}, - "insecure_registry": {"$ref": "#/definitions/list_of_strings"} - } - }, + "properties": { + "engine": {"type": "string"}, + "tls": {"type": "boolean"}, + "tls_args": {"$ref": "#/definitions/list_of_strings"}, + "args": {"$ref": "#/definitions/list_of_strings"}, + "extra_args": {"$ref": "#/definitions/list_of_strings"}, + "server_cert": {"type": "string"}, + "server_key": {"type": "string"}, + "ca_cert": {"type": "string"}, + "ca_key": {"type": "string"}, + "environment": {"$ref": "#/definitions/list_of_strings"}, + "storage_context": {"type": "string"}, + "exec": {"type": ["boolean", "null"]}, + "bridge": {"type": "string"}, + "bip": {"type": "string"}, + "config_file": {"type": "string"}, + "containerd": {"type": "string"}, + "debug": {"type": ["boolean", "null"]}, + "exec_root": {"type": "string"}, + "group": {"type": "string"}, + "graph": {"type": "string"}, + "host": {"type": "array"}, + "live_restore": {"type": ["boolean", "null"]}, + "log_driver": {"type": "string"}, + "log_opts": {"type": "object"}, + "pid_file": {"type": "string"}, + "registry_mirror": {"type": "string"}, + "restart": {"type": ["boolean", "null"]}, + "selinux_enabled": {"type": ["boolean", "null"]}, + "storage_driver": {"type": "string"}, + "userland_proxy": {"type": ["boolean", "null"]}, + "insecure_registry": {"$ref": "#/definitions/list_of_strings"} + } + }, - "ssh_config": { - "id": "#/definitions/ssh_config", - "type": "object", - "additionalProperties": false, + "ssh_config": { + "id": "#/definitions/ssh_config", + "type": "object", + "additionalProperties": false, - "properties": { - "keys": {"type": "object"}, - "daemon": {"type": "boolean"}, - "port": {"type": "integer"}, - "listen_address": {"type": "string"} - } - }, + "properties": { + "keys": {"type": "object"}, + "daemon": {"type": "boolean"}, + "port": {"type": "integer"}, + "listen_address": {"type": "string"} + } + }, - "state_config": { - "id": "#/definitions/state_config", - "type": "object", - "additionalProperties": false, + "state_config": { + "id": "#/definitions/state_config", + "type": "object", + "additionalProperties": false, - "properties": { - "directory": {"type": "string"}, - "fstype": {"type": "string"}, - "dev": {"type": "string"}, - "wait": {"type": "boolean"}, - "required": {"type": "boolean"}, - "autoformat": {"$ref": "#/definitions/list_of_strings"}, - "mdadm_scan": {"type": "boolean"}, - "rngd": {"type": "boolean"}, - "script": {"type": "string"}, - "oem_fstype": {"type": "string"}, - "oem_dev": {"type": "string"} - } - }, + "properties": { + "directory": {"type": "string"}, + "fstype": {"type": "string"}, + "dev": {"type": "string"}, + "wait": {"type": "boolean"}, + "required": {"type": "boolean"}, + "autoformat": {"$ref": "#/definitions/list_of_strings"}, + "mdadm_scan": {"type": "boolean"}, + "rngd": {"type": "boolean"}, + "script": {"type": "string"}, + "oem_fstype": {"type": "string"}, + "oem_dev": {"type": "string"}, + "boot_fstype": {"type": "string"}, + "boot_dev": {"type": "string"} + } + }, - "cloud_init_config": { - "id": "#/definitions/cloud_init_config", - "type": "object", - "additionalProperties": false, + "cloud_init_config": { + "id": "#/definitions/cloud_init_config", + "type": "object", + "additionalProperties": false, - "properties": { - "datasources": {"$ref": "#/definitions/list_of_strings"} - } - }, + "properties": { + "datasources": {"$ref": "#/definitions/list_of_strings"} + } + }, - "defaults_config": { - "id": "#/definitions/defaults_config", - "type": "object", - "additionalProperties": false, + "defaults_config": { + "id": "#/definitions/defaults_config", + "type": "object", + "additionalProperties": false, - "properties": { - "hostname": {"type": "string"}, - "docker": {"type": "object"}, - "network": {"$ref": "#/definitions/network_config"} - } - }, + "properties": { + "hostname": {"type": "string"}, + "docker": {"type": "object"}, + "network": {"$ref": "#/definitions/network_config"} + } + }, - "list_of_strings": { - "type": "array", - "items": {"type": "string"}, - "uniqueItems": true - } - } + "list_of_strings": { + "type": "array", + "items": {"type": "string"}, + "uniqueItems": true + } + } } ` diff --git a/config/types.go b/config/types.go index 3f45be15..70bc2fca 100644 --- a/config/types.go +++ b/config/types.go @@ -12,7 +12,9 @@ import ( ) const ( - OEM = "/usr/share/ros/oem" + OemDir = "/usr/share/ros/oem" + BootDir = "/boot" + StateDir = "/state" RosBin = "/usr/bin/ros" SysInitBin = "/usr/bin/ros-sysinit" SystemDockerHost = "unix:///var/run/system-docker.sock" @@ -47,11 +49,10 @@ const ( EtcResolvConfFile = "/etc/resolv.conf" MultiDockerConfFile = "/var/lib/rancher/conf.d/m-user-docker.yml" MultiDockerDataDir = "/var/lib/m-user-docker" - State = "/state" ) var ( - OemConfigFile = OEM + "/oem-config.yml" + OemConfigFile = OemDir + "/oem-config.yml" Version string BuildDate string Arch string @@ -205,6 +206,8 @@ type StateConfig struct { Script string `yaml:"script,omitempty"` OemFsType string `yaml:"oem_fstype,omitempty"` OemDev string `yaml:"oem_dev,omitempty"` + BootFsType string `yaml:"boot_fstype,omitempty"` + BootDev string `yaml:"boot_dev,omitempty"` } type CloudInit struct { diff --git a/os-config.tpl.yml b/os-config.tpl.yml index 15eee741..458b794e 100644 --- a/os-config.tpl.yml +++ b/os-config.tpl.yml @@ -82,6 +82,8 @@ rancher: fstype: auto oem_fstype: auto oem_dev: LABEL=RANCHER_OEM + boot_fstype: auto + boot_dev: LABEL=RANCHER_BOOT rngd: true sysctl: fs.file-max: 1000000000 diff --git a/pkg/init/cloudinit/cloudinit.go b/pkg/init/cloudinit/cloudinit.go index 77bbf329..f9b91df7 100644 --- a/pkg/init/cloudinit/cloudinit.go +++ b/pkg/init/cloudinit/cloudinit.go @@ -10,7 +10,7 @@ import ( ) func CloudInit(cfg *config.CloudConfig) (*config.CloudConfig, error) { - cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(config.State).Rancher.CloudInit.Datasources + cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(config.StateDir).Rancher.CloudInit.Datasources hypervisor := util.GetHypervisor() if hypervisor == "" { log.Infof("ros init: No Detected Hypervisor") diff --git a/pkg/init/configfiles/configfiles.go b/pkg/init/configfiles/configfiles.go index 113b3303..429573f1 100644 --- a/pkg/init/configfiles/configfiles.go +++ b/pkg/init/configfiles/configfiles.go @@ -86,7 +86,7 @@ func WriteConfigFiles(cfg *config.CloudConfig) (*config.CloudConfig, error) { log.Error(err) } log.FsReady() - log.Debugf("WARNING: switchroot and mount OEM2 phases not written to log file") + log.Debugf("WARNING: switchroot and mount OEM2 and BOOT phases not written to log file") return cfg, nil } diff --git a/pkg/init/fsmount/fsmount.go b/pkg/init/fsmount/fsmount.go index 54e53d51..3c2480be 100644 --- a/pkg/init/fsmount/fsmount.go +++ b/pkg/init/fsmount/fsmount.go @@ -19,15 +19,27 @@ var ( ShouldSwitchRoot bool ) -func OEM(cfg *config.CloudConfig) (*config.CloudConfig, error) { - if cfg == nil { - cfg = config.LoadConfig() - } - if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil { +func MountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) { + if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OemDir); err != nil { log.Debugf("Not mounting OEM: %v", err) } else { log.Infof("Mounted OEM: %s", cfg.Rancher.State.OemDev) } + + return cfg, nil +} + +func MountBoot(cfg *config.CloudConfig) (*config.CloudConfig, error) { + if IsInitrd() { + return cfg, nil + } + + if err := mountConfigured("boot", cfg.Rancher.State.BootDev, cfg.Rancher.State.BootFsType, config.BootDir); err != nil { + log.Debugf("Not mounting BOOT: %v", err) + } else { + log.Infof("Mounted BOOT: %s", cfg.Rancher.State.BootDev) + } + return cfg, nil } @@ -56,7 +68,7 @@ func mountConfigured(display, dev, fsType, target string) error { } func mountState(cfg *config.CloudConfig) error { - return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, config.State) + return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, config.StateDir) } func tryMountState(cfg *config.CloudConfig) error { @@ -74,7 +86,7 @@ func tryMountState(cfg *config.CloudConfig) error { return mountState(cfg) } -func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, bool, error) { +func tryMountStateAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, bool, error) { if !IsInitrd() || cfg.Rancher.State.Dev == "" { return cfg, false, nil } @@ -94,9 +106,9 @@ func IsInitrd() bool { return int64(stat.Type) == tmpfsMagic || int64(stat.Type) == ramfsMagic } -func MountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error) { +func MountStateAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error) { var err error - cfg, ShouldSwitchRoot, err = tryMountAndBootstrap(cfg) + cfg, ShouldSwitchRoot, err = tryMountStateAndBootstrap(cfg) if err != nil { return nil, err diff --git a/pkg/init/switchroot/root.go b/pkg/init/switchroot/root.go index 061c0c6d..a1426b7d 100644 --- a/pkg/init/switchroot/root.go +++ b/pkg/init/switchroot/root.go @@ -19,8 +19,8 @@ func SwitchRoot(cfg *config.CloudConfig) (*config.CloudConfig, error) { if !fsmount.ShouldSwitchRoot { return cfg, nil } - log.Debugf("Switching to new root at %s %s", config.State, cfg.Rancher.State.Directory) - if err := switchRoot(config.State, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil { + log.Debugf("Switching to new root at %s %s", config.StateDir, cfg.Rancher.State.Directory) + if err := switchRoot(config.StateDir, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil { return cfg, err } return cfg, nil @@ -112,7 +112,7 @@ func copyMoveRoot(rootfs string, rmUsr bool) error { } func switchRoot(rootfs, subdir string, rmUsr bool) error { - if err := syscall.Unmount(config.OEM, 0); err != nil { + if err := syscall.Unmount(config.OemDir, 0); err != nil { log.Debugf("Not umounting OEM: %v", err) } diff --git a/pkg/sysinit/sysinit.go b/pkg/sysinit/sysinit.go index 2561facf..35f41e5c 100644 --- a/pkg/sysinit/sysinit.go +++ b/pkg/sysinit/sysinit.go @@ -22,7 +22,7 @@ const ( ) func hasImage(name string) bool { - stamp := path.Join(config.State, name) + stamp := path.Join(config.StateDir, name) if _, err := os.Stat(stamp); os.IsNotExist(err) { return false }