Score:1

Apt and Grub Broken after upgrade & autoremove

cn flag

I ran the following commands in the order 2 days ago:

  1. sudo apt update && sudo apt upgrade -y
  2. sudo apt autoremove
  3. sudo apt update && sudo apt upgrade -y

now apt package manager is not letting me install any package. I am unable to update the grub either. The computer is able to restart itself as usual.

sudo apt --fix-broken install returns the same errors attaching output anyway:

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

unmesh@unmeshpc:~$ sudo apt update
[sudo] password for unmesh: 
Hit:1 http://dl.google.com/linux/chrome/deb stable InRelease                                               
Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease                                                  
Hit:3 http://ppa.launchpad.net/gezakovacs/ppa/ubuntu focal InRelease                                       
Hit:5 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease                                          
Hit:6 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu focal InRelease                                 
Hit:7 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease                                        
Hit:8 http://ppa.launchpad.net/tsbarnes/indicator-keylock/ubuntu focal InRelease                           
Get:9 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                                  
Hit:10 http://packages.ros.org/ros/ubuntu focal InRelease                                                  
Hit:4 https://packagecloud.io/ookla/speedtest-cli/ubuntu focal InRelease                                   
Fetched 114 kB in 8s (14.8 kB/s)                                                                           
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

I am attaching the bash output after running the upgrade command for easier debugging:

unmesh@unmeshpc:~$ sudo apt upgrade -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
3 not fully installed or removed.
Need to get 0 B/8,992 kB of archives.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-5.11.0-38-generic (5.11.0-38.42~20.04.1) ...
depmod: WARNING: could not open modules.order at /lib/modules/5.11.0-38-generic:
 No such file or directory
depmod: WARNING: could not open modules.builtin at /lib/modules/5.11.0-38-generi
c: No such file or directory
Setting up linux-image-5.11.0-41-generic (5.11.0-41.45~20.04.1) ...
Processing triggers for linux-image-5.11.0-38-generic (5.11.0-38.42~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.11.0-38-generic
Error! Your kernel headers for kernel 5.11.0-38-generic cannot be found.
Please install the linux-headers-5.11.0-38-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 5.11.0-38-generic cannot be found.
Please install the linux-headers-5.11.0-38-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.11.0-38-generic
cat: /var/tmp/mkinitramfs_f3YBdS/lib/modules/5.11.0-38-generic/modules.builtin: 
No such file or directory
depmod: WARNING: could not open modules.order at /var/tmp/mkinitramfs_f3YBdS/lib
/modules/5.11.0-38-generic: No such file or directory
depmod: WARNING: could not open modules.builtin at /var/tmp/mkinitramfs_f3YBdS/l
ib/modules/5.11.0-38-generic: No such file or directory
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
/usr/sbin/grub-mkconfig: 14: /etc/default/grub: GRUB_CMDLINE_LIN: not found
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 127
dpkg: error processing package linux-image-5.11.0-38-generic (--configure):
 installed linux-image-5.11.0-38-generic package post-installation script subpro
cess returned error exit status 1
Processing triggers for linux-image-5.11.0-41-generic (5.11.0-41.45~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.11.0-41-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.11.0-41-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
/usr/sbin/grub-mkconfig: 14: /etc/default/grub: GRUB_CMDLINE_LIN: not found
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 127
dpkg: error processing package linux-image-5.11.0-41-generic (--configure):
 installed linux-image-5.11.0-41-generic package post-installation script subpro
cess returned error exit status 1
Errors were encountered while processing:
 linux-image-5.11.0-38-generic
 linux-image-5.11.0-41-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

The update-grub output gives the following output:

unmesh@unmeshpc:~$ sudo update-grub
Sourcing file `/etc/default/grub'
/usr/sbin/grub-mkconfig: 14: /etc/default/grub: GRUB_CMDLINE_LIN: not found

Neofetch output as follows:

$ neofetch
            .-/+oossssoo+/-.               unmesh@unmeshpc 
        `:+ssssssssssssssssss+:`           --------------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 20.04.3 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Host: HP Pavilion Gaming Laptop 15-ec1xxx 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 5.11.0-41-generic 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 1 day, 10 hours, 58 mins 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 3763 (dpkg), 22 (snap) 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 5.0.17 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Resolution: 1920x1080 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   DE: GNOME 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: Mutter 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   WM Theme: Yaru-dark 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Theme: adwaita-dark-amoled-master [GTK2/3] 
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Icons: Yaru [GTK2/3] 
  +sssssssssdmydMMMMMMMMddddyssssssss+     Terminal: tilix 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      CPU: AMD Ryzen 5 4600H with Radeon Graphics (12) @ 3.000GHz 
    .ossssssssssssssssssdMMMNysssso.       GPU: NVIDIA 01:00.0 NVIDIA Corporation Device 1f99 
      -+sssssssssssssssssyyyssss+-         GPU: AMD ATI 05:00.0 Renoir 
        `:+ssssssssssssssssss+:`           Memory: 2625MiB / 7309MiB 
            .-/+oossssoo+/-.
                                                               

I am running the following kernel:

uname -r
5.11.0-41-generic

                                                               

What can I do to fix these issues?

Thank You

Regards, Unmesh

Nmath avatar
ng flag
Here's the problem with running the `-y` tag in your command: It tells the command to automatically answer yes, when there is normally a summary before you proceed. So when you use it, you don't get to audit and approve what is going to take place when you execute. Similarly if you chain commands with `&&`, you don't get to see if there are problems with the first command before the next command is automatically executed. Please edit your question with the output of `sudo apt update` and `sudo apt --fix-broken install`
Unmesh Deshpande avatar
cn flag
Problem solved! In the update, there was a space between the LINUX as LIN UX on line 14 in the grub file. removed the space and all is good now. Thank You!
Nmath avatar
ng flag
You are new here. Ask Ubuntu is a Question and Answer site. Our goal is to host the largest catalog of questions and answers about Ubuntu. If you found the answer to your question, please post the details of your solution as an **answer** below. Your contribution can be helpful to future visitors with the same problem. Make sure that your answer is detailed in a way that someone else can reproduce the steps. Tell us the actual path of the "grub file" and exactly which line to change. Line 14 might not be line 14 on another system. Thanks in advance for your contribution.
karel avatar
sa flag
Does this answer your question? [partial upgrade](https://askubuntu.com/questions/381510/partial-upgrade)
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.