1

When I run sudo apt update in Ubuntu 18.10 I get this error message:

E: flAbsPath on /var/lib/dpkg/status failed - realpath (2: No such file or directory)
E: Could not open file  - open (2: No such file or directory)
E: Problem opening 
E: The package lists or status file could not be parsed or opened.

After running sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status it's showing this error message:

cp: cannot stat '/var/lib/dpkg/status-old': No such file or directory 
5

3 Answers 3

2

Run the following commands:

sudo mkdir -p /var/lib/dpkg/{alternatives,info,parts,triggers,updates}
sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
sudo apt-get download dpkg
sudo dpkg -i dpkg*.deb
sudo apt-get download base-files
sudo dpkg -i base-files*.deb
sudo apt-get update
sudo apt-get check
1

Restore the /var/lib/dpkg/status file from its backup file (/var/lib/dpkg/status-old). Open the terminal and type:

sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status  

Then run sudo apt update again.


If that doesn't work run the following commands:

sudo touch /var/lib/dpkg/status  
sudo apt update && sudo apt upgrade
sudo reboot  
sudo apt full-upgrade
1
  • After running this command its showing this error. cp: cannot stat '/var/lib/dpkg/status-old': No such file or directory Dec 18, 2018 at 12:47
0

My /var/lib/dpkg/status file got deleted and according to apt I had no packages installed, as it determines them from the status file. I used the following method to regenerate the /var/lib/dpkg/status file. The method worked very fine for me in Kali GNU/Linux, which is Debian-based.

NOTE:

  • This method assumes that all installed packages have created entries in the /usr/share/doc directory.

  • This method starts from an empty /var/lib/dpkg/status file.

  • This method may not work if you have more than 1 repository providing the same package. If you do have more than 1 repository providing the same package, temporarily disable the subsidiary repo, then delete the package cache lists for the repo in /var/lib/apt/lists/.

  1. Delete the current status and status-old files. Make a backup of the files before deletion incase you get errors.

    mkdir ~/dpkg-status-backup
    cp /var/lib/dpkg/{status,status-old} ~/dpkg-status-backup
    rm /var/lib/dpkg/{status,status-old}
    
  2. Get list of all packages installed, one package per line.  Note: it's 1 (one) not l (lower-case L).

    ls -1 /usr/share/doc > installed-packages.list
    
  3. Rewrite the packages list into one line.

    tr '\n' ' ' < installed-packages.list > installed-packages-one-line.list
    
  4. Create an empty status file to enable apt-cache to run.

    touch /var/lib/dpkg/status
    
  5. Generate package records using apt-cache.

    cat installed-packages-one-line.list | xargs apt-cache show > raw-status-file
    
  6. The raw-status-file may contain Status: fields for some packages. Delete them to avoid duplication.

    sed -i '/^Status:/d' raw-status-file
    
  7. Add the Status: field for every package to indicate to apt & dpkg that they're installed.

    sed -i 's/^Package:.*/&\nStatus: install ok installed/' raw-status-file
    
  8. Remove fields unwanted by dpkg in status file: SHA1:, SHA256:, MD5sum:, Description-md5:, Size: & Filename: .

    sed -i '/^MD5sum:/d' raw-status-file
    sed -i '/^SHA1:/d' raw-status-file
    sed -i '/^SHA256:/d' raw-status-file
    sed -i '/^Size:/d' raw-status-file
    sed -i '/^Filename:/d' raw-status-file
    sed -i '/^Description-md5:/d' raw-status-file
    
  9. The resultant raw-status-file after running the above commands is now the actual dpkg status file.

    mv raw-status-file status
    
  10. Copy the status file to /var/lib/dpkg/ as status and status-old.

    cp status /var/lib/dpkg/status
    cp status /var/lib/dpkg/status-old
    
  11. Now run dpkg to validate your new status file. If you get errors, take hints from dpkg's error report, & solve accordingly. If you get no errors, then the status file has the correct syntax.

    dpkg --get-selections
    
  12. Re-enable the disabled repos then run apt to update package cache lists to prevent the error packages have unmet dependencies.

    apt update
    
  13. If you run into packages have unmet dependencies error in apt, then make sure you've enabled the subsidiary repos that provide the dependencies, then run aptitude. I prefer aptitude because it's better at solving package installation errors.

    aptitude full-upgrade
    

If you get no errors/your errors have been resolved from apt or dpkg, and get "PACKAGE is already the newest version..." when you try to install a program you're sure is already installed, such as coreutils, then you've successfully regenerated the dpkg status file.

Clean-up the temp files created and the backup.

rm installed-packages.list installed-packages-one-line.list status
rm -r ~/dpkg-status-backup
4
  • Could you summarize your solution in a nutshell? So that your answer remains usable even if your link disappears for whatever reason. Jul 15 at 7:27
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Pilot6
    Jul 16 at 14:26
  • @Pilot6 should I copy over the whole answer from the other stackexchange community? 'Cause summarizing the answer would remove important details.
    – w0nd3r365
    Jul 16 at 16:44
  • It's up to you. But a link answer is not an answer.
    – Pilot6
    Jul 16 at 16:55

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.