考虑更新整个系统镜像会影响到用户的数据和已经安装的应用,所以有些时候单独更新Linux内核是更好的选择。如果你的幽兰系统已经满足如下条件:

  1. 已经使用UEFI固件
  2. 可以成功启动到双剑1的Linux系统

那么可以参照下方步骤对Linux内核进行更新。

1. 下载更新包

下载链接:https://gedu.oss-cn-beijing.aliyuncs.com/Products/YourLand/Release/OpenSourceKernel/update.tar.gz

将下载好的更新包解压到幽兰上,目录内容如下所示。

ls
gedu  grub.cfg  opensources  update.sh

2. 运行更新脚本

进入刚刚解压好的目录内,执行下方的更新命令。

./update -a

更新脚本具体内容:

#!/bin/bash

GrubCfg="/boot/grub/grub.cfg"
NvmePathBase="/dev/nvme0n1"
OpSrcKrn="opensources"
GeDuKrn="gedu"

echo_with_color() {
    echo -e "$1 $2\e[0m"
}

update_failed() {
    echo_with_color "\e[41m" "update failed"
    exit -1
}

last_cmd_status_check() {
    if [ "$?" -eq 0 ]; then
        echo_with_color "\e[42m" "$1 success"
    else
        update_failed
    fi
}

uuid_get() {
        uuid=$(blkid -s $1 -o value $NvmePathBase$2)
        last_cmd_status_check "get $2 $1"
}

uuid_replace() {
        uuid_get $1 $2
        sudo sed -i 's/'"$3"'/'"$uuid"'/g' $GrubCfg
        last_cmd_status_check "replace $2 $1"
}

grub_cfg_update() {
        echo_with_color "\e[33m" "will update grub.cfg"

        sudo rm -rf $GrubCfg
        sudo cp $Path/grub.cfg $GrubCfg

        uuid_replace "UUID" "p1" "P1-UUID"
        uuid_replace "UUID" "p2" "P2-UUID"
        uuid_replace "PARTUUID" "p2" "P2-PUUID"
}

debs_install() {
        local arr=()
        find $1 -name "*.deb" > $1/debs_list.txt
        while read line; do
                arr+=("$line")
        done < $1/debs_list.txt

        for i in "${!arr[@]}"; do
                echo_with_color "\e[33m" "will install ${arr[i]}"
                sudo dpkg -i ${arr[i]} >> $1/install_debs.log 2>&1
                last_cmd_status_check "install ${arr[i]}"
        done
}

cur_krn_check() {
        local krn_type=$(uname -r)
        if [ "$krnn_type" == "$1" ]
        then
                echo_with_color "\e[41m" "updated kernel type cannot be consistent with the currently allowed kernel type"
                update_failed
        fi
}

opsrc_kernel_install() {
        echo_with_color "\e[33m" "will install kernel [open sources code]"

        cur_krn_check "5.10.110-opensources-rk3588"

        debs_install $Path/$OpSrcKrn

        sudo cp $Path/$OpSrcKrn/Image /boot/Image-opsrc
        last_cmd_status_check "update Image-opsrc"
}

gedu_kernel_install() {
        echo_with_color "\e[33m" "will install kernel [gedu code]"

        cur_krn_check "5.10.110-rockchip-rk3588"

        debs_install $Path/$GeDuKrn

        sudo cp $Path/$GeDuKrn/Image /boot/Image-gedu
        last_cmd_status_check "update Image-gedu"
}

kernel_update() {
        grub_cfg_update
        if [ "$1" == "opsrc" ]
        then
                opsrc_kernel_install
        else
                gedu_kernel_install
        fi
}

usage() {
        echo_with_color "\e[36m" "./update [ -o / -g / -a]"
        echo_with_color "\e[36m" "-o: install kernel [open sources code]"
        echo_with_color "\e[36m" "-g: install kernel [gedu code]"
        echo_with_color "\e[36m" "-o: all, -o + -g"
}

Path=$(cd `dirname $0`; pwd)

if [ "$1" == "-o" ]
then
        kernel_update "opsrc"
elif [ "$1" == "-g" ]
then
        kernel_update "gedu"
elif [ "$1" == "-a" ]
then
        kernel_update "opsrc"
        kernel_update "gedu"
else
        usage
fi
作者:Zhang Yinkui  创建时间:2024-01-08 17:40
最后编辑:Zhang Yinkui  更新时间:2024-05-06 17:42