我在Ubuntu16.04上向我的/etc/缺省/grub添加了biosdevname=1和一些其他设置。每次有内核更新时,我都会被问到以下问题:
Found kernel: /boot/vmlinuz-4.15.0-136-generic
Found kernel: /boot/vmlinuz-4.15.0-135-generic
A new version of /boot/grub/menu.lst is available, but the version installed currently has
been locally modified.
1. install the package maintainer's version
2. keep the local version currently installed
3. show the differences between the versions
4. show a side-by-side difference between the versions
5. show a 3-way difference between available versions
6. do a 3-way merge between available versions (experimental)
7. start a new shell to examine the situation
What would you like to do about menu.lst? 2我有大约60台机器需要更新,这破坏了我的ansible剧本,我必须手动进入每台机器,并选择"2“来保持我现有的grub默认值。
我知道有dpkg环境变量可以告诉它“总是覆盖”或“始终保持”,但我不知道如何告诉它对单个包的选择。
我如何告诉apt“始终保持”我的/etc/默认/grub配置?
发布于 2021-02-25 15:41:08
提供这个问题的程序称为dpkg。在类似Debian的系统上安装包的后期阶段,apt会调用它。您可以使用-o Dpkg::Options::="OPTIONS"将配置选项传递给它。由于您希望使用dpkg (force old)来执行--force-confold,请使用以下命令:
apt-get install -o Dpkg::Options::="--force-confold" …这将禁用配置文件的所有修改。您可以将它与--force-confdef组合起来,以更新未经您修改的配置:
apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" …发布于 2021-02-26 12:16:26
@jiwopene给出的答案很好,但它适用于系统上的每个升级包。这不是我所问的,因为当配置文件中存在旧的、不推荐的选项时,一些升级的软件将无法工作。其他包将简单地用警告消息(例如sshd、postfix )填充日志文件,这会给中央日志记录(数据库索引、存储、搜索性能等)带来不必要的开销。最后我使用了下面的脚本。它应用@jiwopene中提到的选项,但指定只升级linux通用包。然后,它应用具有相同选项的autoremove来删除旧内核。
需要DEBIAN_FRONTEND=noninteractive环境变量是因为有些系统提供了一个文本模式对话框(假设这来自正在安装的dialog包)来询问是否覆盖已安装的配置文件,并且似乎忽略了指定的dpkg选项。
#!/bin/bash
# disable any dialog prompts
export DEBIAN_FRONTEND=noninteractive
# check if linux-generic package is installed here
dpkg -l linux-generic &>/dev/null
# if so, upgrade linux-generic package only and force-keep any config files
if [ "$?" -eq 0 ]; then
apt-get install -y --only-upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" linux-generic
# next, autoremove the old kernels and again force-keep grub config
apt-get -y autoremove -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
fihttps://unix.stackexchange.com/questions/636361
复制相似问题