1
0
mirror of https://github.com/rancher/os.git synced 2025-06-26 15:01:34 +00:00

Merge pull request #1957 from SvenDowideit/add-syslinux-menu

Add Syslinux menu with debug and autologin options
This commit is contained in:
Sven Dowideit 2017-07-10 11:29:33 +10:00 committed by GitHub
commit 671a78ac08
11 changed files with 150 additions and 33 deletions

View File

@ -5,6 +5,7 @@ import (
"io"
"io/ioutil"
"os"
"os/exec"
"sort"
"strings"
"text/template"
@ -76,6 +77,11 @@ func configSubcommands() []cli.Command {
},
},
},
{
Name: "syslinux",
Usage: "edit Syslinux boot global.cfg",
Action: editSyslinux,
},
{
Name: "validate",
Usage: "validate configuration from stdin",
@ -146,6 +152,21 @@ func env2map(env []string) map[string]string {
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 {
if c.NArg() < 2 {
return nil

View File

@ -3,6 +3,7 @@ package control
import (
"bufio"
"bytes"
"crypto/md5"
"fmt"
"io"
"io/ioutil"
@ -923,12 +924,36 @@ func installSyslinux(device, baseName, diskType string) error {
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) {
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")
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")
if _, err := os.Stat(previousCfg); !os.IsNotExist(err) {
if err := os.Remove(previousCfg); err != nil {
@ -938,6 +963,7 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
os.Rename(currentCfg, previousCfg)
// 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
files, _ := ioutil.ReadDir(DIST)
@ -945,15 +971,26 @@ func installRancher(baseName, VERSION, DIST, kappend string) (string, error) {
if file.IsDir() {
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)
//return err
}
}
// 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)
//return err
} else {
log.Debugf("installRancher copy global syslinux.cfgS OK")
}
// The global.cfg INCLUDE - useful for over-riding the APPEND line

View File

@ -264,16 +264,22 @@ func defaultFolders(folders ...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) {
log.Debugf("Not copying %s, does not exists", src)
return nil
}
dst := path.Join(folder, name)
if !overwrite {
if _, err := os.Lstat(dst); err == nil {
log.Debugf("Not copying %s => %s already exists", src, dst)
return nil
}
}
if err := createDirs(folder); err != nil {
return err

View File

@ -10,14 +10,13 @@ There are two ways to edit the kernel parameters, in-place (editing the file and
### 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.
```bash
$ sudo system-docker run --rm -it -v /:/host alpine vi /host/boot/global.cfg
```
#### Graphical boot screen
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

View File

@ -1,9 +1,35 @@
# 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
PROMPT 1
PROMPT 0
# doesn't appear to work here?
INCLUDE ../global.cfg
# 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
LABEL rancheros-current
MENU LABEL Current RancherOS Version
MENU DISABLE
INCLUDE ../linux-current.cfg
# http://www.syslinux.org/wiki/index.php?title=Comboot/menu.c32
LABEL Boot next BIOS option
MENU LABEL Boot next BIOS option
LOCALBOOT -1
MENU TITLE RancherOS
MENU BACKGROUND ../rancher.png
MENU WIDTH 80
MENU MARGIN 10
MENU ROWS 12
MENU TABMSGROW 18
MENU CMDLINEROW 18
MENU ENDROW 24
MENU TIMEOUTROW 20

View File

@ -1,9 +1,31 @@
# TODO: should add ros-version to label and initrd
DEFAULT rancheros-${LABEL}
LABEL rancheros-${LABEL}
SAY rancheros-${LABEL}: RancherOS ${VERSION} ${KERNEL_VERSION}
MENU LABEL RancherOS ${VERSION} ${KERNEL_VERSION}
KERNEL ../vmlinuz-${KERNEL_VERSION}
INITRD ../initrd-${VERSION}
# see global.cfg for kernel boot parameters
LABEL rancheros-${LABEL}-autologin
SAY rancheros-${LABEL}-autologin: autologin RancherOS ${VERSION} ${KERNEL_VERSION}
MENU LABEL rancher.autologin
MENU INDENT 2
COM32 cmd.c32
APPEND rancheros-${LABEL} rancher.autologin=tty1 rancher.autologin=ttyS0
LABEL rancheros-${LABEL}-debug
SAY rancheros-${LABEL}-debug: debug RancherOS ${VERSION} ${KERNEL_VERSION}
MENU LABEL rancher.debug=true
MENU INDENT 2
COM32 cmd.c32
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

View File

@ -38,6 +38,7 @@ cat scripts/isolinux.cfg | envsubst > ${DIST}/boot/isolinux/isolinux.cfg
cat scripts/isolinux_label.cfg | LABEL=${VERSION} envsubst > ${DIST}/boot/linux-current.cfg
#cat scripts/isolinux_label.cfg | LABEL=debug APPEND="rancher.debug=true" envsubst > ${DIST}/boot/linux-previous.cfg
cat scripts/global.cfg | LABEL=${VERSION} envsubst > ${DIST}/boot/global.cfg
cp scripts/rancher.png ${DIST}/boot/
mkdir -p ./scripts/installer/build/boot

View File

@ -36,6 +36,7 @@ cp -r ${DIST}/boot/* ${CD}/boot/
cp /usr/lib/ISOLINUX/isolinux.bin ${CD}/boot/isolinux/
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 ${CD}/boot/isolinux/
cp /usr/lib/syslinux/modules/bios/*.c32 ${CD}/boot/isolinux/
# add the installer image to the iso for non-network / dev/test
cp ${ARTIFACTS}/installer.tar ${CD}/rancheros/
cp ${ARTIFACTS}/Dockerfile.amd64 ${CD}/rancheros/

BIN
scripts/rancher.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -26,4 +26,4 @@ docker run --rm -it \
-v /usr/share/ca-certificates:/usr/share/ca-certificates \
-w /var/lib/rancher \
--entrypoint sh \
rancher/os-base:v0.8.1
rancher/os-base:v1.0.3

View File

@ -123,6 +123,9 @@ while [ "$#" -gt 0 ]; do
--netconsole)
NETCONSOLE=1
;;
--gui)
GUICONSOLE=1
;;
--installed)
./scripts/create-installed
INSTALLED=1
@ -265,9 +268,9 @@ if [ "$QIND" != "1" ]; then
HOME=${HOME:-/}
fi
if [ "$GUICONSOLE" == "" ]; then
# default serial console
DISPLAY_OPTS="-nographic -serial mon:stdio -display none"
if [ "$CONSOLEDISPLAY" == "1" ]; then
DISPLAY_OPTS="-curses"
fi
@ -276,6 +279,7 @@ if [ "$NETCONSOLE" == "1" ]; then
DISPLAY_OPTS="${DISPLAY_OPTS} -serial tcp::4444,server"
KERNEL_ARGS="rancher.console=ttyS1 rancher.autologin=ttyS1 ${KERNEL_ARGS}"
fi
fi
if [ "$QEMU" == "1" ]; then
if [ "$INSTALLED" == "1" ]; then