Ubuntu 20.04 升级最新内核、安装指定内核版本

您所在的位置:网站首页 ubuntu最早版本 Ubuntu 20.04 升级最新内核、安装指定内核版本

Ubuntu 20.04 升级最新内核、安装指定内核版本

#Ubuntu 20.04 升级最新内核、安装指定内核版本| 来源: 网络整理| 查看: 265

Ubuntu 20.04 升级最新内核、安装指定内核版本

https://cdmana.com/2021/12/202112290531351544.html

查看目前版本

uname -rs

 

 

#查看当前内核版本uname -r#查看软件库中可下载的内核sudo apt list | grep linux-generic*

 

 

#下载最新的内核(不用和我一样,但我的这个版本可以支持,具体版本以你的软件库中为准)sudo apt-get install linux-generic-hwe-20.04-edge/focal-updates

 

 

 

  更新之后,打开电脑设置后可以发现显示出了第二个屏幕,并且可以手动选择功能。

 

 

 

 

 

 

下载ubuntu-mainline-kernel脚本

wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh

下载不了看后面脚本

 

 

将脚本放在可执行路径中

sudo install ubuntu-mainline-kernel.sh /usr/local/bin/

检查最新的可用内核版本

ubuntu-mainline-kernel.sh -c

获得最新版本并确认这就是您想要安装在系统上的版本之后,运行

sudo ubuntu-mainline-kernel.sh -i

 

 

重新启动系统并检查内核版本

uname -rs

安装结束

卸载最新的Linux Kernel

sudo ubuntu-mainline-kernel.sh -u

首先重启系统,然后运行以下命令:

uname -rs 参考安装脚本

ubuntu-mainline-kernel.sh

