1
0
mirror of https://github.com/rancher/os.git synced 2025-07-17 00:21:03 +00:00

Merge pull request #1254 from joshwget/preserve-kernel-args

Preserve custom kernel arguments when upgrading
This commit is contained in:
Darren Shepherd 2016-09-26 21:22:41 -07:00 committed by GitHub
commit 7ac9d02614
3 changed files with 33 additions and 22 deletions

View File

@ -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

View File

@ -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,11 +187,11 @@ 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 {

View File

@ -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()
{ {
@ -45,7 +46,7 @@ format_device()
mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${PARTITION} mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${PARTITION}
} }
mount_device() mount_device()
{ {
local label=RANCHER_STATE local label=RANCHER_STATE
local raw="${1:-false}" local raw="${1:-false}"
@ -55,7 +56,7 @@ mount_device()
if [ "$(lsblk -o label|grep RANCHER_BOOT | wc -l)" -gt "0" ]; then if [ "$(lsblk -o label|grep RANCHER_BOOT | wc -l)" -gt "0" ]; then
label=RANCHER_BOOT label=RANCHER_BOOT
fi fi
local mount_opts="-L ${label}" local mount_opts="-L ${label}"
if [ "${raw}" == "true" ]; then if [ "${raw}" == "true" ]; then
device_defined ${DEVICE} device_defined ${DEVICE}
@ -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")
@ -180,7 +180,7 @@ if [ -n ${ENV} ]; then
KERNEL_ARGS="${KERNEL_ARGS} rancher.cloud_init.datasources=[ec2,gce]" KERNEL_ARGS="${KERNEL_ARGS} rancher.cloud_init.datasources=[ec2,gce]"
;; ;;
"rancher-upgrade") "rancher-upgrade")
mount_device mount_device
create_boot_dirs create_boot_dirs
;; ;;
*) *)
@ -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