You are not logged in.

#1 2022-11-06 04:40:08

zggzcgy
Member
From: CN
Registered: 2022-08-27
Posts: 9

[SOLVED] Power loss when updating the system, how to recover

Today was not a good day, my laptop battery failed, causing me to be interrupted while updating the system and unable to boot the system properly.

I accessed the file system via a USB image and found that most of the dynamically libraries were corrupted, making almost all commands unusable.

[root@usb /]# arch-chroot /mnt/
[root@usb /]# ldconfig 
ldconfig: File /usr/lib32/libssh2.so.1.0.1 is empty, not checked.
ldconfig: File /usr/lib32/libkrb5support.so.0.1 is empty, not checked.
ldconfig: File /usr/lib32/libssh2.so.1 is empty, not checked.
ldconfig: File /usr/lib32/libdrm_radeon.so.1.0.1 is empty, not checked.
ldconfig: File /usr/lib32/libssh2.so is empty, not checked.
ldconfig: File /usr/lib32/libkrb5support.so.0 is empty, not checked.
ldconfig: File /usr/lib32/libverto.so.0 is empty, not checked.
ldconfig: File /usr/lib32/libverto.so.0.0 is empty, not checked.
ldconfig: File /usr/lib32/libcurl.so.4.8.0 is empty, not checked.
ldconfig: File /usr/lib32/libssl.so.3 is empty, not checked.
ldconfig: File /usr/lib32/libldap.so.2 is empty, not checked.

        ……plenty……

ldconfig: File /usr/lib/libkmod.so.2 is empty, not checked.
ldconfig: File /usr/lib/libkmod.so.2.4.0 is empty, not checked.
[root@usb /]# pwd
/
[root@usb /]# ls /
[root@usb /]# ldd /usr/bin/ls
	not a dynamic executable
[root@usb /]# pacman -h

I removed db.lck, tried to use the pacstrap script to rebuilt the base package, Linux kernel.

[root@usb /]# exit
exit
[root@usb /]# rm /mnt/var/lib/pacman/db.lck
[root@usb /]# pacstrap -K /mnt base linux linux-firmware
==> Creating install root at /mnt/
==> Installing packages to /mnt/
:: Synchronizing package databases...
 core downloading...
 extra downloading...
 community downloading...
resolving dependencies...
looking for conflicting packages...

Packages (3) base-3-1  linux-6.0.7.arch1-1  linux-firmware-20220913.f09bebf-1
Total Installed Size:  326.87 MiB
Net Upgrade Size:      163.59 MiB

:: Proceed with installation? [Y/n] 
checking keyring...
checking package integrity...
loading package files...
checking for file conflicts...
error: failed to commit transaction (conflicting files)
linux: /mnt/usr/lib/modules/6.0.7-arch1-1/kernel/arch/x86/crypto/aegis128-aesni.ko.zst exists in filesystem
linux: /mnt/usr/lib/modules/6.0.7-arch1-1/kernel/arch/x86/crypto/aesni-intel.ko.zst exists in filesystem
        ……plenty……
[root@usb /]# pacstrap --help
usage: pacstrap [options] root [packages...]

  Options:
    -C <config>    Use an alternate config file for pacman
    -c             Use the package cache on the host, rather than the target
    -G             Avoid copying the host's pacman keyring to the target
    -i             Prompt for package confirmation when needed (run interactively)
    -K             Initialize an empty pacman keyring in the target (implies '-G')
    -M             Avoid copying the host's mirrorlist to the target
    -N             Run in unshare mode as a regular user
    -U             Use pacman -U to install packages

    -h             Print this help message

pacstrap installs packages to the specified new root directory. If no packages
are given, pacstrap defaults to the "base" group.

How can I save my system library?

Last edited by zggzcgy (2022-11-06 08:38:19)

Offline

#2 2022-11-06 05:03:03

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,156

Re: [SOLVED] Power loss when updating the system, how to recover

pacstrap is designed to install a new system. I would try

pacman --sysroot /mnt

instead.

If that doesn't work, I would look at the tools provided by pacutils. Here's an example from pacrepairdb's man page:

EXAMPLES
       Find and reinstall broken packages:

       

paccheck --list-broken --files --file-properties --db-files --require-mtree | pacrepairdb

But that is obviously designed to be used from within the system rather than from outside so you'd need to adapt it e.g. with --sysroot /mnt again.

Last edited by cfr (2022-11-06 05:07:39)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2022-11-06 12:58:26

zggzcgy
Member
From: CN
Registered: 2022-08-27
Posts: 9

Re: [SOLVED] Power loss when updating the system, how to recover

cfr wrote:
pacman --sysroot /mnt

smile Thank you very much for the idea!i successfully solved this problem, the approximate steps are as follows:

  1. Find and visibly corrupt files.

    find /mnt/usr/lib /mnt/var/cache/pacman/pkg -empty -type f -delete
  2. Try to install the base package.

    pacman --sysroot /mnt -S base
  3. Reinstall all applications.

    pacman --sysroot /mnt -Qqn | pacman --sysroot /mnt -S --overwrite=* -

Fix the following issues encountered in the error:

  1. error: could not open file: /etc/mtab: No such file or directory
    An error is reported when installing the base package

    pacman --sysroot /mnt -S base

    error: could not open file: /etc/mtab: No such file or directory
    This is because pacman is based on the /mnt environment, so you also need to execute the following command. reference Using chroot

    mount -t proc proc /mnt/proc; mount --rbind /sys /mnt/sys; mount --rbind /dev /mnt/dev
  2. error: GPGME error: Invalid crypto engine
    An error is reported when installing any package

    pacman --sysroot /mnt -S base

    error: GPGME error: Invalid crypto engine:: File /var/cache/pacman/pkg/base-3-1-any.pkg.tar.zst is corrupted (invalid or corrupted package (PGP signature)).
    This is because the files are lost when the power is lost, and you can remove them with the following command

    find /mnt/usr/lib /mnt/var/cache/pacman/pkg -empty -type f -delete
  3. error: failed retrieving file 'core.db' Could not resolve host: mirrors.xxx.org
    Copy the rescue system file to /mnt

    cp {,/mnt}/etc/resolv.conf
  4. error: failed to commit transaction
    pkgname: /path/to/file exists in filesystem
    Errors occurred, no packages were upgraded.

    This is because the /mnt/var/lib/pacman/local/pkgname/files  file is corrupt and may need to overwrite the installation.reference:Avoid certain pacman commands and [SOLVED] GPGME error: Invalid crypto engine

    pacman --sysroot /mnt -S --overwrite=* pkgname
  5. UEFI variables not supported on this machine
    reference Using chroot

    mount --rbind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars

If you want to repair broken packages one by one. paccheck can be performed externally to detect breakage

paccheck --sysroot=/mnt --list-broken --files --file-properties --db-files --require-mtree 2>/dev/null | pacman --sysroot /mnt -S -

If you want to rebuild it all, use the following command. reference:Reinstalling all packages

pacman --sysroot /mnt -Qqn | pacman --sysroot /mnt -S -

NOTE: Packages on AUR cannot be rebuilt using the archlinux official source and may need to be manually excluded

Offline

Board footer

Powered by FluxBB