Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

VM's Hosted on SSD - TRIM?

Featured Replies

I have a couple Windows 7 VM's hosting various things. I turned off Disk Defragment because I'm not sure if it sees the virtual drive as an SSD or not and I'd rather err on the side of caution. When it comes to TRIM though, do I need to figure out how to get Windows to TRIM or will my Dynamix SSD TRIM plugin take care of all my virtual drives?

Hopefully @johnnie.black will chime in, but from what I'm reading with a quick google, you would need to change the virtio interface to scsi in the VM image controller definition, first making sure the virtio-scsi driver is available in the guest. After the guest is successfully using virtio-scsi, and you have edited the xml properly, the guest should be able to pass the trim command through to the host device. I'm not altogether clear on whether qcow2 is the only image format supported for this or if a sparse raw image that unraid creates by default will work.

https://blog.zencoffee.org/2016/05/trim-support-kvm-virtual-machines/

 

Trimming the host device with the dynamix plugin will work fine, except that the contents of the virtual disk will not get processed and over time you will probably need to "re-sparsify" the guest disk file and then trim. https://www.jamescoyle.net/how-to/323-reclaim-disk-space-from-a-sparse-image-file-qcow2-vmdk

  • Community Expert
5 hours ago, jonathanm said:

Hopefully @johnnie.black will chime in

 

Not sure about this, never really looked into into, will try to investigate when I can if no one else knows for sure how it works.

  • Community Expert

So I did some investigating as like I said I'd never considered this, but I'm glad DDock brought this up.

 

By default trim doesn't work, since the vdisk on a SSD is detected by Windows as and hard disk drive, not SSD, but following up on what jonathanm posted I found that using the virtio-scsi controller together with discard='unmap' (image can remain raw, no need to use qcow2) will make Windows defrag detect the disk as a "Thin provisioned drive" and this way Windows will discard all unused space on the vdisk, this free space will then be trimmed by the dynamix trim plugin.

 

Example, my Win 8.1 VM, before trim:

 

(allocation - capacity)

50G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

after trim:

31G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

So besides trim not working on the vdisk it was wasting about 20GB.

 

 

 

Edited by johnnie.black

  • Author

Cool, thanks for the replies. I will have to play with this. Just a thought I had and I'm not that experienced with the nitty gritty of VM's and such. I will look into this and hopefully get it working this weekend. I was going through and thinning out all the fluff (services and other features I do not use) and saw disk defragmenter. I figured unRAID would see the file as a "blob" like any encrypted container, but I wanted to check. Thanks again for the information.

On 4/26/2017 at 7:44 AM, johnnie.black said:

So I did some investigating as like I said I'd never considered this, but I'm glad DDock brought this up.

 

By default trim doesn't work, since the vdisk on a SSD is detected by Windows as and hard disk drive, not SSD, but following up on what jonathanm posted I found that using the virtio-scsi controller together with discard='unmap' (image can remain raw, no need to use qcow2) will make Windows defrag detect the disk as a "Thin provisioned drive" and this way Windows will discard all unused space on the vdisk, this free space will then be trimmed by the dynamix trim plugin.

 

Example, my Win 8.1 VM, before trim:

 

(allocation - capacity)

50G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

after trim:

31G -rwxrwxrwx 1 root users 60G Apr 26 12:15 vdisk1.img*

 

So besides trim not working on the vdisk it was wasting about 20GB.

 

 

 

How did you manage to convert / get Windows to boot after this?  I've changed the controller type, added the controller (and set an appropriate bus#), and windows starts, but then winds up in a boot loop (and ultimately wants to repair the installation)?  Or was this a new install (hard to determine from your post detailing the before / after allocation size).  BTW, windows is detecting my vdisk as an SSD (Win10 Creators edition), but am unable to manually optimize the drive

Edited by Squid

  • Community Expert
15 minutes ago, Squid said:

How did you manage to convert / get Windows to boot after this?  I've changed the controller type, added the controller (and set an appropriate bus#), and windows starts, but then winds up in a boot loop (and ultimately wants to repair the installation)?  Or was this a new install (hard to determine from your post detailing the before / after allocation size).  BTW, windows is detecting my vdisk as an SSD (Win10 Creators edition), but am unable to manually optimize the drive

 

First only add the controller to the XML, boot Windows and install the driver, it install as "virtio scsi pass-trough controller", shutdown vm and now change the disk line.

 

Fist time booting Windows will crash, due to Windows fast startup, but let it reboot and from now on will boot correctly.

37 minutes ago, johnnie.black said:

 

First only add the controller to the XML, boot Windows and install the driver, it install as "virtio scsi pass-trough controller", shutdown vm and now change the disk line.

 

Fist time booting Windows will crash, due to Windows fast startup, but let it reboot and from now on will boot correctly.

You da man!!!  :D

Untitled.thumb.png.c943708b56d38be364e3e6180546d1f0.png

down to

Untitled.thumb.png.354dffaa8b518f0d58902da8b16bb9c0.png

this should be addd somewhere to something. faq. optimization. something.  seems important enough to merit it.

  • Author

I'm glad I brought it up. Just a thought I had one day at work. I haven't been able to test it out yet, I have a drive that is possibly failing, so I have been keeping it easy on my server. Drives came in today to replace and I will test it this weekend. I'm sure it will work since other have had success.

  • Author

