无法使用 sudo apt autoremove 删除 linux 映像

无法使用 sudo apt autoremove 删除 linux 映像

我试过

sudo apt autoremove

结果如下

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  linux-image-5.13.0-21-generic
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
3 not fully installed or removed.
After this operation, 10.3 MB disk space will be freed.
Do you want to continue? [Y/n]

接受

(Reading database ... 236998 files and directories currently installed.)
Removing linux-image-5.13.0-21-generic (5.13.0-21.21) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.13.0-21-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
/usr/sbin/grub-mkconfig: 1: /etc/default/grub: d#: not found
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127
<b>dpkg:</b> error processing package linux-image-5.13.0-21-generic (--remove):
 installed linux-image-5.13.0-21-generic package post-removal script subprocess returned error exit status 1
<b>dpkg:</b> too many errors, stopping
Errors were encountered while processing:
 linux-image-5.13.0-21-generic
Processing was halted because there were too many errors.
E: </b></font>Sub-process /usr/bin/dpkg returned an error code (1)

我也试过

sudo apt --fix-missing install

正在读取软件包列表...完成
构建依赖关系树...完成
正在读取状态信息...完成
下列软件包将被删除:
  Linux-映像-5.13.0-21-通用
0 个已升级,0 个已新安装,1 个已删除,1 个未升级。
3 未完全安装或删除。
此操作后,将释放10.3 MB的磁盘空间。
您想继续吗?[Y/n] y
(正在读取数据库...当前安装了 236998 个文件和目录。)
正在删除 linux-image-5.13.0-21-generic (5.13.0-21.21) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs:删除 /boot/initrd.img-5.13.0-21-generic
/etc/kernel/postrm.d/zz-update-grub:
源文件“/etc/default/grub”
/usr/sbin/grub-mkconfig:1:/etc/default/grub:d#:未找到
运行部分:/etc/kernel/postrm.d/zz-update-grub 退出,返回代码 127
软件包:处理软件包 linux-image-5.13.0-21-generic (--remove) 时出错:
 已安装 linux-image-5.13.0-21-generic 包删除后脚本子进程 ret
错误退出状态 1
软件包:错误太多,停止
处理时遇到错误:
 Linux-映像-5.13.0-21-通用
由于错误太多,处理已停止。
埃:子进程 /usr/bin/dpkg 返回错误代码 (1)
dkms status
未找到命令“dkms”,但可以使用以下命令安装:
sudo apt 安装 dkms

当我尝试安装 dkms 时

3 分 53 秒内获取 130 MB (559 kB/s)                                             
(正在读取数据库...当前安装了 236998 个文件和目录。)
正在删除 linux-image-5.13.0-21-generic (5.13.0-21.21) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs:删除 /boot/initrd.img-5.13.0-21-generic
/etc/kernel/postrm.d/zz-update-grub:
源文件“/etc/default/grub”
/usr/sbin/grub-mkconfig:1:/etc/default/grub:d#:未找到
运行部分:/etc/kernel/postrm.d/zz-update-grub 退出,返回代码 127
软件包:处理软件包 linux-image-5.13.0-21-generic (--remove) 时出错:
 已安装 linux-image-5.13.0-21-generic 包删除后脚本子进程 ret
错误退出状态 1
软件包:错误太多,停止
处理时遇到错误:
 Linux-映像-5.13.0-21-通用
由于错误太多,处理已停止。
埃:子进程 /usr/bin/dpkg 返回错误代码 (1)

的结果uname -r

5.13.0-22-generic

的结果sudo apt -f install

