分类
devops

解决ubuntu22.04版本apt upgrade 或者 apt install 提示重启


Last Updated on 2022-10-20

Symptoms

ubuntu 22.04 通过apt upgrade 安装完新版本的kernel后会进入一个text-based user interfaces,提示用户哪些服务需要重启。

Resolution

# Enable/disable hints on pending kernel upgrades:
# 1: requires the user to acknowledge pending kernels
# 0: disable kernel checks completely
# -1: print kernel hints to stderr only
#$nrconf{kernelhints} = -1;

# Restart mode: (l)ist only, (i)nteractive or (a)utomatically.
#
# ATTENTION: If needrestart is configured to run in interactive mode but is run
# non-interactive (i.e. unattended-upgrades) it will fallback to list only mode.
#
#$nrconf{restart} = ‘i’;

通过更改以下两个参数

echo "\$nrconf{kernelhints} = 0;" >> /etc/needrestart/needrestart.conf
echo "\$nrconf{restart} = 'l';" >> /etc/needrestart/needrestart.conf

或者增加一个配置片段

cat > /etc/needrestart/conf.d/silence_kernel.conf <<'EOF'
$nrconf{kernelhints} = 0;
$nrconf{restart} = 'l';
EOF

或者可以直接把这个软件删除掉

apt autoremove -y --purge needrestart

Ref