What command is run when the dpkg option is selected in recovery mode?
This feature is provided by the friendly recovery menu, and in particular its dpkg
plugin (which adds a menu entry titled “Repair broken packages”, translated appropriately in whatever language the user configured the system to use).
This plugin uses two different approaches to repair broken packages:
-
if
dist-upgrader
is available, it uses that to repair the system, by runningenv RELEASE_UPGRADER_NO_SCREEN=1 python3 /usr/lib/python3/dist-packages/DistUpgrade/dist-upgrade.py \ --partial --frontend DistUpgradeViewText \ --datadir /usr/share/ubuntu-release-upgrader
-
otherwise, it runs
dpkg --configure -a apt-get update apt-get install -f apt-get dist-upgrade
To achieve the same effect as the menu selection, you should try the first command using dist-upgrader
, and if that fails because it doesn’t exist, run the four commands starting with dpkg --configure -a
.
Note that both these options don’t just repair broken packages, they upgrade the system to the latest versions of the packages available in whatever release is installed. (This is necessary because repairing the broken packages might involve installing missing packages, and that can only be done using the current versions of the packages from the configured repositories.)
Related videos on Youtube
![Jacob Horbulyk](https://i.stack.imgur.com/XQIUk.jpg?s=256&g=1)
Jacob Horbulyk
Updated on September 18, 2022Comments
-
Jacob Horbulyk almost 2 years
I recently ran into the following situation:
- I could not boot my computer normally. (I was shown a blinking cursor after the boot-loader and Ubunutu load screen but before the login page while never reaching the login page.)
- I was able to enter recovery mode. If I fully continued the boot, I could get to a terminal where I could add/remove any packages with apt-get.
- Before fully booting into recovery mode, I was shown a menu where one of the options was
dpkg
which would repair installed packages. If I selected this option, the system calculated that a repair could be made if I reinstalled 103 packages. However saying yes to that operation ran into network issues when trying to download the packages for re-installation. - I was able to resolve the situation by looking at the list of packages being offered to repair and then by using the "throw a dart and pray" strategy, I opted to run
sudo apt-get install --reinstall ubuntu-gnome-desktop
from the prompt offered after fully entering recovery mode. This ended up triggering a re-install of 103 packages. Once this was done, I could boot Ubuntu normally.
The question I have is:
What command could I have entered at the command prompt when booted which would have performed the same operation as the
dpkg
menu option?