我在 Intel Atom(amd64)和 Raspberry Pi(arm64)上安装了 Ubuntu Server 22.04。
使用最新的内核更新(由 安装unattended-upgrades
),文件/var/run/reboot-required
和/var/run/reboot-required.pkgs
尚未在英特尔系统上创建(因此系统未标记为重新启动),但在 RasPi 上它可以按预期工作。
日志条目从/var/log/apt/history.log
。
英特尔凌动 (Intel Atom):
Start-Date: 2022-05-24 06:52:55
Commandline: /usr/bin/unattended-upgrade
Install: linux-image-5.15.0-33-generic:amd64 (5.15.0-33.34, automatic), linux-headers-5.15.0-33-generic:amd64 (5.15.0-33.34, automatic), linux-modules-5.15.0-33-generic:amd64 (5.15.0-33.34, automatic), linux-headers-5.15.0-33:amd64 (5.15.0-33.34, automatic), linux-modules-extra-5.15.0-33-generic:amd64 (5.15.0-33.34, automatic)
Upgrade: linux-headers-generic:amd64 (5.15.0.30.33, 5.15.0.33.36), linux-generic:amd64 (5.15.0.30.33, 5.15.0.33.36), linux-image-generic:amd64 (5.15.0.30.33, 5.15.0.33.36)
End-Date: 2022-05-24 06:53:41
Start-Date: 2022-05-24 06:53:46
Commandline: /usr/bin/unattended-upgrade
Remove: linux-headers-5.15.0-27-generic:amd64 (5.15.0-27.28)
End-Date: 2022-05-24 06:53:47
Start-Date: 2022-05-24 06:53:51
Commandline: /usr/bin/unattended-upgrade
Remove: linux-modules-extra-5.15.0-27-generic:amd64 (5.15.0-27.28), linux-image-5.15.0-27-generic:amd64 (5.15.0-27.28), linux-modules-5.15.0-27-generic:amd64 (5.15.0-27.28)
End-Date: 2022-05-24 06:53:56
Start-Date: 2022-05-24 06:54:00
Commandline: /usr/bin/unattended-upgrade
Remove: linux-headers-5.15.0-27:amd64 (5.15.0-27.28)
End-Date: 2022-05-24 06:54:02
树莓派:
Start-Date: 2022-05-25 06:44:33
Commandline: /usr/bin/unattended-upgrade
Install: linux-modules-5.15.0-1008-raspi:arm64 (5.15.0-1008.8, automatic), linux-raspi-headers-5.15.0-1008:arm64 (5.15.0-1008.8, automatic), linux-image-5.15.0-1008-raspi:arm64 (5.15.0-1008.8, automatic), linux-headers-5.15.0-1008-raspi:arm64 (5.15.0-1008.8, automatic)
Upgrade: linux-headers-raspi:arm64 (5.15.0.1006.6, 5.15.0.1008.8), linux-raspi:arm64 (5.15.0.1006.6, 5.15.0.1008.8), linux-image-raspi:arm64 (5.15.0.1006.6, 5.15.0.1008.8)
End-Date: 2022-05-25 06:46:44
Start-Date: 2022-05-25 06:47:16
Commandline: /usr/bin/unattended-upgrade
Remove: linux-modules-5.15.0-1005-raspi:arm64 (5.15.0-1005.5), linux-image-5.15.0-1005-raspi:arm64 (5.15.0-1005.5)
End-Date: 2022-05-25 06:47:20
Start-Date: 2022-05-25 06:47:26
Commandline: /usr/bin/unattended-upgrade
Remove: linux-headers-5.15.0-1005-raspi:arm64 (5.15.0-1005.5)
End-Date: 2022-05-25 06:47:29
Start-Date: 2022-05-25 06:47:35
Commandline: /usr/bin/unattended-upgrade
Remove: linux-raspi-headers-5.15.0-1005:arm64 (5.15.0-1005.5)
End-Date: 2022-05-25 06:47:42
内核历史(5.15内核行):dpkg --list *linux-image* | grep "\-5.15" | grep -v "un"
英特尔凌动 (Intel Atom):(现已安装内核 5.15.0-30 和 5.15.0-33)
rc linux-image-5.15.0-27-generic 5.15.0-27.28 amd64 Signed kernel image generic
ii linux-image-5.15.0-30-generic 5.15.0-30.31 amd64 Signed kernel image generic
ii linux-image-5.15.0-33-generic 5.15.0-33.34 amd64 Signed kernel image generic
树莓派:(现已安装内核 5.15.0-1006 和 5.15.0-1008)
rc linux-image-5.15.0-1005-raspi 5.15.0-1005.5 arm64 Linux kernel image for version 5.15.0 on ARMv8 SMP
ii linux-image-5.15.0-1006-raspi 5.15.0-1006.6 arm64 Linux kernel image for version 5.15.0 on ARMv8 SMP
ii linux-image-5.15.0-1008-raspi 5.15.0-1008.8 arm64 Linux kernel image for version 5.15.0 on ARMv8 SMP
文件目录 /var/run/reboot-required
和/var/run/reboot-required.pkgs
。
英特尔凌动 (Intel Atom):
$ cat /var/run/reboot-required
cat: /var/run/reboot-required: No such file or directory
$ cat /var/run/reboot-required.pkgs
cat: /var/run/reboot-required.pkgs: No such file or directory
树莓派:
$ cat /var/run/reboot-required
*** System restart required ***
$ cat /var/run/reboot-required.pkgs
linux-image-5.15.0-1008-raspi
linux-base
我已经读过了这个答案,但我在两个系统上都安装了该软件包update-notifier-common
。而且,符号链接/run -> /var/run
也存在。
两个系统都已从 20.04 升级,现在它在两个系统上都按预期运行。还应注意,对于其他软件包(例如libssl3
),我很确定/var/run/reboot-required
两个系统上都已更新。
这对我来说有点烦人,因为我使用这些文件,既是为了知道已安装内核更新,也是为了在指定时间触发手动重启。因此,任何关于如何解决此问题并获取要/var/run/reboot-required
写入的文件的建议都将不胜感激。
注意:我刚刚从一位朋友那里得到确认(他也有一台 Intel 服务器),这里的文件已经按预期写入。所以看起来这也不是软件包错误。
答案1
因此现在,我的解决方案是每天运行以下脚本来模仿/cron
的所需行为:apt
unattended-upgrade
#!/bin/bash
# Get last reboot time and installed kernel
lastreboot=$(date -r /home/am/last_reboot +%s)
kernelinst=$(grep 'Upgrade: linux-headers-generic' /var/log/apt/history.log -A 1 -B 1 | tail -n 3)
# Get kernel version and install date
if [[ -n "$kernelinst" ]]
then
kernelvers=$(echo "$kernelinst" | grep -oP 'linux-image-[0-9]+\.[0-9]+\.[0-9-]+[A-Z-a-z]+')
kerneldate=$(date -d $(echo "$kernelinst" | grep 'End-Date' | awk '{print $2}') +%s)
fi
# Check if reboot-required.pkgs is already updated
if [[ -f /var/run/reboot-required.pkgs ]]
then
kernelpkgs=$(grep "$kernelvers" /var/run/reboot-required.pkgs)
fi
# Write to reboot-required/reboot-required.pkgs if conditions are met
if [[ "$kerneldate" -gt "$lastreboot" ]] && [[ "$kernelvers" != "$kernelpkgs" ]]
then
# Echo to /var/run/reboot-required
echo "*** System restart required ***" | tee /var/run/reboot-required
# Echo to /var/run/reboot-required.pkgs
echo "$kernelvers" | tee -a /var/run/reboot-required.pkgs
echo "linux-base" | tee -a /var/run/reboot-required.pkgs
else
echo "Do nothing"
fi