Let's look at this from a troubleshooting perspective. The number one thing to do instead of guessing is diagnose and the best way to do that when you don't know what the problem is. I'll take you through the steps for my particular use case but it should give you a general idea on how to look at the problem in order to find the correct solution.
a.-Have a look at the actual logs of the VM:
Click on the Menu Item, you should see three choices:
- Details
- Snapshots
- Logs
Look for this error code:
VMSetError and look for the matching RETURN CODE (rc)
rc=VERR_VD_IMAGE_READ_ONLY
In the example below the file under /build/virtualbox....is in read only mode.
VMSetError: /build/virtualbox-8vePuu/virtualbox-6.1.16-dfsg/src/VBox/Devices/Storage/DrvVD.cpp(5228) int drvvdConstruct(PPDMDRVINS, PCFGMNODE, uint32_t); rc=VERR_VD_IMAGE_READ_ONLY
b.-Interpret what that means:
But the problem is the /build directory does not exist at all. So what the rc above really means is that it cannot FIND that file, because /build doesn't even exist (nor it seems to be supposed to).
cd: /build/virtualbox-8vePuu/virtualbox-6.1.16-dfsg/src/VBox/Devices/Storage/: No such file or directory
root@pop-os:~# cd /build/virtualbox-8vePuu/virtualbox-6.1.16-dfsg/
-bash: cd: /build/virtualbox-8vePuu/virtualbox-6.1.16-dfsg/: No such file or directory
root@pop-os:~# cd /build
-bash: cd: /build: No such file or directory
root@pop-os:~# ls /
bin dev home lib32 libx32 media opt root sbin sys usr
boot etc lib lib64 lost+found mnt proc run srv tmp var
Another thing to notice is that for my case other VMs with VDIs in the same location don't have the problem.
That completely discards two possibilities:
- There's a problem with the install of Virtual Box
- There's an actual file permissions issue
The possibility is that the VM got corrupted at some point during shut down and that created the config corruption, not a VDI corruption at the VM level, not VirtualBox level.
Unless you power off your VM the "Close" function on your Vm window will ALWAYS save the state of the machine, so "Discarding" the state is only possible when you have two or more states because in that case at a minimum there is always the LAST state.
The conclusion is then that the corruption is at the VM state level and we need to get rid of that.
c.-Solution:
Go to VM-> Menu->Snapshots -> Clone
Create a linked Clone. That will simply copy the config files to the right place and link with the same VDI.
Start that one.
If it starts you know you have a problem with the original VM. You can either re-create the VM and point to the existing VDI or create a full clone (it will take longer) and the delete the original.
To prevent this (at least for my case), avoid sending the Power Off Message to your VM when closing, better use the ACPI Shutdown method as Power off can leave (as we saw) your machine on an unwanted state.