Having trouble removing Virtualbox

Hello, Zorin Forum

I'm using Zorin OS 17.3. Installed Virtualbox through the Zorin repository. I get a critical error when trying to run a vm. Virtualbox used to work fine on Zorin 16. I uninstalled it in the Software manager. I then downloaded an older version from Virtualbox' own website and tried to install that. But when the deb file opens in Software manager, the only option there is to uninstall Virtualbox. When I choose that, I get an error message: "Unable to remove Oracle Virtualbox ". When I click the “More information” button, it says: "No packages to remove". I've tried using the terminal, tried apt remove, apt purge and it says: "virtualbox is not installed". I've tried apt install and apt reinstall, in both cases it says "Running VMs found. Virtualbox is currently running. Please close it and try again. etc." But when I search for virtualbox, I don't find it anywhere. I'm pretty sure it's gone. I've also checked all the processes that are running, it's not there. How can it still be running and why can't I get rid of this dog dawn thing?

Maybe the virtual machines are still there? I have read that they are not removed when Oracle VirtualBox is uninstalled.
Unfortunately, I don't know my way around that well. I only found this thread, maybe it will help you.

Try simply restarting the computer. Whatever files are created when running a VM should be temporary and shouldn't survive a reboot. Then, uninstall by running:

sudo apt remove virtualbox

When that's done, or if it returns a message saying that it's already uninstalled, run:

sudo apt autoremove

This will clean left over files that are no longer in use. You should be clear now to try to re-install it.

I did a reboot and then apt remove virtualbox: "Package 'virtualbox' is not installed, so not removed". Then apt autoremove: "0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded". Virtualbox is still showing up in the Software manager, but is nowhere to be found on the system. When I try to uninstall it I get the same error messages again. If I try to reinstall it again I also get the same error message.

And to be clear, Virtualbox is NOT running and no VMs are running.

Ok, so let's work it out manually then. What's the output of:

sudo find / -type d -iname "*virtual*box*" 2>/dev/null

This should list all the locations named with some combination of virtual box. On a fresh installation of VirtualBox this what it looks like to me:

Before doing anything else, let's confirm what it does look like in your case.

I get dpkg errors when trying to install Virtualbox. Here’s the output from the terminal:

Sudo apt install virtualbox

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libsdl-ttf2.0-0
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
dctrl-tools dkms libgsoap-2.8.117 liblzf1 libqt5opengl5 virtualbox-dkms
virtualbox-qt
Suggested packages:
debtags menu vde2 virtualbox-guest-additions-iso
The following packages will be REMOVED:
virtualbox-7.1
The following NEW packages will be installed:
dctrl-tools dkms libgsoap-2.8.117 liblzf1 libqt5opengl5 virtualbox
virtualbox-dkms virtualbox-qt
0 upgraded, 8 newly installed, 1 to remove and 2 not upgraded.
Need to get 0 B/46.7 MB of archives.
After this operation, 97.4 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 321950 files and directories currently installed.)
Removing virtualbox-7.1 (7.1.10-169112~Ubuntu~jammy) ...
dpkg: error processing package virtualbox-7.1 (--remove):
installed virtualbox-7.1 package pre-removal script subprocess returned error exit st
atus 1
dpkg: too many errors, stopping
/var/lib/dpkg/info/virtualbox-7.1.postinst: 105: /usr/lib/virtualbox/prerm-common.sh:
not found
/var/lib/dpkg/info/virtualbox-7.1.postinst: 106: /usr/lib/virtualbox/postinst-common.s
h: not found
Errors were encountered while processing:
virtualbox-7.1
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

This is beyond my capabilities. I don’t know how to fix this issue.

/home/gonzo/.config/VirtualBox
/root/.config/VirtualBox
/usr/share/doc/virtualbox-7.1

That's really odd... not only there are few locations left but one of the is in the root user's home directory.

If that's all it found you can run:

sudo find / -type d -iname "*virtual*box*" -delete 2>/dev/null

This will delete them right away. After that, let's see if it still finds anything with:

sudo find / -type d -iname "*v*box*" 2>/dev/null

