Virtualization Station img File shrink and defrag

Post Reply
maxx8888
New here
Posts: 6
Joined: Sat Jan 15, 2011 6:34 pm

Virtualization Station img File shrink and defrag

Post by maxx8888 » Mon Nov 09, 2015 11:30 pm

Hi!

Is there any way to free up unused Space within *.img File?

It also seems like some of the *.img Files i'm using are really slow. Is it possible that they are fragmented a lot?

Thanks for help!
Regards,
Markus

Dh4rms
Starting out
Posts: 10
Joined: Thu Nov 20, 2014 4:11 pm

Re: Virtualization Station img File shrink and defrag

Post by Dh4rms » Mon Sep 26, 2016 11:05 pm

Did anyone get an answer to this as I created a Windows vm which has been shrunk in the OS but want to reduce in virtualisation station and hence remove unused disks in the OS
I have asked qnap support

maxx8888
New here
Posts: 6
Joined: Sat Jan 15, 2011 6:34 pm

Re: Virtualization Station img File shrink and defrag

Post by maxx8888 » Fri Jan 20, 2017 2:36 am

Actually, No :-)

Still an open question for me.

There is a way via VMWare Converter Utlity. However, this means exporting shrinking and reimporting VM.

Bye,
Maxx

Dh4rms
Starting out
Posts: 10
Joined: Thu Nov 20, 2014 4:11 pm

Re: Virtualization Station img File shrink and defrag

Post by Dh4rms » Sun Jan 22, 2017 5:21 am

Thank you
I didn't think of that but know as it's an office line activity it may take some time

orgetorix
New here
Posts: 4
Joined: Sat Jan 28, 2017 3:34 am

Re: Virtualization Station img File shrink and defrag

Post by orgetorix » Sat Jan 28, 2017 3:36 am

I also am looking for an answer to this. There seems to be an option is the Virtualization Station settings but ti's asking me to delete all snapshots first?

User avatar
razormoon
Easy as a breeze
Posts: 462
Joined: Fri Feb 13, 2015 5:05 am
Location: Denver, CO

Re: Virtualization Station img File shrink and defrag

Post by razormoon » Sat Jan 28, 2017 4:52 am

