Ubuntu系统下的apt工具用来管理软件包很是方便,就连Linux系统内核都可以使用apt来更新。
而apt upgrade命令比较不够灵活,这一个命令下去,系统中所有可以升级的软件包都会被升级,包括系统内核,这也是Linux系统的一个软件包。有的时候,有些软件包我们不想升级,特别是系统内核。
可以用下面的方法来避免使用apt upgrade命令时,升级某个软件包,麦新杰就用系统内核包来举例说明。
首先,使用命令uname -r查看系统使用的内核名称;
使用dpkg --get-selections linux-image*命令查询已经安装内核的列表:
[email protected]:~$
[email protected]:~$ dpkg --get-selections linux-image*
linux-image-4.10.0-27-generic install
linux-image-4.4.0-31-generic install
linux-image-4.4.0-83-generic install
linux-image-extra-4.4.0-31-generic install
linux-image-extra-4.4.0-83-generic install
linux-image-generic install
[email protected]:~$
[email protected]:~$ uname -r
4.10.0-27-generic
[email protected]:~$
可以看出系统使用的内核是linux-image-4.10.0-27-generic。
将正在使用的内核软件包设置为hold状态,这个命令只能是root用户执行,不建议修改dpkg工具相关文件的属性。(位置:/usr/lib/dpkg)
[email protected]:~$
[email protected]:~$ su
Password:
[email protected]:/home/xinlin# cd
[email protected]:~# echo "linux-image-4.10.0-27-generic hold" | dpkg --set-selections
[email protected]:~#
[email protected]:~# exit
exit
[email protected]:~$
xinl[email protected]:~$ dpkg --get-selections linux-image-4.10.0-27-generic
linux-image-4.10.0-27-generic hold
[email protected]:~$
这样,就实现了使用apt upgrade命令,不升级hold软件包的功能。
注意:设置为hold状态的软件包,对于apt upgrade命令,不会升级,但是依然可以通过apt install命令将其升级并将状态切回install。因此,从安全性角度来看,这样做其实效果不大,仅仅只是避免了偶然的操作失误。本人还是推荐执行apt install来进行“定点升级”。