This searches for even more directories named with any combination of VirtualBox, as sometimes there are directories named "vbox" and things like that. If there are none, restart and try again. If there are, please post the output here to make sure what it found.

/etc/vbox
/home/gonzo/.config/google-chrome/PrivacySandboxAttestationsPreloaded
/home/gonzo/.config/VirtualBox
/home/gonzo/.var/app/com.spotify.Client/cache/spotify/PrivacySandboxAttestationsPreloaded
/root/.config/VirtualBox
/opt/google/chrome/PrivacySandboxAttestationsPreloaded
/opt/brave.com/brave/PrivacySandboxAttestationsPreloaded
/usr/local/lib/python3.10/dist-packages/vboxapi
/usr/lib/modules/6.8.0-59-generic/kernel/drivers/virt/vboxguest
/usr/lib/modules/6.8.0-59-generic/kernel/drivers/gpu/drm/vboxvideo
/usr/lib/modules/6.8.0-59-generic/kernel/fs/vboxsf
/usr/lib/modules/6.8.0-60-generic/kernel/drivers/virt/vboxguest
/usr/lib/modules/6.8.0-60-generic/kernel/drivers/gpu/drm/vboxvideo
/usr/lib/modules/6.8.0-60-generic/kernel/fs/vboxsf
/usr/share/doc/virtualbox-7.1
/usr/src/linux-hwe-6.8-headers-6.8.0-60/drivers/virt/vboxguest
/usr/src/linux-hwe-6.8-headers-6.8.0-60/drivers/gpu/drm/vboxvideo
/usr/src/linux-hwe-6.8-headers-6.8.0-60/fs/vboxsf
/usr/src/linux-hwe-6.8-headers-6.8.0-59/drivers/virt/vboxguest
/usr/src/linux-hwe-6.8-headers-6.8.0-59/drivers/gpu/drm/vboxvideo
/usr/src/linux-hwe-6.8-headers-6.8.0-59/fs/vboxsf
/usr/src/linux-headers-5.15.0-141/drivers/virt/vboxguest
/usr/src/linux-headers-5.15.0-141/drivers/gpu/drm/vboxvideo
/usr/src/linux-headers-5.15.0-141/fs/vboxsf

Let's try this:

sudo systemctl status virtualbox.service

If the output says is active (in green):

sudo systemctl disable --now virtualbox.service

Restart, and try to uninstall.

sudo systemctl status virtualbox.service

Unit virtualbox.service could not be found.

If you look at the dpkg errors, do they provide any clues?

Tricky one :thinking:

I'm going to take a guess and go with one of the threads I found with a similar issue. Looking at the output on your previous reply, it seems the problem is that there's a pre-remove script missing and that causes the hold up. So, let's try to re-create them as empty files just so that they're found:

sudo mkdir -p /usr/lib/virtualbox

This will ensure the location exists since it's probably gone by now.

sudo touch /usr/lib/virtualbox/postinst-common.sh /usr/lib/virtualbox/prerm-common.sh

We'll also need executable permissions:

sudo chmod +x /usr/lib/virtualbox/postinst-common.sh /usr/lib/virtualbox/prerm-common.sh

Now, you can try to re-install as you did above:

sudo apt install virtualbox

Let's see what happens then.

That actually worked! Or so I thought ... Now things become interesting. Virtualbox installed, but when I open it and try to run a vm I've just created, this happens:

I must have really funked up things when I tried to install another version of Virtualbox. What's weird is that I'm not able to uninstall Virtualbox from the Software manager, I get the same error message:

I am able to uninstall Virtualbox using the terminal. but it still shows up like that in the software manager.

There were some errors during installation:

vboxdrv.ko:
Running module version sanity check.
Error! Module version 6.1.50_Ubuntu for vboxdrv.ko
is not newer than what is already found in kernel 6.8.0-60-generic (7.1.10).
You may override by specifying --force.

vboxnetadp.ko:
Running module version sanity check.
Error! Module version 6.1.50_Ubuntu for vboxnetadp.ko
is not newer than what is already found in kernel 6.8.0-60-generic (7.1.10).
You may override by specifying --force.

