Can a virtual machine (VM) overwrite a host disk, a host or guest disk, or a guest another guest disk?
This question stems from "Is it safe to answer "wipe the disk and install Ubuntu" on a virtual machine? ".
Guest space from host:
It happens when the disk space becomes larger than the unused disk space (probably not at the beginning), but later, when the usage increases to 40 out of 50 GB and the main drive only has 40 GB left What? In other words, will the VM overwrite the data, or will it report this data? I just want to be sure, I don't think the VM will overwrite the host's data.
Host space for the guest:
Conversely, if the host disk were to use the space guaranteed for the guest, is there any chance it could damage the guest in some way, and is it possible? Will the host tell you that the host space is limited by that VM?
Guest space:
Just an example from Oracle VirtualBox or any similar VM software, i.e. using "thin provisioning" to install a Linux Mint guest on a Windows 10 host. After selecting the "Clean" option, the installer directly tells me:
"If you continue, the changes listed below will be written to disk. Otherwise, you will be able to make further changes manually. Changed the partition table for the following devices: SCSI3(0,0,0) (sda) will format the following partitions : Partition #1 of SCSI3(0,0,0) (sda) as ext4."
I chose "Continue" and nothing bad happened. Probably the popup message because I already have another VM installed. It seems that this VM can take space from another VM, is this possible?
This problem is not limited to Oracle VirtualBox usage. This question is a general question about VMS, certainly not excluding answers on VirtualBox.
Guest space
On Linux Mint, using VirtualBox, the installer tells me directly after selecting the "erase" option:
If you continue, the changes listed below will be written to disk. Otherwise, you will be able to make further changes manually. Changed the partition table for the following device: SCSI3(0,0,0)(sda) will format the following partition: Partition #1 of SCSI3(0,0,0)(sda) as ext4.
I chose "Continue" and nothing bad happened. Probably the popup message because I already have another VM installed. I don't think the VM will overwrite the host's data. However, it seems like one VM might be taking the space of another VM?
Virtual machines are completely self-contained. They are (broadly speaking) indistinguishable from physical computers, and they won't know about each other unless you connect them in some way - just like physical computers.
The message is not caused by the presence of another VM. This is a "sanity check" type dialog. It requires you to double-check that the installer's automatic selection matches your intent.
I have confirmed experimentally that this message appears when installing Ubuntu 18.04 and 20.04 to an empty, unpartitioned drive.
Host space for guests
From the inside, the VM looks like a normal computer, while from the outside (ie, from the host's point of view) it's just a bunch of files. Typically, you will have a file that describes the hardware configuration of the virtual machine, and a file for each virtual disk attached to that virtual machine. So in most use cases the VM contains two files: one for configuration and one for disk.
Disk files can be preallocated or dynamically allocated. A preallocated disk is created from the beginning to occupy space equal to its capacity. It can slightly improve performance at the cost of taking up host disk space in unused disk areas. If there is not enough disk space to do this, the process will fail when the VM is created, but not yet run.
A dynamically allocated virtual disk file grows when a guest tries to write to its previously unused area. The technical term is sparse file . In this case, the host may actually run out of disk space when the guest tries to write to its virtual disk. Nothing will be overwritten, as this is just a typical case of a program trying to create a file that is too large to fit on disk (the program is your VM software - a hypervisor). The fact that it's a virtual disk attached to a running VM doesn't matter, because from the host's perspective, the file is no different from any other file. The operating system's filesystem driver will simply deny writes to the file. How the hypervisor handles this is up to its implementation.
host's guest space
Again, to the host, a virtual disk is just a file, and it's subject to the same rules as any other file. Any process that is allowed to write to the file can make any modifications to it, unless the file is currently locked for exclusive writing by another process.