mirror of
https://github.com/rancher/os.git
synced 2025-07-17 08:31:02 +00:00
Merge pull request #1254 from joshwget/preserve-kernel-args
Preserve custom kernel arguments when upgrading
This commit is contained in:
commit
7ac9d02614
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
||||||
@ -45,6 +46,10 @@ var installCommand = cli.Command{
|
|||||||
Name: "no-reboot",
|
Name: "no-reboot",
|
||||||
Usage: "do not reboot after install",
|
Usage: "do not reboot after install",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "append, a",
|
||||||
|
Usage: "append additional kernel parameters",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,17 +85,18 @@ func installAction(c *cli.Context) error {
|
|||||||
cloudConfig = uc
|
cloudConfig = uc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append := strings.TrimSpace(c.String("append"))
|
||||||
force := c.Bool("force")
|
force := c.Bool("force")
|
||||||
reboot := !c.Bool("no-reboot")
|
reboot := !c.Bool("no-reboot")
|
||||||
|
|
||||||
if err := runInstall(image, installType, cloudConfig, device, force, reboot); err != nil {
|
if err := runInstall(image, installType, cloudConfig, device, append, force, reboot); err != nil {
|
||||||
log.WithFields(log.Fields{"err": err}).Fatal("Failed to run install")
|
log.WithFields(log.Fields{"err": err}).Fatal("Failed to run install")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInstall(image, installType, cloudConfig, device string, force, reboot bool) error {
|
func runInstall(image, installType, cloudConfig, device, append string, force, reboot bool) error {
|
||||||
in := bufio.NewReader(os.Stdin)
|
in := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
fmt.Printf("Installing from %s\n", image)
|
fmt.Printf("Installing from %s\n", image)
|
||||||
@ -110,7 +116,7 @@ func runInstall(image, installType, cloudConfig, device string, force, reboot bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=user-volumes", image,
|
cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=user-volumes", image,
|
||||||
"-d", device, "-t", installType, "-c", cloudConfig)
|
"-d", device, "-t", installType, "-c", cloudConfig, "-a", append)
|
||||||
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -58,7 +58,7 @@ func osSubcommands() []cli.Command {
|
|||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "append",
|
Name: "append",
|
||||||
Usage: "kernel args to append by kexec",
|
Usage: "append additional kernel parameters",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "upgrade-console",
|
Name: "upgrade-console",
|
||||||
@ -187,12 +187,12 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra
|
|||||||
|
|
||||||
if kexec {
|
if kexec {
|
||||||
command = append(command, "-k")
|
command = append(command, "-k")
|
||||||
|
}
|
||||||
|
|
||||||
kernelArgs = strings.TrimSpace(kernelArgs)
|
kernelArgs = strings.TrimSpace(kernelArgs)
|
||||||
if kernelArgs != "" {
|
if kernelArgs != "" {
|
||||||
command = append(command, "-a", kernelArgs)
|
command = append(command, "-a", kernelArgs)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if upgradeConsole {
|
if upgradeConsole {
|
||||||
if err := config.Set("rancher.force_console_rebuild", true); err != nil {
|
if err := config.Set("rancher.force_console_rebuild", true); err != nil {
|
||||||
|
@ -30,6 +30,7 @@ BASE_DIR="/mnt/new_img"
|
|||||||
# TODO: Change this to a number so that users can specify.
|
# TODO: Change this to a number so that users can specify.
|
||||||
# Will need to make it so that our builds and packer APIs remain consistent.
|
# Will need to make it so that our builds and packer APIs remain consistent.
|
||||||
PARTITION=${PARTITION:=${DEVICE}1}
|
PARTITION=${PARTITION:=${DEVICE}1}
|
||||||
|
KERNEL_ARGS="rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=${CONSOLE}"
|
||||||
|
|
||||||
device_defined()
|
device_defined()
|
||||||
{
|
{
|
||||||
@ -85,7 +86,7 @@ set timeout="1"
|
|||||||
|
|
||||||
menuentry "RancherOS-current" {
|
menuentry "RancherOS-current" {
|
||||||
set root=(hd0,msdos1)
|
set root=(hd0,msdos1)
|
||||||
linux /boot/vmlinuz-${VERSION}-rancheros ${append_line} rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=${CONSOLE}
|
linux /boot/vmlinuz-${VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
|
||||||
initrd /boot/initrd-${VERSION}-rancheros
|
initrd /boot/initrd-${VERSION}-rancheros
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ if [ ! -z ${ROLLBACK_VERSION} ]; then
|
|||||||
cat >>${grub_cfg} <<EOF
|
cat >>${grub_cfg} <<EOF
|
||||||
menuentry "RancherOS-rollback" {
|
menuentry "RancherOS-rollback" {
|
||||||
set root=(hd0,msdos1)
|
set root=(hd0,msdos1)
|
||||||
linux /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${append_line} rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=${CONSOLE}
|
linux /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
|
||||||
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
|
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
@ -123,7 +124,7 @@ hiddenmenu
|
|||||||
|
|
||||||
title RancherOS ${VERSION}-(current)
|
title RancherOS ${VERSION}-(current)
|
||||||
root (hd0)
|
root (hd0)
|
||||||
kernel /boot/vmlinuz-${VERSION}-rancheros ${append_line} rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=${CONSOLE}
|
kernel /boot/vmlinuz-${VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
|
||||||
initrd /boot/initrd-${VERSION}-rancheros
|
initrd /boot/initrd-${VERSION}-rancheros
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
@ -133,7 +134,7 @@ if [ ! -z ${ROLLBACK_VERSION} ]; then
|
|||||||
cat >> ${grub_file}<<EOF
|
cat >> ${grub_file}<<EOF
|
||||||
title RancherOS ${ROLLBACK_VERSION}-(rollback)
|
title RancherOS ${ROLLBACK_VERSION}-(rollback)
|
||||||
root (hd0)
|
root (hd0)
|
||||||
kernel /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${append_line} rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=${CONSOLE}
|
kernel /boot/vmlinuz-${ROLLBACK_VERSION}-rancheros ${KERNEL_ARGS} ${append_line}
|
||||||
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
|
initrd /boot/initrd-${ROLLBACK_VERSION}-rancheros
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
@ -146,7 +147,6 @@ format_and_mount()
|
|||||||
create_boot_dirs
|
create_boot_dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
KERNEL_ARGS=${KERNEL_ARGS:-""}
|
|
||||||
if [ -n ${ENV} ]; then
|
if [ -n ${ENV} ]; then
|
||||||
case ${ENV} in
|
case ${ENV} in
|
||||||
"generic")
|
"generic")
|
||||||
@ -190,8 +190,16 @@ if [ -n ${ENV} ]; then
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
grub2_config "${KERNEL_ARGS}"
|
if [ -e ${BASE_DIR}/boot/append ]; then
|
||||||
pvgrub_config "${KERNEL_ARGS}"
|
PRESERVED_APPEND=$(cat ${BASE_DIR}/boot/append)
|
||||||
|
fi
|
||||||
|
if [ "${APPEND}" = "" ]; then
|
||||||
|
APPEND="${PRESERVED_APPEND}"
|
||||||
|
fi
|
||||||
|
echo "${APPEND}" > ${BASE_DIR}/boot/append
|
||||||
|
|
||||||
|
grub2_config "${APPEND}"
|
||||||
|
pvgrub_config "${APPEND}"
|
||||||
install_rancher
|
install_rancher
|
||||||
|
|
||||||
seusers=${BASE_DIR}/etc/selinux/ros/seusers
|
seusers=${BASE_DIR}/etc/selinux/ros/seusers
|
||||||
@ -204,8 +212,5 @@ if [ -f "${failsafe_context}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$KEXEC" = "y" ]; then
|
if [ "$KEXEC" = "y" ]; then
|
||||||
if [ "$APPEND" = "" ]; then
|
kexec -l ${DIST}/vmlinuz --initrd=${DIST}/initrd --append="${KERNEL_ARGS} ${APPEND}" -f
|
||||||
APPEND=$(cat /proc/cmdline)
|
|
||||||
fi
|
|
||||||
kexec -l ${DIST}/vmlinuz --initrd=${DIST}/initrd --append="$APPEND" -f
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user