vboxnetflt.ko:
Running module version sanity check.
Error! Module version 6.1.50_Ubuntu for vboxnetflt.ko
is not newer than what is already found in kernel 6.8.0-60-generic (7.1.10).
You may override by specifying --force.

Here's the whole thing:

Sudo apt install virtualbox
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
dctrl-tools dkms libgsoap-2.8.117 liblzf1 libqt5opengl5 libsdl1.2debian
virtualbox-dkms virtualbox-qt
Suggested packages:
debtags menu vde2 virtualbox-guest-additions-iso
The following NEW packages will be installed:
dctrl-tools dkms libgsoap-2.8.117 liblzf1 libqt5opengl5 libsdl1.2debian
virtualbox virtualbox-dkms virtualbox-qt
0 upgraded, 9 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/46.9 MB of archives.
After this operation, 181 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package dctrl-tools.
(Reading database ... 321172 files and directories currently installed.)
Preparing to unpack .../0-dctrl-tools_2.24-3build2_amd64.deb ...
Unpacking dctrl-tools (2.24-3build2) ...
Selecting previously unselected package dkms.
Preparing to unpack .../1-dkms_2.8.7-2ubuntu2.2_all.deb ...
Unpacking dkms (2.8.7-2ubuntu2.2) ...
Selecting previously unselected package libgsoap-2.8.117:amd64.
Preparing to unpack .../2-libgsoap-2.8.117_2.8.117-2build1_amd64.deb ...
Unpacking libgsoap-2.8.117:amd64 (2.8.117-2build1) ...
Selecting previously unselected package liblzf1:amd64.
Preparing to unpack .../3-liblzf1_3.6-3_amd64.deb ...
Unpacking liblzf1:amd64 (3.6-3) ...
Selecting previously unselected package libqt5opengl5:amd64.
Preparing to unpack .../4-libqt5opengl5_5.15.3+dfsg-2ubuntu0.2_amd64.deb ...
Unpacking libqt5opengl5:amd64 (5.15.3+dfsg-2ubuntu0.2) ...
Selecting previously unselected package libsdl1.2debian:amd64.
Preparing to unpack .../5-libsdl1.2debian_1.2.15+dfsg2-6_amd64.deb ...
Unpacking libsdl1.2debian:amd64 (1.2.15+dfsg2-6) ...
Selecting previously unselected package virtualbox-dkms.
Preparing to unpack .../6-virtualbox-dkms_6.1.50-dfsg-1~ubuntu1.22.04.3_amd64.de
b ...
Unpacking virtualbox-dkms (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Selecting previously unselected package virtualbox.
Preparing to unpack .../7-virtualbox_6.1.50-dfsg-1~ubuntu1.22.04.3_amd64.deb ...
Unpacking virtualbox (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Selecting previously unselected package virtualbox-qt.
Preparing to unpack .../8-virtualbox-qt_6.1.50-dfsg-1~ubuntu1.22.04.3_amd64.deb
...
Unpacking virtualbox-qt (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Setting up libgsoap-2.8.117:amd64 (2.8.117-2build1) ...
Setting up liblzf1:amd64 (3.6-3) ...
Setting up libsdl1.2debian:amd64 (1.2.15+dfsg2-6) ...
Setting up libqt5opengl5:amd64 (5.15.3+dfsg-2ubuntu0.2) ...
Setting up dctrl-tools (2.24-3build2) ...
Setting up dkms (2.8.7-2ubuntu2.2) ...
Setting up virtualbox-dkms (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Loading new virtualbox-6.1.50 DKMS files...
Building for 6.8.0-60-generic
Building initial module for 6.8.0-60-generic
Secure Boot not enabled on this system.
Done.

vboxdrv.ko:
Running module version sanity check.
Error! Module version 6.1.50_Ubuntu for vboxdrv.ko
is not newer than what is already found in kernel 6.8.0-60-generic (7.1.10).
You may override by specifying --force.

vboxnetadp.ko:
Running module version sanity check.
Error! Module version 6.1.50_Ubuntu for vboxnetadp.ko
is not newer than what is already found in kernel 6.8.0-60-generic (7.1.10).
You may override by specifying --force.

vboxnetflt.ko:
Running module version sanity check.
Error! Module version 6.1.50_Ubuntu for vboxnetflt.ko
is not newer than what is already found in kernel 6.8.0-60-generic (7.1.10).
You may override by specifying --force.

depmod...
Setting up virtualbox (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Setting up virtualbox-qt (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for libc-bin (2.35-0ubuntu3.10) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for shared-mime-info (2.1-2) ...

It looks like there's a Virtualbox kernel modules funk up.

I'm kind of fed up with this thing now, so this is the last thing I'm posting today. I think maybe there are some clues here:

Sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
dctrl-tools dkms libgsoap-2.8.117 liblzf1 libqt5opengl5 libsdl1.2debian
virtualbox-dkms
0 upgraded, 0 newly installed, 7 to remove and 10 not upgraded.
After this operation, 9,105 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 321531 files and directories currently installed.)
Removing virtualbox-dkms (6.1.50-dfsg-1~ubuntu1.22.04.3) ...
Module virtualbox-6.1.50 for kernel 6.8.0-60-generic (x86_64).
Before uninstall, this module version was ACTIVE on this kernel.

vboxdrv.ko:

  • Uninstallation
    • Deleting from: /lib/modules/6.8.0-60-generic/
      rmdir: failed to remove '': No such file or directory
  • Original module
    • No original module was found for this module on this kernel.
    • Use the dkms install command to reinstall any previous module version.

vboxnetadp.ko:

  • Uninstallation
    • Deleting from: /lib/modules/6.8.0-60-generic/
      rmdir: failed to remove '': No such file or directory
  • Original module
    • No original module was found for this module on this kernel.
    • Use the dkms install command to reinstall any previous module version.

vboxnetflt.ko:

  • Uninstallation
    • Deleting from: /lib/modules/6.8.0-60-generic/
      rmdir: failed to remove '': No such file or directory
  • Original module
    • No original module was found for this module on this kernel.
    • Use the dkms install command to reinstall any previous module version.

depmod...
Deleting module virtualbox-6.1.50 completely from the DKMS tree.
Removing dkms (2.8.7-2ubuntu2.2) ...
Removing dctrl-tools (2.24-3build2) ...
Removing libgsoap-2.8.117:amd64 (2.8.117-2build1) ...
Removing liblzf1:amd64 (3.6-3) ...
Removing libqt5opengl5:amd64 (5.15.3+dfsg-2ubuntu0.2) ...
Removing libsdl1.2debian:amd64 (1.2.15+dfsg2-6) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.10) ...

That's the error that appeared with VirtualBox 6.x. At this point you should try to uninstall it following the previous steps as outlined above, and then move on to VirtualBox 7.x as per the instructions in this thread:

Alternatively, you could try using KVM instead for your virtual machines. It's a native technology built into the Linux kernel and it works much better than VirtualBox. The only "downsides" is that is not as portable to other platforms, and I'm not really sure how well it handles Windows guests.

Hello, again. Thank you for all your help. I managed to install Virtualbox 7.1.10 with the deb file for Ubuntu 22.04. It seems to be working fine.
I guess this is a separate issue, but there's still something weird going on with the Software manager (gnome-software). The deb file opened fine in the Software manager. The version there said 7.1.10. I clicked on install and immediately after it installed the version changed to 6.1.50 - before my very eyes! But of course when I open Virtualbox, it's the 7.1.10 version that's installed. If I go back to the Software manager and search for the 7.1.10 version it's nowhere to be found. I only have the option to uninstall the stupid 6.1.50 version which is NOT on the system and I get the same error message as before when I try to uninstall it. I checked with the apt list --installed command and only virtualbox-7.1 is listed there. I don't know enough about how the Software manager works to figure out what’s wrong. Where does it get its list of apps from and how is that connected to what's really installed on the system?

Exhibit A

Exhibit B