mirror of
https://github.com/rancher/os.git
synced 2025-06-24 22:11:33 +00:00
add some better menu touches, make upgrade also upgrade to the menu, and add a ros config syslinux cmd for editing the global.cfg
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
parent
204facc395
commit
b733bde9cd
@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -76,6 +77,11 @@ func configSubcommands() []cli.Command {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "syslinux",
|
||||||
|
Usage: "edit Syslinux boot global.cfg",
|
||||||
|
Action: editSyslinux,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "validate",
|
Name: "validate",
|
||||||
Usage: "validate configuration from stdin",
|
Usage: "validate configuration from stdin",
|
||||||
@ -146,6 +152,21 @@ func env2map(env []string) map[string]string {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func editSyslinux(c *cli.Context) error {
|
||||||
|
cmd := exec.Command("system-docker", "run", "--rm", "-it",
|
||||||
|
"-v", "/:/host",
|
||||||
|
"-w", "/host",
|
||||||
|
"--entrypoint=vi",
|
||||||
|
"rancher/os-console:"+config.Version,
|
||||||
|
"boot/global.cfg")
|
||||||
|
cmd.Stdout, cmd.Stderr, cmd.Stdin = os.Stdout, os.Stderr, os.Stdin
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func configSet(c *cli.Context) error {
|
func configSet(c *cli.Context) error {
|
||||||
if c.NArg() < 2 {
|
if c.NArg() < 2 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -3,6 +3,7 @@ package control
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -923,12 +924,36 @@ func installSyslinux(device, baseName, diskType string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func different(existing, new string) bool {
|
||||||
|
// assume existing file exists
|
||||||
|
if _, err := os.Stat(new); os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
data, err := ioutil.ReadFile(existing)
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
newData, err := ioutil.ReadFile(new)
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
md5sum := md5.Sum(data)
|
||||||
|
newmd5sum := md5.Sum(newData)
|
||||||
|
if md5sum != newmd5sum {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
||||||
log.Debugf("installRancher")
|
log.Debugf("installRancher")
|
||||||
|
|
||||||
// detect if there already is a linux-current.cfg, if so, move it to linux-previous.cfg,
|
// 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, install.BootDir, "linux-current.cfg")
|
||||||
if _, err := os.Stat(currentCfg); !os.IsNotExist(err) {
|
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, install.BootDir, "linux-previous.cfg")
|
||||||
if _, err := os.Stat(previousCfg); !os.IsNotExist(err) {
|
if _, err := os.Stat(previousCfg); !os.IsNotExist(err) {
|
||||||
if err := os.Remove(previousCfg); err != nil {
|
if err := os.Remove(previousCfg); err != nil {
|
||||||
@ -938,6 +963,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
|||||||
os.Rename(currentCfg, previousCfg)
|
os.Rename(currentCfg, previousCfg)
|
||||||
// TODO: now that we're parsing syslinux.cfg files, maybe we can delete old kernels and initrds
|
// TODO: now that we're parsing syslinux.cfg files, maybe we can delete old kernels and initrds
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The image/ISO have all the files in it - the syslinux cfg's and the kernel&initrd, so we can copy them all from there
|
// The image/ISO have all the files in it - the syslinux cfg's and the kernel&initrd, so we can copy them all from there
|
||||||
files, _ := ioutil.ReadDir(DIST)
|
files, _ := ioutil.ReadDir(DIST)
|
||||||
@ -945,15 +971,26 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
|
|||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := dfs.CopyFile(filepath.Join(DIST, file.Name()), filepath.Join(baseName, install.BootDir), file.Name()); err != nil {
|
// TODO: should overwrite anything other than the global.cfg
|
||||||
|
overwrite := true
|
||||||
|
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 {
|
||||||
log.Errorf("copy %s: %s", file.Name(), err)
|
log.Errorf("copy %s: %s", file.Name(), err)
|
||||||
//return err
|
//return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the general INCLUDE syslinuxcfg
|
// the general INCLUDE syslinuxcfg
|
||||||
if err := dfs.CopyFile(filepath.Join(DIST, "isolinux", "isolinux.cfg"), filepath.Join(baseName, install.BootDir, "syslinux"), "syslinux.cfg"); err != nil {
|
isolinuxFile := filepath.Join(DIST, "isolinux", "isolinux.cfg")
|
||||||
|
syslinuxDir := filepath.Join(baseName, install.BootDir, "syslinux")
|
||||||
|
if err := dfs.CopyFileOverwrite(isolinuxFile, syslinuxDir, "syslinux.cfg", true); err != nil {
|
||||||
log.Errorf("copy global syslinux.cfgS%s: %s", "syslinux.cfg", err)
|
log.Errorf("copy global syslinux.cfgS%s: %s", "syslinux.cfg", err)
|
||||||
//return err
|
//return err
|
||||||
|
} else {
|
||||||
|
log.Debugf("installRancher copy global syslinux.cfgS OK")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The global.cfg INCLUDE - useful for over-riding the APPEND line
|
// The global.cfg INCLUDE - useful for over-riding the APPEND line
|
||||||
|
@ -264,16 +264,22 @@ func defaultFolders(folders ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CopyFile(src, folder, name string) error {
|
func CopyFile(src, folder, name string) error {
|
||||||
|
return CopyFileOverwrite(src, folder, name, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CopyFileOverwrite(src, folder, name string, overwrite bool) error {
|
||||||
if _, err := os.Lstat(src); os.IsNotExist(err) {
|
if _, err := os.Lstat(src); os.IsNotExist(err) {
|
||||||
log.Debugf("Not copying %s, does not exists", src)
|
log.Debugf("Not copying %s, does not exists", src)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := path.Join(folder, name)
|
dst := path.Join(folder, name)
|
||||||
|
if !overwrite {
|
||||||
if _, err := os.Lstat(dst); err == nil {
|
if _, err := os.Lstat(dst); err == nil {
|
||||||
log.Debugf("Not copying %s => %s already exists", src, dst)
|
log.Debugf("Not copying %s => %s already exists", src, dst)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := createDirs(folder); err != nil {
|
if err := createDirs(folder); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -10,14 +10,13 @@ There are two ways to edit the kernel parameters, in-place (editing the file and
|
|||||||
|
|
||||||
### In-place editing
|
### In-place editing
|
||||||
|
|
||||||
For in-place editing, you will need to run a container with an editor and a mount to access the `/boot/global.cfg` file containing the kernel parameters.
|
To edit the kernel boot parameters of an already installed RancherOS system, use the new `sudo ros config syslinux` editing command (uses `vi`).
|
||||||
|
|
||||||
> To activate this setting, you will need to reboot.
|
> To activate this setting, you will need to reboot.
|
||||||
|
|
||||||
```bash
|
#### Graphical boot screen
|
||||||
$ sudo system-docker run --rm -it -v /:/host alpine vi /host/boot/global.cfg
|
|
||||||
```
|
|
||||||
|
|
||||||
|
RancherOS v1.1.0 added a syslinux boot menu, which on desktop systems can be switched to graphical mode by adding `UI vesamenu.c32` to a new line in `global.cfg` (use `sudo ros config syslinux` to edit the file).
|
||||||
|
|
||||||
### During installation
|
### During installation
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
UI vesamenu.c32
|
# Add `UI vesamenu.c32` to a new line in `global.cfg` to switch to GUI bootmenu (use `sudo ros config syslinux`)
|
||||||
|
UI menu.c32
|
||||||
TIMEOUT 20 #2s
|
TIMEOUT 20 #2s
|
||||||
PROMPT 0
|
PROMPT 0
|
||||||
|
|
||||||
@ -6,7 +7,14 @@ PROMPT 0
|
|||||||
INCLUDE ../global.cfg
|
INCLUDE ../global.cfg
|
||||||
|
|
||||||
# each INCLUDEd file has a `DEFAULT mylabel` in it, and the last one wins
|
# each INCLUDEd file has a `DEFAULT mylabel` in it, and the last one wins
|
||||||
|
LABEL rancheros-previous
|
||||||
|
MENU LABEL Previous RancherOS Version
|
||||||
|
MENU DISABLE
|
||||||
INCLUDE ../linux-previous.cfg
|
INCLUDE ../linux-previous.cfg
|
||||||
|
|
||||||
|
LABEL rancheros-current
|
||||||
|
MENU LABEL Current RancherOS Version
|
||||||
|
MENU DISABLE
|
||||||
INCLUDE ../linux-current.cfg
|
INCLUDE ../linux-current.cfg
|
||||||
|
|
||||||
# http://www.syslinux.org/wiki/index.php?title=Comboot/menu.c32
|
# http://www.syslinux.org/wiki/index.php?title=Comboot/menu.c32
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
# TODO: should add ros-version to label and initrd
|
|
||||||
DEFAULT rancheros-${LABEL}
|
DEFAULT rancheros-${LABEL}
|
||||||
LABEL rancheros-${LABEL}
|
LABEL rancheros-${LABEL}
|
||||||
SAY rancheros-${LABEL}: RancherOS ${VERSION} ${KERNEL_VERSION}
|
SAY rancheros-${LABEL}: RancherOS ${VERSION} ${KERNEL_VERSION}
|
||||||
@ -22,4 +21,11 @@ LABEL rancheros-${LABEL}-debug
|
|||||||
COM32 cmd.c32
|
COM32 cmd.c32
|
||||||
APPEND rancheros-${LABEL} rancher.debug=true
|
APPEND rancheros-${LABEL} rancher.debug=true
|
||||||
|
|
||||||
|
LABEL rancheros-${LABEL}-debug-autologin
|
||||||
|
SAY rancheros-${LABEL}-debug-autolgin: debug and autologin RancherOS ${VERSION} ${KERNEL_VERSION}
|
||||||
|
MENU LABEL rancher.debug and rancher.autologin
|
||||||
|
MENU INDENT 2
|
||||||
|
COM32 cmd.c32
|
||||||
|
APPEND rancheros-${LABEL} rancher.autologin=tty1 rancher.autologin=ttyS0 rancher.debug=true
|
||||||
|
|
||||||
MENU SEPARATOR
|
MENU SEPARATOR
|
||||||
|
@ -26,4 +26,4 @@ docker run --rm -it \
|
|||||||
-v /usr/share/ca-certificates:/usr/share/ca-certificates \
|
-v /usr/share/ca-certificates:/usr/share/ca-certificates \
|
||||||
-w /var/lib/rancher \
|
-w /var/lib/rancher \
|
||||||
--entrypoint sh \
|
--entrypoint sh \
|
||||||
rancher/os-base:v0.8.1
|
rancher/os-base:v1.0.3
|
||||||
|
Loading…
Reference in New Issue
Block a user