Page 1 of 1
Dynamic VDI: how does VB store guest's data?
Posted: 19. May 2011, 17:54
by scottgus1
Say I have a 100GB dynamic vdi that really has only 60GB of data in it. On the host drive the vdi takes up 60GB. In my guest VM I delete 20GB of data. Now the vdi has only 40GB of data, but it still takes up 60GB on the host drive. There will be 20GB of empty blocks.
OK, so I'm browsing the web in the guest and I download an DVD ISO into the guest's C:\ drive, about 5GB new data. How does Virtualbox determine where in the vdi this new data gets written? Will VB make sure to put that data into the blocks the old data was deleted from first? Or does the guest OS have a say? Or something else?
Re: Dynamic VDI: how does VB store guest's data?
Posted: 20. May 2011, 06:56
by BillG
It really doesn't have much to do with VirtualBox. VB is simply an application running under the host OS. It does not write directly to the HDD. Like all other applications it does this through calls to the host OS.
The guest OS "writes" to its virtual hard disk as if it was an HDD. At that level the OS is not aware that it is running in a vm. VB redirects these writes to the virtual hard disk through the host OS. So basically the guest OS will decide where it wants to write a new file and VB and the host OS translate this to a write to the virtual hard disk.
If you want to tidy up storage in your virtual disk you do it through the guest OS.
Re: Dynamic VDI: how does VB store guest's data?
Posted: 20. May 2011, 07:08
by mpack
All decisions about which parts of the disk to write to are taken by the guest OS. There's a linear mapping between what the guest is doing and what VBox does to simulate it. E.g. if the guest thinks it's writing to physical sector number X on the guest drive, then it is actually writing to logical sector X on the virtual disk image. If (X/2048) identifies a 1MB block that hasn't been allocated yet then the VDI file will grow by 1MB. In fixed VDIs these 1MB blocks are allocated at creation time and hence the guest can never write to a block that hasn't been allocated yet.