3

I have problems with apt:

E: Unable to lock the administration directory /var/lib/dpkg/lock
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? 

I followed the guide in the answer to this question. Unfortunately, it did not fix my problem. When I run sudo dpkg --configure -a this is the output:

Setting up linux-image-4.15.0-36-generic (4.15.0-36.39) ...
Processing triggers for linux-image-4.15.0-36-generic (4.15.0-36.39) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-36-generic

The process is stuck on the last line even after hours and does not continue.

When I run ps aux | grep dpkg while the process is stuck:

root     28722  0.0  0.0  20248  5616 pts/8    Ss+  Oct05   0:00 /usr/bin/dpkg --status-fd 25 --configure --pending
root     28730  0.0  0.0   4628   812 pts/8    S+   Oct05   0:00 /bin/sh /var/lib/dpkg/info/linux-image-4.15.0-36-generic.postinst triggered linux-update-4.15.0-36-generic

How can I fix this problem without reinstalling ubuntu?

Bobface
  • 161

1 Answers1

2
  1. Immediately after the motherboard / computer manufacturer logo splash screen appears when the computer is booting, with BIOS, quickly press and hold the Shift key, which will bring up the GNU GRUB menu. (If you see the Ubuntu logo, you've missed the point where you can enter the GRUB menu.) With UEFI press (perhaps several times) the Esc key to get to the GRUB menu. Sometimes the manufacturer's splash screen is a part of the Windows bootloader, so when you power up the machine it goes straight to the GRUB screen, and then pressing Shift is unnecessary.

  2. From the GRUB screen select Advanced options for Ubuntu and press Enter.

enter image description here

  1. A new purple screen will appear showing a list of Linux kernels, which includes options of booting the kernels normally or in recovery mode.

enter image description here

  1. Use the arrow keys on the keyboard to select an earlier kernel version and press Enter to boot with the selected kernel.

Open a text-only virtual console by pressing the keyboard combination Ctrl+Alt+F3.

  1. At the login: prompt type your username and press Enter.

  2. At the Password: prompt type your user password and press Enter. After you have logged in, you can run commands from the virtual console.

  3. Run the following commands to remove your /var/lib/dpkg/lock file and force package reconfiguration.

     sudo apt install --reinstall linux-image-generic=4.15.0.36.39  
     sudo rm /var/lib/dpkg/lock
     sudo dpkg --configure -a
    
  4. To bring up the normal Ubuntu login screen run this command:

     sudo systemctl start graphical.target
    

If this doesn't work bring up the virtual console again and run the following commands in Step 3 of the preceding 4 steps:

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock  
karel
  • 114,770
  • 1
    Thank you very much for your detailed answer! Unfortunately, I cannot try it out right now. I will do it on monday and report back :) – Bobface Oct 05 '18 at 19:24
  • 1
    I added some more info to the question. Does this change anything? And should I boot in recovery mode or not? – Bobface Oct 06 '18 at 09:35
  • Don't boot in recovery mode, boot with a normal (non-recovery) option. The results of apt policy linux-image-generic on my computer show that version 4.15.0.36.38 is installed, but the results of uname -a show that version 4.15.0.36.39 is installed, the same version that you have installed. Maybe linux-image-generic needs to be reinstalled, so I edited my answer. – karel Oct 06 '18 at 09:52