I'm still learning, and I've got things kinda working. Added:

 

    <controller type='scsi' index='0' model='virtio-scsi'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </controller>

Changed the slot to one that was not used by anything else, but now my network controller is no longer functioning, can someone please explain to me what I did wrong. Is it something to do with the function= argument.

  • Community Expert

I added a FAQ entry with the instructions, check it out and if any step doesn't work correctly for you post here so I can improve it.

 

 

  • Author

Got it all working now! Thanks for all the help.

Thanks for the detailed guide johnnie!

 

Have it working too with the additional recovery of space on my cache disk. Now to make it permanently stick in XML :)

 

Is this only a Windows 7/8 issue? My Windows 10 VM identifies my drive as an SSD without modifying my xml in the above fashion. Do I still need to do this modification?

Edited by DoeBoye

1 minute ago, DoeBoye said:

Is this only a Windows 7/8 issue? My Windows 10 VM identifies my drive as an SSD without modifying my xml in the above fashion. Do I still need to do this modification?

So did mine, but the vdisk would never release the unused space back to the cache drive without the changes, effectively meaning that trim would never work.

  • Community Expert
2 minutes ago, DoeBoye said:

Is this only a Windows 7/8 issue? My Windows 10 VM identifies my drive as an SSD without modifying my xml in the above fashion. Do I still need to do this modification?

 

If it's identified as an SSD trim is probably working but won't recover the unused space.

Just now, Squid said:

So did mine, but the vdisk would never release the unused space back to the cache drive without the changes, effectively meaning that trim would never work.

 

 

1 minute ago, johnnie.black said:

 

If it's identified as an SSD trim is probably working but won't recover the unused space.

 

Good to know! I'll implement this change tonight! :)

 

Thanks gents!

Just now, johnnie.black said:

 

If it's identified as an SSD trim is probably working but won't recover the unused space.

But wouldn't the trim ultimately have to operate at the vdisk level?  If the blocks are never released from the vdisk, then ultimately the blocks are still in use on the cache drive, and trim won't operate.

  • Community Expert
Just now, Squid said:

But wouldn't the trim ultimately have to operate at the vdisk level?  If the blocks are never released from the vdisk, then ultimately the blocks are still in use on the cache drive, and trim won't operate.

 

If Windows detects an SSD it should issue the trim commands and the SSD should do them, but difficult to be sure, using the other method the unused space is unallocated and trimmed by linux/fstrim.

I made the required changes last night to the xml, and it looks like all systems are a go! Win10 sees the drive as a "thin provisioned drive" now, and has successfully run "optimize" on it.

 

The only difference for me was it took a couple of boots before it stopped blue screening. Also, for some odd reason, it forgot all my files on my desktop after the switch to the scsi controller, but I created a blank txt file on the desktop, and they all magically reappeared. Very odd...

 

Unfortunately, I took a picture of the cache drive's used space before making the change, forgetting that I had moved the VM to a separate UnassignedDevices ssd, so I don't know exactly how much space was freed :(  Doh!

 

Thanks folks!

  • Author

So I got everything working last weekend, so I thought. I was converting all my VM's and as of now it seems that Windows is unable to optimize the drives. When I defragmented using the GUI, it would Trim and then say "Needs optimization (42% space efficiency) every time I clicked optimize.  I've tried a couple other defrag commands in command prompt like /x which consolidates free space. This did run for awhile and seemed to do something, but still would not optimize properly via the GUI. I ran the command defrag c: and it did something, but did not reduce the file size of the image at all. Is there something else I am missing. Is it maybe when I setup the VM's, I set a hard size? Thanks for any imput.

needsoptimized.PNG

cmddefrag.PNG

aftercmddefrag.PNGcontroller.PNG

disk.PNG

Edited by DDock
ocd

  • Community Expert
42 minutes ago, DDock said:

I've tried a couple other defrag commands in command prompt like /x which consolidates free space

 

Drive optimization only needs to be used once after the controller change to recover the unused space, after that all space is automatically recovered after any file deletion, no point in running optimize.

 

As for the low space efficiency don't know, mine all are above 75%, maybe if you have a lot of small files is less efficient, not sure.

  • Author

I understand. But sadly I have not reclaimed any free space on my SSD after the changes. These were all steps to try and troubleshoot why my vdisk.img has not shrunk in size at all. I did bump up all my space to 75gb after I took those images on the 3 Windows VM's I have, so the used space all show 78gb used within windows. Within unRAID, the VM's show they have all 75GB allocated, which I would think it would shrink if it was reducing the size appropriately. These were originally Windows 7 machines that were upgraded to 10, if that makes a difference.

allocation.PNG

  • Community Expert
6 minutes ago, DDock said:

I understand. But sadly I have not reclaimed any free space on my SSD after the changes. These were all steps to try and troubleshoot why my vdisk.img has not shrunk in size at all. I did bump up all my space to 75gb after I took those images on the 3 Windows VM's I have, so the used space all show 78gb used within windows. Within unRAID, the VM's show they have all 75GB allocated, which I would think it would shrink if it was reducing the size appropriately. These were originally Windows 7 machines that were upgraded to 10, if that makes a difference.

 

What filesystem is your cache?

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.