1

The situation is whenever I boot up my Ubuntu OS laptop if I run apt-get command is always said:

Could not get lock /var/lib/apt/lists/lock . It is held by process xxxx

I try to solve the problem by killing that process (sudo kill -9 ) then everything fine. But if I boot up the problem appears again.

Can anyone have any suggestions for my situation?

Thank you very much.

Edit:

When I run sudo apt-get update and error was:

 Reading package lists... Done
 E: Could not get lock /var/lib/apt/lists/lock. It is held by process 1791 (apt-get)
 N: Be aware that removing the lock file is not a solution and may break your system.
 E: Unable to lock directory /var/lib/apt/lists/

The process id changes every time I boot or close the terminal.

3
  • @user535733 thank you, I have edited my question.
    – Q.H.Chu
    Oct 7, 2020 at 2:29
  • Check ps -e. Is apt-get running?
    – user535733
    Oct 7, 2020 at 2:39
  • Just wait a few minutes until the process finishes and releases the lock.
    – Soren A
    Oct 7, 2020 at 4:34

1 Answer 1

1

That's being caused by the unattended-upgrades... it is not a "problem" per se.... I would not be "killing it".. no telling where it was in the process when you did that.... you're basically giving it a power outage during an update. With that said, if you have been doing that all along, this is probably self-inflicted because the updates could be just never finishing...and compounding.

But, if you want to try to make it wait until some other time, like never directly after you boot... You can look into the parameters that you can add to the configs that can vary the timing of the updates.

I have not worked with these myself so I haven't seen them function, and judging by the mixed results across the internet, they may have some nuances, so you'll have to experiment.

Reference man systemd.timer for the attributes.

I'd start with the OnBootSec setting, in from what I can tell, the daily timer and the daily upgrade timer.

the scheduling of those is visible in:
/lib/systemd/system/apt-daily.timer
/lib/systemd/system/apt-daily-upgrade.timer

Apparently you don't edit those, you use:
sudo systemctl edit apt-daily.timer
sudo systemctl edit apt-daily-upgrade.timer
... and an /etc/systemd/system/apt-daily.XXXXX.d/override.conf file is created where you can customize timer settings.

I would try testing with something like

[Timer]
OnBootSec=60min
RandomizedDelaySec=2h

According to the man page, this should add an additional random delay of up to 2 hours before it starts, 60 minutes after boot... There are a lot of timing settings to play with.

Save the edit to the override file(s).
reboot the machine or try restarting the services
sudo systemctl daemon-reload
sudo systemctl restart apt-daily.service
sudo systemctl restart apt-daily-upgrade.service

Reboot is probably better to test the behavior.

Or....do nothing and just wait until the updates finish.

Not the answer you're looking for? Browse other questions tagged .