在 Ubuntu 發生 dpkg: error processing archive 的問題該如何處理?

發生 dpkg: error processing archive 的問題

在我使用 apt install 指令時,遇到了 dpkg: error processing archive 的問題。

下面是錯誤訊息:

$ sudo apt install lm-sensors
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 nvidia-dkms-535 : Depends: nvidia-kernel-common-535 (= 535.54.03-0ubuntu1) but 535.54.03-0ubuntu0.22.04.1 is to be installed
 nvidia-driver-535 : Depends: nvidia-compute-utils-535 (= 535.54.03-0ubuntu1) but 535.54.03-0ubuntu0.22.04.1 is to be installed
                     Recommends: libnvidia-compute-535:i386 (= 535.54.03-0ubuntu1)
                     Recommends: libnvidia-decode-535:i386 (= 535.54.03-0ubuntu1)
Preparing to unpack .../nvidia-kernel-common-535_535.54.03-0ubuntu1_amd64.deb ...
Unpacking nvidia-kernel-common-535 (535.54.03-0ubuntu1) over (535.54.03-0ubuntu0.22.04.1) ...
dpkg: error processing archive /var/cache/apt/archives/nvidia-kernel-common-535_535.54.03-0ubuntu1_amd64.deb (--unpack):
 trying to overwrite '/lib/firmware/nvidia/535.54.03/gsp_ga10x.bin', which is also in package nvidia-firmware-535-535.54.03 535.54.03-0ubuntu0.22.04.1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Could not execute systemctl:  at /usr/bin/deb-systemd-invoke line 142.
Preparing to unpack .../nvidia-compute-utils-535_535.54.03-0ubuntu1_amd64.deb ...
Unpacking nvidia-compute-utils-535 (535.54.03-0ubuntu1) over (535.54.03-0ubuntu0.22.04.1) ...
dpkg: error processing archive /var/cache/apt/archives/nvidia-compute-utils-535_535.54.03-0ubuntu1_amd64.deb (--unpack):
 trying to overwrite '/usr/bin/nvidia-powerd', which is also in package nvidia-kernel-common-535 535.54.03-0ubuntu0.22.04.1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
nvidia-persistenced.service is a disabled or a static unit not running, not starting it.
nvidia-persistenced.service is a disabled or a static unit not running, not starting it.
Errors were encountered while processing:
 /var/cache/apt/archives/nvidia-kernel-common-535_535.54.03-0ubuntu1_amd64.deb
 /var/cache/apt/archives/nvidia-compute-utils-535_535.54.03-0ubuntu1_amd64.deb
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)

從上述訊息中,我們可以看到問題的主要原因是 NVIDIA kernel 的相依性問題。

使用 dpkg -i –force-overwrite 修復錯誤

雖然 apt 工具本身可以修復這個問題,但在這個情況下出現了 dpkg: error processing archive,阻止了修復的過程。那麼該如何解決呢?實際上,只需使用 dpkg -i –force-overwrite 指令即可解決。

下面是解決步驟:

$ sudo dpkg -i --force-overwrite /var/cache/apt/archives/nvidia-kernel-common-535_535.54.03-0ubuntu1_amd64.deb
(Reading database ... 106087 files and directories currently installed.)
Preparing to unpack .../nvidia-kernel-common-535_535.54.03-0ubuntu1_amd64.deb ...
Unpacking nvidia-kernel-common-535 (535.54.03-0ubuntu1) over (535.54.03-0ubuntu0.22.04.1) ...
dpkg: warning: overriding problem because --force enabled:
dpkg: warning: trying to overwrite '/lib/firmware/nvidia/535.54.03/gsp_ga10x.bin', which is also in package nvidia-firmware-535-535.54.03 535.54.03-0ubuntu0.22.04.1
dpkg: warning: overriding problem because --force enabled:
dpkg: warning: trying to overwrite '/lib/firmware/nvidia/535.54.03/gsp_tu10x.bin', which is also in package nvidia-firmware-535-535.54.03 535.54.03-0ubuntu0.22.04.1
nvidia-peermem.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.15.0-76-generic/updates/dkms/

nvidia-uvm.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.15.0-76-generic/updates/dkms/

depmod...
Setting up nvidia-driver-535 (535.54.03-0ubuntu1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for initramfs-tools (0.140ubuntu13.2) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-76-generic
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.
  nvidia-firmware-535-535.54.03
Use 'sudo apt autoremove' to remove it.
Suggested packages:
  fancontrol read-edid i2c-tools
The following NEW packages will be installed:
  lm-sensors
0 upgraded, 1 newly installed, 0 to remove and 6 not upgraded.
Need to get 91.0 kB of archives.
After this operation, 404 kB of additional disk space will be used.
Get:1 http://tw.archive.ubuntu.com/ubuntu jammy/universe amd64 lm-sensors amd64 1:3.6.0-7ubuntu1 [91.0 kB]
Fetched 91.0 kB in 0s (2,502 kB/s)
Selecting previously unselected package lm-sensors.
(Reading database ... 106082 files and directories currently installed.)
Preparing to unpack .../lm-sensors_1%3a3.6.0-7ubuntu1_amd64.deb ...
Unpacking lm-sensors (1:3.6.0-7ubuntu1) ...
Setting up lm-sensors (1:3.6.0-7ubuntu1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/lm-sensors.service → /lib/systemd/system/lm-sensors.service.
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

總結

總結而言,這篇文章與前一篇相似,使用 DKMS 來解決底層問題。同樣地,該方法能夠幫助您解決 dpkg: error processing archive 的問題。