Score:2

cannot remove linux image with sudo apt autoremove

fr flag

I tried

sudo apt autoremove

With the following result

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]

On accepting

(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)

I also tried

sudo apt --fix-missing 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)
dkms status
Command 'dkms' not found, but can be installed with:
sudo apt install dkms

when I tried to install dkms

Fetched 130 MB in 3min 53s (559 kB/s)                                             
(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)

result of uname -r

5.13.0-22-generic

result of 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)  

output of 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  

output of lsb_release -a

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

output of 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"
Deepak Tandan avatar
fr flag
@Someone thanks for your help . I have included the output of `cat /etc/default/grub` . I regret that I couldn't format it correctly, though. Thanks
Someone avatar
my flag
Please change the contents of your grub file to [the contents provided in this answer](https://askubuntu.com/a/509925/1460940) and run `apt -f install`
Deepak Tandan avatar
fr flag
@Someone deleting the 'd' from the first line of /etc/default/grub seems to have solved the issue. I will keep you updated. Thank you
Score:0
my flag

As the error message says:

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

Your /etc/default/grub file has some invalid characters. The invalid character is d at the beginning of the file. Remove that.

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

Make it look like:

# If you change this file....

After removing, run:

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

Ideally, your file will contain:

# 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"
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.