Reading package lists...   Done  
Building dependency tree... Done    
Reading state information... Done   
The following packages will be REMOVED:  
  linux-image-5.13.0-21-generic  
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.  
3 not fully installed or removed.  
After this operation, 10.3 MB disk space will be freed.  
Do you want to continue? \[Y/n\] y  
(Reading database ... 236998 files and directories currently installed.)  
Removing linux-image-5.13.0-21-generic (5.13.0-21.21) ...  
/etc/kernel/postrm.d/initramfs-tools:  
update-initramfs: Deleting /boot/initrd.img-5.13.0-21-generic
/etc/kernel/postrm.d/zz-update-grub:  
Sourcing file \`/etc/default/grub'  
/usr/sbin/grub-mkconfig: 1: /etc/default/grub: d#: not found  
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127  
**dpkg:** error processing package linux-image-5.13.0-21-generic (--remove):  
 installed linux-image-5.13.0-21-generic package post-removal script subprocess ret
urned error exit status 1  
**dpkg:** too many errors, stopping  
Errors were encountered while processing:  
 linux-image-5.13.0-21-generic  
Processing was halted because there were too many errors.  
**E:** Sub-process /usr/bin/dpkg returned an error code (1)  

输出ls /var/lib/dpkg/info | grep linux

console-setup-linux.conffiles  
console-setup-linux.list  
console-setup-linux.md5sums  
console-setup-linux.postinst  
console-setup-linux.postrm  
console-setup-linux.prerm  
libselinux1:amd64.list  
libselinux1:amd64.md5sums  
libselinux1:amd64.shlibs  
libselinux1:amd64.symbols  
libselinux1:amd64.triggers  
libselinux1:i386.list  
libselinux1:i386.md5sums  
libselinux1:i386.shlibs  
libselinux1:i386.symbols  
libselinux1:i386.triggers  
linux-base.conffiles  
linux-base.list  
linux-base.md5sums  
linux-base.postinst  
linux-base.postrm  
linux-base.templates  
linux-firmware.list  
linux-firmware.md5sums  
linux-firmware.postinst  
linux-generic-hwe-20.04.list  
linux-generic-hwe-20.04.md5sums  
linux-headers-5.13.0-22-generic.list  
linux-headers-5.13.0-22-generic.md5sums  
linux-headers-5.13.0-22-generic.postinst  
linux-headers-5.13.0-22.list  
linux-headers-5.13.0-22.md5sums  
linux-headers-5.13.0-23-generic.list  
linux-headers-5.13.0-23-generic.md5sums  
linux-headers-5.13.0-23-generic.postinst  
linux-headers-5.13.0-23.list  
linux-headers-5.13.0-23.md5sums  
linux-headers-5.13.0-25-generic.list  
linux-headers-5.13.0-25-generic.md5sums  
linux-headers-5.13.0-25-generic.postinst  
linux-headers-5.13.0-25.list  
linux-headers-5.13.0-25.md5sums  
linux-headers-generic-hwe-20.04.list  
linux-headers-generic-hwe-20.04.md5sums  
linux-image-5.13.0-20-generic.list  
linux-image-5.13.0-20-generic.postrm  
linux-image-5.13.0-21-generic.list  
linux-image-5.13.0-21-generic.md5sums  
linux-image-5.13.0-21-generic.postinst  
linux-image-5.13.0-21-generic.postrm  
linux-image-5.13.0-21-generic.preinst  
linux-image-5.13.0-21-generic.prerm  
linux-image-5.13.0-21-generic.triggers  
linux-image-5.13.0-22-generic.list  
linux-image-5.13.0-22-generic.md5sums  
linux-image-5.13.0-22-generic.postinst  
linux-image-5.13.0-22-generic.postrm  
linux-image-5.13.0-22-generic.preinst  
linux-image-5.13.0-22-generic.prerm  
linux-image-5.13.0-22-generic.triggers  
linux-image-5.13.0-23-generic.list  
linux-image-5.13.0-23-generic.md5sums  
linux-image-5.13.0-23-generic.postinst  
linux-image-5.13.0-23-generic.postrm  
linux-image-5.13.0-23-generic.preinst  
linux-image-5.13.0-23-generic.prerm  
linux-image-5.13.0-23-generic.triggers  
linux-image-5.13.0-25-generic.list  
linux-image-5.13.0-25-generic.md5sums  
linux-image-5.13.0-25-generic.postinst  
linux-image-5.13.0-25-generic.postrm  
linux-image-5.13.0-25-generic.preinst  
linux-image-5.13.0-25-generic.prerm  
linux-image-5.13.0-25-generic.triggers  
linux-image-generic-hwe-20.04.list  
linux-image-generic-hwe-20.04.md5sums  
linux-libc-dev:amd64.list  
linux-libc-dev:amd64.md5sums  
linux-modules-5.13.0-20-generic.list  
linux-modules-5.13.0-20-generic.postrm  
linux-modules-5.13.0-21-generic.list  
linux-modules-5.13.0-21-generic.postrm  
linux-modules-5.13.0-22-generic.list  
linux-modules-5.13.0-22-generic.md5sums  
linux-modules-5.13.0-22-generic.postinst  
linux-modules-5.13.0-22-generic.postrm  
linux-modules-5.13.0-23-generic.list  
linux-modules-5.13.0-23-generic.md5sums  
linux-modules-5.13.0-23-generic.postinst  
linux-modules-5.13.0-23-generic.postrm  
linux-modules-5.13.0-25-generic.list  
linux-modules-5.13.0-25-generic.md5sums  
linux-modules-5.13.0-25-generic.postinst  
linux-modules-5.13.0-25-generic.postrm  
linux-modules-extra-5.13.0-20-generic.list  
linux-modules-extra-5.13.0-20-generic.postrm  
linux-modules-extra-5.13.0-21-generic.list  
linux-modules-extra-5.13.0-21-generic.postrm  
linux-modules-extra-5.13.0-22-generic.list  
linux-modules-extra-5.13.0-22-generic.md5sums  
linux-modules-extra-5.13.0-22-generic.postinst  
linux-modules-extra-5.13.0-22-generic.postrm  
linux-modules-extra-5.13.0-23-generic.list  
linux-modules-extra-5.13.0-23-generic.md5sums  
linux-modules-extra-5.13.0-23-generic.postinst  
linux-modules-extra-5.13.0-23-generic.postrm  
linux-modules-extra-5.13.0-25-generic.list  
linux-modules-extra-5.13.0-25-generic.md5sums  
linux-modules-extra-5.13.0-25-generic.postinst  
linux-modules-extra-5.13.0-25-generic.postrm  
linux-sound-base.config  
linux-sound-base.list  
linux-sound-base.md5sums  
linux-sound-base.postinst  
linux-sound-base.postrm  
linux-sound-base.templates  
pptp-linux.conffiles  
pptp-linux.list  
pptp-linux.md5sums  
util-linux.conffiles  
util-linux.list  
util-linux.md5sums  
util-linux.postinst  
util-linux.postrm  
util-linux.preinst  
util-linux.prerm  

输出lsb_release -a

No LSB modules are available.  
Distributor ID: Ubuntu  
Description:    Ubuntu 21.10  
Release:    21.10  
Codename:   impish 

输出cat /etc/default/grub

d# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB\_DEFAULT=0
GRUB\_TIMEOUT\_STYLE=hidden
GRUB\_TIMEOUT=10
GRUB\_DISTRIBUTOR=\`lsb\_release -i -s 2> /dev/null || echo Debian\`
GRUB\_CMDLINE\_LINUX\_DEFAULT="quiet splash noresume"
GRUB\_CMDLINE\_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB\_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB\_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command \`vbeinfo'
#GRUB\_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB\_DISABLE\_LINUX\_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB\_DISABLE\_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB\_INIT\_TUNE="480 440 1"

答案1

正如错误信息所说:

 /usr/sbin/grub-mkconfig: 1: /etc/default/grub: d#: not found

您的/etc/default/grub文件包含一些无效字符。无效字符位于d文件开头。请将其删除。

d# If you change this file.....

让它看起来像:

# If you change this file....

删除后,运行:

sudo apt update 
sudo apt -f install 
sudo update-grub

理想情况下,您的文件将包含:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

相关内容