27
15
I am aware of the huge number of posts on the internet saying that this would not work and why and I really spent days looking for the solutions months ago but I've found yesterday some tips how to "enable TRIM command support" for guest machines. I've tried it and "it looks" like working. What I would like to know is where's the catch or is this really working as it should.
Sources:
https://forums.virtualbox.org/viewtopic.php?f=7&t=51768
http://jaysonrowe.blogspot.com/2013/08/compacting-virtualbox-vdi.html
My exact command attaching the disk file:
VBoxManage storageattach "GuestOsMachineName" --storagectl "SATA" --port 1 --device 0 --nonrotational on --discard on --medium "C:\path\to\file.vdi" --type hdd
Which genereted this entry in the machine's *.vbox file:
<AttachedDevice nonrotational="true" discard="true" type="HardDisk" port="1" device="0">
<Image uuid="{3836a042-a83e-4000-9a59-e95ad65162ce}"/>
</AttachedDevice>
To be sure I would not lose any data this drive was the second one attached to the machine. I've made simple test like copying some file to the drive, leaving it, restarting the machine, shutting down the machine, checking if it's there after booting back, looking at the disk file usage in the host OS. Results are:
- disk file attached without options --nonrotational and --discard keeps its (dynamic) size even after deleting files in the guest OS
- disk file attached with both options mentioned above releases the space after the data was deleted
Now here are my questions:
- what does exactly --discard option do? it's not described in the VirtualBox manual
(http://www.virtualbox.org/manual/ch08.html#vboxmanage-storageattach)
- is it really passing TRIM down to the host OS or does it just look like?
Just a warning for anybody interested in the topic. The trimming implementation on the VirtualBox disk image emulator is extremely buggy and will likely crash your vm. There's a 2 years old bug opened for it. It's possible to enable it but don't waste time trying it. – Dominik SMogor – 2019-05-10T09:15:54.403
I think this is the bug Dominik is referring to: https://www.virtualbox.org/ticket/16450
– bobpaul – 2019-07-09T16:01:07.4803Virtual TRIM used on a virtual machine interfaced to a virtual disk for virtual feelgood... – Fiasco Labs – 2013-09-17T19:12:49.007
Ramhound: So what is the "Solid-state drive" checkbox option in the storage submenu for? Beside, if there is an option like --discard mentioned in the manual, then it should be detailed. I completely don't get your point saying that "there is a reason why it's not described". If so, why it is in the manual at all? – Krzysztof Szynter – 2013-09-19T06:32:13.887
12To answer @Ramhound my blog is one of the post the OP listed. I'm not sure what his reason was, but for me, I had a Virtual Machine that I needed to physically shrink the filesize of the dynamically allocated disk. It was a disk that had held data that was deleted and I was trying to shrink it back down to a smaller size -- passing the TRIM command enabled that to happen...shrinking my virtual disk from 12G to 7G. To the OP, I hope my post helped you. I got here by seeing incoming traffic on my blog. – Jayson Rowe – 2014-01-07T03:03:26.880