diff --git a/.dockerignore b/.dockerignore index 6cbff056..99e24dc8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,6 +12,6 @@ tests/integration/.tox */*/*/*.pyc */*/*/__pycache__ .trash-cache -.dapper +#.dapper vendor/*/*/*/.git tmp diff --git a/cmd/control/install.go b/cmd/control/install.go index 15f0eac9..2d8442a3 100755 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -78,7 +78,7 @@ var installCommand = cli.Command{ Hidden: true, }, cli.BoolFlag{ - Name: "kexec", + Name: "kexec, k", Usage: "reboot using kexec", }, cli.BoolFlag{ @@ -395,7 +395,7 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin CONSOLE := "tty0" baseName := "/mnt/new_img" bootDir := "boot/" - kernelArgs := "rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait" // console="+CONSOLE + kernelArgs := "rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait printk.devkmsg=on" // console="+CONSOLE // unmount on trap defer util.Unmount(baseName) @@ -517,7 +517,7 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin install.PvGrubConfig(menu) } log.Debugf("installRancher") - err := installRancher(baseName, bootDir, VERSION, DIST, kernelArgs+" "+kappend) + currentCfg, err := installRancher(baseName, bootDir, VERSION, DIST, kernelArgs+" "+kappend) if err != nil { log.Errorf("%s", err) return err @@ -526,12 +526,19 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin // Used by upgrade if kexec { + vmlinuzFile, initrdFile, err := readSyslinuxCfg(currentCfg) + if err != nil { + log.Errorf("%s", err) + return err + } // kexec -l ${DIST}/vmlinuz --initrd=${DIST}/initrd --append="${kernelArgs} ${APPEND}" -f - cmd := exec.Command("kexec", "-l "+DIST+"/vmlinuz", - "--initrd="+DIST+"/initrd", - "--append='"+kernelArgs+" "+kappend+"'", + cmd := exec.Command( + "kexec", + "-l", DIST+"/"+vmlinuzFile, + "--initrd", DIST+"/"+initrdFile, + "--append", "'"+kernelArgs+" "+kappend+"'", "-f") - log.Debugf("Run(%v)", cmd) + log.Debugf("Run(%#v)", cmd) cmd.Stderr = os.Stderr if _, err := cmd.Output(); err != nil { log.Errorf("Failed to kexec: %s", err) @@ -543,6 +550,31 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin return nil } +func readSyslinuxCfg(currentCfg string) (string, string, error) { + vmlinuzFile := "" + initrdFile := "" + // Need to parse currentCfg for the lines: + // KERNEL ../vmlinuz-4.9.18-rancher^M + // INITRD ../initrd-41e02e6-dirty^M + buf, err := ioutil.ReadFile(currentCfg) + if err != nil { + return vmlinuzFile, initrdFile, err + } + s := bufio.NewScanner(bytes.NewReader(buf)) + for s.Scan() { + line := strings.TrimSpace(s.Text()) + if strings.HasPrefix(line, "KERNEL") { + vmlinuzFile = strings.TrimSpace(strings.TrimPrefix(line, "KERNEL")) + vmlinuzFile = filepath.Base(vmlinuzFile) + } + if strings.HasPrefix(line, "INITRD") { + initrdFile = strings.TrimSpace(strings.TrimPrefix(line, "INITRD")) + initrdFile = filepath.Base(initrdFile) + } + } + return vmlinuzFile, initrdFile, err +} + // files is an array of 'sourcefile:destination' - but i've not seen any examples of it being used. func seedData(baseName, cloudData string, files []string) error { log.Debugf("seedData") @@ -982,7 +1014,7 @@ func installSyslinux(device, baseName, bootDir, diskType string) error { return nil } -func installRancher(baseName, bootDir, VERSION, DIST, kappend string) error { +func installRancher(baseName, bootDir, 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, @@ -991,7 +1023,7 @@ func installRancher(baseName, bootDir, VERSION, DIST, kappend string) error { previousCfg := filepath.Join(baseName, bootDir, "linux-previous.cfg") if _, err := os.Stat(previousCfg); !os.IsNotExist(err) { if err := os.Remove(previousCfg); err != nil { - return err + return currentCfg, err } } os.Rename(currentCfg, previousCfg) @@ -1021,8 +1053,8 @@ func installRancher(baseName, bootDir, VERSION, DIST, kappend string) error { err := ioutil.WriteFile(globalFile, []byte("APPEND "+kappend), 0644) if err != nil { log.Errorf("write (%s) %s", "global.cfg", err) - return err + return currentCfg, err } } - return nil + return currentCfg, nil } diff --git a/scripts/installer/BaseDockerfile.amd64 b/scripts/installer/BaseDockerfile.amd64 index 0f07b544..be892c18 100644 --- a/scripts/installer/BaseDockerfile.amd64 +++ b/scripts/installer/BaseDockerfile.amd64 @@ -17,6 +17,7 @@ COPY ./build/ros /bin/ #OR softlink in the host one - this image should only be used when installing from ISO.. # (except its useful for testing) # && ln -s /host/usr/bin/ros /bin/ +COPY kexec/dist/sbin/kexec /sbin/ RUN ln -s /bootiso/boot/ /dist diff --git a/scripts/installer/kexec/Dockerfile.dapper b/scripts/installer/kexec/Dockerfile.dapper new file mode 100644 index 00000000..a60d39f7 --- /dev/null +++ b/scripts/installer/kexec/Dockerfile.dapper @@ -0,0 +1,42 @@ +FROM ubuntu:16.04 +# FROM arm64=aarch64/ubuntu:16.04 arm=armhf/ubuntu:16.04 + + +RUN apt-get update \ + && apt-get install -yq build-essential autoconf libtool gawk alien fakeroot \ + zlib1g-dev uuid-dev libattr1-dev libblkid-dev libselinux-dev libudev-dev libdevmapper-dev \ + module-init-tools \ + parted lsscsi ksh curl git + +WORKDIR /source + +#ADD https://github.com/rancher/os-kernel/releases/download/v4.9.15-rancher/build-linux-4.9.15-rancher-x86.tar.gz . +#RUN mkdir -p /usr/src/v4.9.15-rancher \ +# && cd /usr/src/v4.9.15-rancher \ +# && tar zxvf /source/build-linux-4.9.15-rancher-x86.tar.gz + +# https://www.kernel.org/pub/linux/utils/kernel/kexec/ +ENV VERSION 2.0.14 +ADD https://www.kernel.org/pub/linux/utils/kernel/kexec/kexec-tools-$VERSION.tar.gz . + +RUN zcat kexec-tools-$VERSION.tar.gz | tar xvf - \ + && cd kexec-tools-$VERSION \ + && sed 's/loff_t/off_t/g' -i vmcore-dmesg/vmcore-dmesg.c \ + && LDFLAGS=-static ./configure \ + && make \ + && make install +RUN mkdir -p /source/dist \ + && cp -r /usr/local/* /source/dist + +########## Dapper Configuration ##################### + +ENV DAPPER_ENV VERSION DEV_BUILD RUNTEST +#ENV DAPPER_DOCKER_SOCKET true +ENV DAPPER_SOURCE /source +ENV DAPPER_OUTPUT ./dist +#ENV DAPPER_RUN_ARGS --privileged +#ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache +#ENV SHELL /bin/bash + +CMD true + diff --git a/scripts/package-installer b/scripts/package-installer index f75c3ef2..9c43b3a0 100755 --- a/scripts/package-installer +++ b/scripts/package-installer @@ -18,6 +18,18 @@ if \ exit 0 fi +# build kexec +pushd . +cd scripts/installer/kexec +echo Downloading dapper +curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m|sed 's/v7l//'` > .dapper.tmp +chmod +x .dapper.tmp +./.dapper.tmp -v +mv .dapper.tmp .dapper +./.dapper +popd + + # TODO maybe extract the creation of the syslinux cfg files DIST=$(pwd)/dist echo "mkdir -p ${DIST}/boot/isolinux/"