7

when i tried to use command- sudo apt install libudev-devit give me this error

Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
 installed systemd package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 systemd
E: Sub-process /usr/bin/dpkg returned an error code (1)

what to do pls tell me

4
  • is that exactly the output, nothing at all more than that? try sudo apt update Commented Aug 14, 2023 at 11:46
  • What distribution and release are you running? Clearly it's Debian-based, but is it Ubuntu? 20.04, 22.04, an interim release? Also, is Systemd running? Commented Aug 15, 2023 at 11:46
  • Since I just got this exact error while trying to upgrade my WSL Kali, my guess is that.
    – Panki
    Commented Aug 15, 2023 at 15:56
  • @Panki - There is no guarantee you actually have the same problem as the author. Best to allow the author to clarify their question by editing.
    – Ramhound
    Commented Aug 15, 2023 at 20:05

3 Answers 3

21

I came across this thing that i tried and it worked! Might work for you aswell here: https://databasefaqs.com/sub-process-usr-bin-dpkg-returned-an-error-code-1/

sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_silent

sudo mkdir /var/lib/dpkg/info

sudo apt-get update

sudo apt-get -f install

sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_silent

sudo rm -rf /var/lib/dpkg/info

sudo mv /var/lib/dpkg/info_silent /var/lib/dpkg/info

sudo apt-get update

sudo apt-get upgrade

Done!

4
  • Welcome to Super User! As a heads-up, I know this is a bit tricky to navigate - You properly edited your other answer that a Mod deleted. But rather than posting a new one, you really should have Flagged it for the Moderator to undelete. Commented Aug 17, 2023 at 15:58
  • The commands above worked for me, when my first attempt for a sudo apt-get upgrade failed on a fresh Ubuntu-24.04 in WSL 2 (Windows 10 Home 22H2, 19045.4412).
    – Yaniv
    Commented Jun 10 at 22:09
  • Like @Yaniv mentioned, error during fresh Ubuntu-24.04 WSL2 installed. Commands as listed work like a charm.
    – Sam
    Commented Jun 30 at 0:45
  • Saved me so many tears. Thanks a lot!. Worked fine for my WSL1 Ubuntu 24.04 instance.
    – LA.27
    Commented Sep 30 at 9:00
5

systemd.postinsts script calls systemd-sysusers, and it in turn tries to get a lock with fcntl F_OFD_SETLKW which fails.

strace output of sudo systemd-sysusers:

openat(AT_FDCWD, "/etc/.pwd.lock", O_WRONLY|O_CREAT|O_NOCTTY|O_NOFOLLOW|O_CLOEXEC, 0600) = 3
fcntl(3, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = -1 EINVAL (Invalid argument)

WSL1 does not support these kinds of locks: https://github.com/Microsoft/WSL/issues/1927

That ticket is about F_SETLK but it's likely the same situation with F_OFD_SETLKW.

Although that ticket is closed it's labeled fixed-in-wsl2 meaning there are no plans to fix it in WSL1.

5

Landed here looking for a WSL-specific problem. I found some other people's solutions here: https://github.com/microsoft/WSL/issues/10397

The gist of it is:

$ sudo mv /var/lib/dpkg/info/systemd-timesyncd.postinst /tmp/
$ sudo mv /var/lib/dpkg/info/systemd.postinst /tmp/
$ sudo dpkg --configure -a

That should allow dpkg to finish "configuring" systemd (because we removed the problematic scripts)

After that you can put the scripts back and continue apt upgrade

$ sudo mv /tmp/systemd-timesyncd.postinst /var/lib/dpkg/info/
$ sudo mv /tmp/systemd.postinst /var/lib/dpkg/info/
$ sudo apt upgrade
1
  • 2
    For anyone else coming here, I've also seen errors on upgrades to the following packages on Debian sid: udev, cron-daemon-common, cron
    – maxprehl
    Commented Oct 10, 2023 at 8:28

You must log in to answer this question.

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