#!/usr/bin/env bash # shellcheck disable=SC1117 # Ubuntu Kernel PPA info ppa_host="kernel.ubuntu.com" ppa_index="/~kernel-ppa/mainline/" ppa_key="17C622B0" # If quiet=1 then no log messages are printed (except errors) quiet=0 # If check_signature=0 then the signature of the CHECKSUMS file will not be checked check_signature=1 # If check_checksum=0 then the checksums of the .deb files will not be checked check_checksum=1 # If doublecheckversion=1 then also check the version specific ppa page to make # sure the kernel build was successful doublecheckversion=1 # Connect over http or https to ppa (only https works) use_https=1 # Path to sudo command, empty by default sudo="" #sudo=$(command -v sudo) # Uncomment this line if you dont want to sudo yourself # Path to wget command wget=$(command -v wget) ##### ## Below are internal variables of which most can be toggled by command options ## DON'T CHANGE THESE MANUALLY ##### # (internal) If cleanup_files=1 then before exiting all downloaded/temporaryfiles # are removed cleanup_files=1 # (internal) If do_install=0 downloaded deb files will not be installed do_install=1 # (internal) If use_lowlatency=1 then the lowlatency kernel will be installed use_lowlatency=0 # (internal) If use_lpae=1 then the lpae kernel will be installed use_lpae=0 # (internal) If use_snapdragon=1 then the snapdragon kernel will be installed use_snapdragon=0 # (internal) If use_rc=1 then release candidate kernel versions are also checked use_rc=0 # (internal) If assume_yes=1 assume yes on all prompts assume_yes=0 # (internal) How many files we expect to retrieve from the ppa # checksum, signature, header-all, header-arch, image(-unsigned), modules expected_files_count=6 # (internal) Which action/command the script should run run_action="help" # (internal) The workdir where eg the .deb files are downloaded workdir="/tmp/$(basename "$0")/" # (internal) The stdio where all detail output should be sent debug_target="/dev/null" # (internal) Holds all version numbers of locally installed ppa kernels LOCAL_VERSIONS=() # (internal) Holds all version numbers of available ppa kernels REMOTE_VERSIONS=() # (internal) The architecture of the local system arch=$(dpkg --print-architecture) # (internal) The text to search for to check if the build was successfully # NOTE: New succeed text since v5.6.18 build_succeeded_text="(Build for ${arch} succeeded|Test ${arch}/build succeeded)" # (internal) The pid of the child process which checks download progress monitor_pid=0 # (internal) The size of the file which is being downloaded download_size=0 action_data=() ##### ## Check if we are running on an Ubuntu-like OS ##### # shellcheck disable=SC1091,SC2015 [ -f "/etc/os-release" ] && { source /etc/os-release [[ "$ID" == "ubuntu" ]] || [[ "$ID_LIKE" =~ "ubuntu" ]] } || { OS=$(lsb_release -si 2>&-) [[ "$OS" == "Ubuntu" ]] || [[ "$OS" == "LinuxMint" ]] || [[ "$OS" == "neon" ]] || { echo "Abort, this script is only intended for Ubuntu-like distros" exit 2 } } ##### ## helper functions ##### single_action () { [ "$run_action" != "help" ] && { err "Abort, only one argument can be supplied. See -h" exit 2 } } log () { [ $quiet -eq 0 ] && echo "$@" } logn () { [ $quiet -eq 0 ] && echo -n "$@" } warn () { [ $quiet -eq 0 ] && echo "$@" >&2 } err () { echo "$@" >&2 } ##### ## Simple command options parser ##### while (( "$#" )); do argarg_required=0 case $1 in -c|--check) single_action run_action="check" ;; -l|--local-list) single_action run_action="local-list" argarg_required=1 ;; -r|--remote-list) single_action run_action="remote-list" argarg_required=1 ;; -i|--install) single_action run_action="install" argarg_required=1 ;; -u|--uninstall) single_action run_action="uninstall" argarg_required=1 ;; -p|--path) if [ -z "$2" ] || [ "${2##-}" != "$2" ]; then err "Option $1 requires an argument." exit 2 else workdir="$(realpath "$2")/" shift if [ ! -d "$workdir" ]; then mkdir -p "$workdir"; fi if [ ! -d "$workdir" ] || [ ! -w "$workdir" ]; then err "$workdir is not writable" exit 1 fi cleanup_files=0 fi ;; -ll|--lowlatency|--low-latency) [[ "$arch" != "amd64" ]] && [[ "$arch" != "i386" ]] && { err "Low-latency kernels are only available for amd64 or i386 architectures" exit 3 } use_lowlatency=1 ;; -lpae|--lpae) [[ "$arch" != "armhf" ]] && { err "Large Physical Address Extension (LPAE) kernels are only available for the armhf architecture" exit 3 } use_lpae=1 ;; --snapdragon) [[ "$arch" != "arm64" ]] && { err "Snapdragon kernels are only available for the arm64 architecture" exit 3 } use_snapdragon=1 ;; --rc) use_rc=1 ;; -s|--signed) log "The option '--signed' is not yet implemented" ;; --yes) assume_yes=1 ;; -q|--quiet) [ "$debug_target" == "/dev/null" ] && { quiet=1; } ;; -do|--download-only) do_install=0 cleanup_files=0 ;; -ns|--no-signature) check_signature=0 ;; -nc|--no-checksum) check_checksum=0 ;; -d|--debug) debug_target="/dev/stderr" quiet=0 ;; -h|--help) run_action="help" ;; *) run_action="help" err "Unknown argument $1" ;; esac if [ $argarg_required -eq 1 ]; then [ -n "$2" ] && [ "${2##-}" == "$2" ] && { action_data+=("$2") shift } elif [ $argarg_required -eq 2 ]; then # shellcheck disable=SC2015 [ -n "$2" ] && [ "${2##-}" == "$2" ] && { action_data+=("$2") shift } || { err "Option $1 requires an argument" exit 2 } fi shift done ##### ## internal functions ##### containsElement () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] || [[ "$e" =~ $1- ]] && return 0; done return 1 } download () { host=$1 uri=$2 if [ $use_https -eq 1 ]; then $wget -q --save-headers --output-document - "https://$host$uri" else exec 3/dev/tcp/"$host"/80 echo -e "GET $uri HTTP/1.0\r\nHost: $host\r\nConnection: close\r\n\r\n" >&3 cat /dev/null } remove_http_headers () { file="$1" nr=0 while(true); do nr=$((nr + 1)) line=$(head -n$nr "$file" | tail -n 1) if [ -z "$(echo "$line" | tr -cd '\r\n')" ]; then tail -n +$nr "$file" > "${file}.tmp" mv "${file}.tmp" "${file}" break fi [ $nr -gt 100 ] && { err "Abort, could not remove http headers from file" exit 3 } done } load_local_versions() { local version if [ ${#LOCAL_VERSIONS[@]} -eq 0 ]; then IFS=$'\n' for pckg in $(dpkg -l linux-image-* | cut -d " " -f 3 | sort -V); do # only match kernels from ppa if [[ "$pckg" =~ linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6} ]]; then version="v"$(echo "$pckg" | cut -d"-" -f 3,4) LOCAL_VERSIONS+=("$version") fi done unset IFS fi } latest_local_version() { load_local_versions 1 if [ ${#LOCAL_VERSIONS[@]} -gt 0 ]; then local sorted mapfile -t sorted < &1; then logn "Importing kernel-ppa gpg key " if gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv ${ppa_key} >$debug_target 2>&1; then log "ok" else logn "failed" warn "Unable to check signature" check_signature=0 fi fi if [ $check_signature -eq 1 ]; then if gpg --verify CHECKSUMS.gpg CHECKSUMS >$debug_target 2>&1; then log "Signature of checksum file has been successfully verified" else err "Abort, signature of checksum file is NOT OK" exit 4 fi fi fi if [ $check_checksum -eq 1 ]; then shasums=( "sha256sum" "sha1sum" ) for shasum in "${shasums[@]}"; do xshasum=$(command -v "$shasum") if [ -n "$xshasum" ] && [ -x "$xshasum" ]; then # shellcheck disable=SC2094 shasum_result=$($xshasum --ignore-missing -c CHECKSUMS 2>>$debug_target | tee -a $debug_target | wc -l) if [ "$shasum_result" -eq 0 ] || [ "$shasum_result" -ne ${#debs[@]} ]; then err "Abort, $shasum returned an error $shasum_result" exit 4 else log "Checksums of deb files have been successfully verified with $shasum" fi break fi done fi if [ $do_install -eq 1 ]; then if [ ${#debs[@]} -gt 0 ]; then log "Installing ${#debs[@]} packages" $sudo dpkg -i "${debs[@]}" >$debug_target 2>&1 else warn "Did not find any .deb files to install" fi else log "deb files have been saved to $workdir" fi if [ $cleanup_files -eq 1 ]; then log "Cleaning up work folder" rm -f "$workdir"*.deb rm -f "$workdir"CHECKSUM* rmdir "$workdir" fi ;; uninstall) guard_run_as_root load_local_versions if [ ${#LOCAL_VERSIONS[@]} -eq 0 ]; then echo "No installed mainline kernels found" exit 1 elif [ -z "${action_data[0]}" ]; then echo "Which kernel version do you wish to uninstall?" nr=0 for version in "${LOCAL_VERSIONS[@]}"; do echo "[$nr]: $version" nr=$((nr + 1)) [ $nr -gt 9 ] && break done echo -n "type the number between []: " read -rn1 index echo "" uninstall_version=${LOCAL_VERSIONS[$index]} elif containsElement "v${action_data[0]#v}" "${LOCAL_VERSIONS[@]}"; then uninstall_version="v"${action_data[0]#v} else err "Kernel version ${action_data[0]} not installed locally" exit 2 fi if [ $assume_yes -eq 0 ]; then echo -n "Are you sure you wish to remove kernel version $uninstall_version? (y/N)" read -rsn1 continue echo "" else continue="y" fi if [ "$continue" == "y" ] || [ "$continue" == "Y" ]; then IFS=$'\n' pckgs=() for pckg in $(dpkg -l linux-{image,image-[un]?signed,headers,modules}-"${uninstall_version#v}"* 2>$debug_target | cut -d " " -f 3); do # only match kernels from ppa, they have 6 characters as second version string if [[ "$pckg" =~ linux-headers-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6} ]]; then pckgs+=("$pckg:$arch") pckgs+=("$pckg:all") elif [[ "$pckg" =~ linux-(image(-(un)?signed)?|modules)-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6} ]]; then pckgs+=("$pckg:$arch") fi done if [ ${#pckgs[@]} -eq 0 ]; then warn "Did not find any packages to remove" else echo "The following packages will be removed: " echo "${pckgs[@]}" if [ $assume_yes -eq 0 ]; then echo -n "Are you really sure? Do you still have another kernel installed? (y/N)" read -rsn1 continue echo "" else continue="y" fi if [ "$continue" == "y" ] || [ "$continue" == "Y" ]; then if $sudo env DEBIAN_FRONTEND=noninteractive dpkg --purge "${pckgs[@]}" 2>$debug_target >&2; then log "Kernel $uninstall_version successfully purged" exit 0 fi fi fi fi ;; esac exit 0

  



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3