From 1731fc5642b2f38b609e9b3026901c3e82cf3207 Mon Sep 17 00:00:00 2001 From: Josh Curl Date: Mon, 26 Sep 2016 17:27:53 -0700 Subject: [PATCH] Preserve custom kernel arguments when upgrading --- cmd/control/install.go | 12 +++++++++--- cmd/control/os.go | 10 +++++----- scripts/installer/lay-down-os | 33 +++++++++++++++++++-------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/cmd/control/install.go b/cmd/control/install.go index e937a572..8efc2b49 100644 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "strings" log "github.com/Sirupsen/logrus" @@ -45,6 +46,10 @@ var installCommand = cli.Command{ Name: "no-reboot", 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 } + append := strings.TrimSpace(c.String("append")) force := c.Bool("force") 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") } 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) 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, - "-d", device, "-t", installType, "-c", cloudConfig) + "-d", device, "-t", installType, "-c", cloudConfig, "-a", append) cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.Run(); err != nil { return err diff --git a/cmd/control/os.go b/cmd/control/os.go index 84d91ddc..992e5d9b 100644 --- a/cmd/control/os.go +++ b/cmd/control/os.go @@ -58,7 +58,7 @@ func osSubcommands() []cli.Command { }, cli.StringFlag{ Name: "append", - Usage: "kernel args to append by kexec", + Usage: "append additional kernel parameters", }, cli.BoolFlag{ Name: "upgrade-console", @@ -187,11 +187,11 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra if kexec { command = append(command, "-k") + } - kernelArgs = strings.TrimSpace(kernelArgs) - if kernelArgs != "" { - command = append(command, "-a", kernelArgs) - } + kernelArgs = strings.TrimSpace(kernelArgs) + if kernelArgs != "" { + command = append(command, "-a", kernelArgs) } if upgradeConsole { diff --git a/scripts/installer/lay-down-os b/scripts/installer/lay-down-os index a6ce4332..72edbe0e 100755 --- a/scripts/installer/lay-down-os +++ b/scripts/installer/lay-down-os @@ -30,6 +30,7 @@ BASE_DIR="/mnt/new_img" # 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. PARTITION=${PARTITION:=${DEVICE}1} +KERNEL_ARGS="rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait console=${CONSOLE}" device_defined() { @@ -45,7 +46,7 @@ format_device() mkfs.ext4 -F -i 4096 -L RANCHER_STATE ${PARTITION} } -mount_device() +mount_device() { local label=RANCHER_STATE local raw="${1:-false}" @@ -55,7 +56,7 @@ mount_device() if [ "$(lsblk -o label|grep RANCHER_BOOT | wc -l)" -gt "0" ]; then label=RANCHER_BOOT fi - + local mount_opts="-L ${label}" if [ "${raw}" == "true" ]; then device_defined ${DEVICE} @@ -85,7 +86,7 @@ set timeout="1" menuentry "RancherOS-current" { 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 } @@ -96,7 +97,7 @@ if [ ! -z ${ROLLBACK_VERSION} ]; then cat >>${grub_cfg} <> ${grub_file}< ${BASE_DIR}/boot/append + +grub2_config "${APPEND}" +pvgrub_config "${APPEND}" install_rancher seusers=${BASE_DIR}/etc/selinux/ros/seusers @@ -204,8 +212,5 @@ if [ -f "${failsafe_context}" ]; then fi if [ "$KEXEC" = "y" ]; then - if [ "$APPEND" = "" ]; then - APPEND=$(cat /proc/cmdline) - fi - kexec -l ${DIST}/vmlinuz --initrd=${DIST}/initrd --append="$APPEND" -f + kexec -l ${DIST}/vmlinuz --initrd=${DIST}/initrd --append="${KERNEL_ARGS} ${APPEND}" -f fi