[quote="orgetorix"There seems to be an option is the Virtualization Station settings but ti's asking me to delete all snapshots first?[/quote]

Where are you seeing this option??
:!: TVS-871-i7-16G 4.5.1.1480 Build 20201108, KODI, WSE 2019, Untangle (formerly pfSense)
:?: 1 x KINGSTON SNV325S2 as 2mb block cache, WDC WD40EFRX as RAID5, 1 x WDC WD40EFRX as iSCSI
:arrow: Untangle 16.1 (PPPoE), suricata, AdGuard, Killswitched PIA TunnelVPN clients
:idea: APC PRO 1500 S
:-0 WIKI SUPPORT

"Nothing is impossible. Only expensive, illegal or both."

orgetorix
New here
Posts: 4
Joined: Sat Jan 28, 2017 3:34 am

Re: Virtualization Station img File shrink and defrag

Post by orgetorix » Wed Feb 01, 2017 6:14 am

Where are you seeing this option??


It's under the settings tab of the VM. It's under storage. There is a slider, but I cannot change the size. I had originally set it to 2048 GB but have halved it in the OS. Virtualization Station won't let me shrink the volume.

When I try to shrink I get the message "The HDD size cannot be decreased"
You do not have the required permissions to view the files attached to this post.

User avatar
razormoon
Easy as a breeze
Posts: 462
Joined: Fri Feb 13, 2015 5:05 am
Location: Denver, CO

Re: RE: Re: Virtualization Station img File shrink and defrag

Post by razormoon » Wed Feb 01, 2017 7:31 am

orgetorix wrote:
Where are you seeing this option??


It's under the settings tab of the VM. It's under storage. There is a slider, but I cannot change the size. I had originally set it to 2048 GB but have halved it in the OS. Virtualization Station won't let me shrink the volume.

When I try to shrink I get the message "The HDD size cannot be decreased"

Ah. No, that is a completely different function. That refers to the size of the drive as it appears to the VM as physical space. You can increase space, but not the other way around. The drive will start a small file and increase until the size you set when creating it. What OP was referring to was the fact that the file will not get smaller as you delete files on the virtual disk and how to reclaim that space. It's totally different than what you pointed out.
:!: TVS-871-i7-16G 4.5.1.1480 Build 20201108, KODI, WSE 2019, Untangle (formerly pfSense)
:?: 1 x KINGSTON SNV325S2 as 2mb block cache, WDC WD40EFRX as RAID5, 1 x WDC WD40EFRX as iSCSI
:arrow: Untangle 16.1 (PPPoE), suricata, AdGuard, Killswitched PIA TunnelVPN clients
:idea: APC PRO 1500 S
:-0 WIKI SUPPORT

"Nothing is impossible. Only expensive, illegal or both."

orgetorix
New here
Posts: 4
Joined: Sat Jan 28, 2017 3:34 am

Re: Virtualization Station img File shrink and defrag

Post by orgetorix » Thu Feb 02, 2017 2:15 am

I see. I guess I figured that creating a VM with a 2 TB HDD would create am IMG file that size and if I shrunk the volume in the OS that it would shrink the IMG as well.

ssybesma
Starting out
Posts: 39
Joined: Mon Nov 28, 2016 6:53 am

'direct' solution to shrinking virtual HDDs created in Virtualization Station

Post by ssybesma » Wed Aug 07, 2019 12:37 pm

This started out as having an IMG file created in Virtualization Station that contains a virtual HDD that was 64GB in size and I wanted to shrink it down to 16GB so that Virtualization Station sees it that way.
So, shrinking it down by 48GB. Note, the actual SIZE of the IMG file will not change, because the size of the IMG file only reflects what files you actually have on the virtual HDD, not its virtual size.

FIRST, before you do this you must boot the VM to an ISO image loaded into the virtual CD drive (like GParted or PartedMagic) that allows you to resize the virtual HDD partitions. You cannot skip this step.
Using the above-mentioned utility, you must move all allocated space to the beginning of the virtual drive and then de-allocate the space you want to shrink the virtual HDD by.
ALL de-allocated space you're getting rid of to shrink the virtual HDD must all be at the END. The utility you will be using below starts at the end of the virtual HDD and works backwards to shrink it.

SECOND...

I found out how to shrink the virtual HDD in the most 'direct' way possible. That is, I first looked at the header of a small IMG file created in Virtualization Station that I have to see what the file signature was.

The first four bytes appear this way in a hex editor that shows the hexidecimal view as well as the text view: 51 46 49 FB QFIû

When I looked that up online I found: IMG QEMU Qcow Disk Image

The utility that is able to directly modify the file (without first changing formats to another type of file) is part of Qemu for Windows and is called qemu-img.

NOTE: It runs at the command line so it's not a GUI application.

Source for binary files:

https://qemu.weilnetz.de/w64/ <-- Qemu 64-bit (32-bit also available) for Windows -- you will need to extract the qemu-img.exe executable and the following 20 DLL files it needs to run:

iconv.dll
libbz2-1.dll
libcurl-4.dll
libffi-6.dll
libgcc_s_seh-1.dll
libglib-2.0-0.dll
libgmp-10.dll
libgnutls-30.dll
libhogweed-4.dll
libidn2-0.dll
libintl-8.dll
libnettle-6.dll
libnghttp2-14.dll
libp11-kit-0.dll
libpcre-1.dll
libssh2-1.dll
libtasn1-6.dll
libunistring-2.dll
libwinpthread-1.dll
ssleay32.dll

If you need the pre-extracted package, please send me a message and I'll send the zipped file to you.

Instructions for using qemu-img:

https://qemu.weilnetz.de/doc/qemu-doc.h ... invocation <-- check near bottom of section 2.8.4, just before 2.8.5 and you'll see the resize switch options

Example command line to shrink a virtual HDD inside an image file (filename.img) from 64Gb down to 16Gb:

qemu-img resize --shrink filename.img 16G

Replace filename.img with your existing image file's name. Replace 16G with whatever size you have already reduced the allocated space to on the virtual HDD in the first step above.

I tested the qemu-img command above and it worked perfectly to shrink the virtual HDD within the IMG file from 64GB to 16GB.

Key is to make sure when you move/resize partitions in the first step that total allocated space is contiguous and at the FRONT and is no more than the size you're shrinking to (preferably a little less) or the VM won't boot.

Save the newly-shrunk IMG file to a place where you can easily get to it for the next step.

Delete the old IMG file and copy the new IMG file in its place. Keep the existing folder and other files in place.

(Note: you should just be able to pop the modified IMG in the original IMG's place and it works. What I did instead is start over and create a barebones VM using no image but with the correct virtual HDD size as the modified IMG has.)

I tested and it booted fine, and the image info in Virtualization Station now says the virtual HDD is 16GB instead of 64GB. Good, since you could not shrink it there!

DONE!

Post Reply

Return to “Virtualization Station”