5

My Ubuntu Server 18.04 system, while it continues to work, has become unable to apply any updates. I'm not aware of any system change that I made that could be the culprit.

What can I do to fix this? I've tried autoremove, purge, etc.

Here is typical output but any apt command produces a similar error:

# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be REMOVED:
  linux-image-4.15.0-22-generic
The following packages will be upgraded:
  libcephfs2 librados2 ssh-import-id
3 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/3,065 kB of archives.
After this operation, 8,281 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 149817 files and directories currently installed.)
Removing linux-image-4.15.0-22-generic (4.15.0-22.24) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-4.15.0-22-generic
/etc/kernel/postrm.d/x-grub-legacy-ec2:
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ...

Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub-legacy-ec2: line 1101: read: 
read error: 0: Bad file descriptor
run-parts: /etc/kernel/postrm.d/x-grub-legacy-ec2 exited with return code 1
dpkg: error processing package linux-image-4.15.0-22-generic (--remove):
 installed linux-image-4.15.0-22-generic package post-removal script 
subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-4.15.0-22-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Thanks to all for the responses. Followed suggestions below. Can't seem to clean it up via apt / dpkg. Here is output:

# sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-22-generic
Found initrd image: /boot/initrd.img-4.15.0-22-generic
Found linux image: /boot/vmlinuz-4.15.0-20-generic
Found initrd image: /boot/initrd.img-4.15.0-20-generic
done

# sudo dpkg --purge linux-image-4.15.0-22-generic
dpkg: dependency problems prevent removal of linux-image-4.15.0-22-generic:
 linux-image-generic depends on linux-image-4.15.0-22-generic.
 linux-modules-extra-4.15.0-22-generic depends on linux-image-4.15.0-22-generic | linux-image-unsigned-4.15.0-22-generic; however:
  Package linux-image-4.15.0-22-generic is to be removed.
  Package linux-image-unsigned-4.15.0-22-generic is not installed.

dpkg: error processing package linux-image-4.15.0-22-generic (--purge): 

dependency problems - not removing Errors were encountered while processing: linux-image-4.15.0-22-generic

3
  • Have you made any changes to grub or its data files? May 27 '18 at 22:41
  • 1
    Welcome to Ask Ubuntu! Could you please try to remove the package individually with sudo dpkg --purge linux-image-4.15.0-22-generic. If that fails, could you please run sudo update-grub and try again? If that still fails please edit your question to include the output of both. Thanks. May 27 '18 at 22:53
  • Made no changes to grub prior to this problem, at least none that I am aware of. The server's purpose is primarily as a Samba server, and a hypervisor for other VMs, so the usual maintenance activity is simply applying updates.
    – SDT2000USA
    May 29 '18 at 14:26
14

I am still unclear on why I experienced this issue, but it seems a missing grub /boot/grub/menu.lst file was causing apt / dpkg updates to fail. So I created an empty file.

sudo touch /boot/grub/menu.lst
sudo update-grub2

All good. Then proceed with updating the system:

sudo apt update
sudo apt upgrade
sudo apt autoremove --purge

Along the way, there will be a warning that the current menu.lst file is different than the package maintainer's version. Select the option to install the package maintainer's version, and then the rest of the update and cleanup completes successfully. Will see how the next kernel upgrade goes, but problem is solved for now.

Thank you to all who contributed suggestions and help!

3
  • You should accept your own answer
    – Oussema
    Jun 5 '18 at 4:27
  • I was trying to convert the working OpenVPN server VM to use XFS file systems instead of ext4. After formatting and copying data back to the XFS volumes, grub was hosed. I'm now seeing this same error when I try to install packages.
    – user38537
    Mar 7 '19 at 20:59
  • Thank you so much. I was downgrading from 19.* to 18.04 after facing many challenges in installing R Studio etc. I was very worried when I hit the grub error. Your suggestions worked like charm Apr 21 '20 at 7:17
1

I know this should be a comment but I don't have enough reputation.
But I want to let you know I had a similar problem yesterday.
If this answer doesn't work for you, you can contact @videonauth . He's the super nice guy who helped me with this issue.
I will copypaste from his answer the part that will hopefully help you:

First remove the removable packages after having run an update to get the proper package archives updated:

sudo apt update
sudo apt autoremove --purge

This should remove all removable packages so far except the one which managed to get messed up which we can then remove then by installing it and then removing it properly:

cd /var/cache/apt/archives
sudo dpkg -i linux-modules-4.15.0-22-generic_4.15.0-22.24_amd64.deb
sudo dpkg -r linux-modules-4.15.0-22-generic_4.15.0-22.24_amd64.deb  

(Note from Oussema: ^This command was used based on the fact that my system's architecture is amd64. You can see yours using the command uname -a
"i386", "i486", "i586" and "i686" and "athlon" all mean 32 bit. "x86_64" means 64 bit (Opteron or Athlon-64). "i686-64" means 32-bit operation with 64-bit address space (Intel 686 with the new memory mechanism). )

Now cleaning up the archives by running:

sudo apt clean

And now we can reinstall the packages properly after having run an complete update process:

sudo apt update
sudo apt dist-upgrade

with the following line:

sudo apt install --reinstall linux-generic
1
  • Thanks for the suggestions. Unfortunately, the apt commands all fail similarly to the orgiginal error.
    – SDT2000USA
    May 29 '18 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.