From fc5aae23fea8074563d2bd329ca7d4a873043477 Mon Sep 17 00:00:00 2001 From: linxin Date: Wed, 19 Jul 2023 18:02:12 +0800 Subject: [PATCH] =?UTF-8?q?TSG-16020:=20=E9=80=9A=E8=BF=87kexec=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=BF=AB=E9=80=9F=E5=86=85=E6=A0=B8=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E7=A1=AC=E4=BB=B6=E6=A3=80=E6=9F=A5=E5=8A=A0?= =?UTF-8?q?=E5=BF=AB=E5=8D=87=E7=BA=A7=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- installer/install.sh | 19 ++++++++++++- rootconf/sysroot-bin/onie-reboot-install | 36 ++++++++++++++++++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 5fdb0245..1517c944 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -369,4 +369,21 @@ umount ${distro_mnt} cd / echo "TSG-OS install successfully, need to reboot." -exit 0 +if grep -q "fastreboot=1" /proc/cmdline ; then + echo "os need fastboot" + mkdir -p /tmp/os + mount /dev/sda4 /tmp/os + + if [ -e /tmp/os/boot/vmlinuz ] && [ -e /tmp/os/boot/initrd.img ]; then + kexec -l /tmp/os/boot/vmlinuz --initrd=/tmp/os/boot/initrd.img \ + --append="$(cat /proc/cmdline | sed 's/fastboot=1 //')" + + kexec -e + else + echo "vmlinuz and initrd.img do not exist in /tmp/os/boot. Exiting." + exit 0 + fi +else + echo "Don't need fastboot" + exit 0 +fi \ No newline at end of file diff --git a/rootconf/sysroot-bin/onie-reboot-install b/rootconf/sysroot-bin/onie-reboot-install index 5c6c64bd..16463ded 100755 --- a/rootconf/sysroot-bin/onie-reboot-install +++ b/rootconf/sysroot-bin/onie-reboot-install @@ -4,10 +4,36 @@ # # SPDX-License-Identifier: GPL-2.0 -. /lib/onie/common-blkdev -echo "Rebooting into ONIE (re)install mode..." +# Check for --no-kexec argument +if [ "$1" = "--no-kexec" ] +then + . /lib/onie/common-blkdev -set_onie_next_boot -/mnt/onie-boot/onie/tools/bin/onie-boot-mode -q -o install -reboot + echo "Rebooting into ONIE (re)install mode..." + set_onie_next_boot + /mnt/onie-boot/onie/tools/bin/onie-boot-mode -q -o install + echo "Rebooting with reboot command..." + reboot +else + echo "Rebooting with kexec command..." + + # Find vmlinuz and initrd files in /mnt/onie-boot + vmlinuz_file=$(find /mnt/onie-boot -name 'vmlinuz*' | head -n 1) + initrd_file=$(find /mnt/onie-boot -name 'initrd*' | head -n 1) + + if [ -z "$vmlinuz_file" ] || [ -z "$initrd_file" ] + then + echo "Error: vmlinuz or initrd file not found. Falling back to reboot command." + reboot + else + # Get current kernel command line parameters + current_kernel_params=$(cat /proc/cmdline) + + # Load the kernel and initrd using kexec + kexec -l "$vmlinuz_file" --initrd="$initrd_file" --append="fastreboot=1 $current_kernel_params" + + # Execute kexec + kexec -e + fi +fi \ No newline at end of file