Jump to content











Photo
- - - - -

Can You Shrink the Capacity of Image Files?

shrink capacity image capacity

  • Please log in to reply
No replies to this topic

#1 TechnicGeek

TechnicGeek

    Newbie

  • Members
  • 14 posts
  • Location:Israel
  • Interests:Computing, home DIY, technology
  •  
    Israel

Posted 14 May 2023 - 06:50 AM

Hello

As you see from the image the actual used space is 9MB while the capacity is 62MB.

 

This is just an example that I am experimenting with. Imagine 4GB USB flash drive and 8GB image file where actual used capacity is around 500MB. If I want to place that image on a multi-boot flash drive with other image files that empty space that actually takes capacity space will be a problem.

 

Screenshot-poweriso-144402.jpg

 

Does anyone know how to shrink the empty space that takes unnecessary capacity of image file?

When I tried to create images of USB flash drive the resulting image was of that drive's capacity

and not actual used space.

 

Is there a way to eliminate unused space out of the equation? In Windows computer management tool

in storage there is a way to shrink capacity of volumes. I need something like this but for image files.

 

Thanks


  • antonino61 likes this

#2 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 14 May 2023 - 09:25 PM

would u pls tell us what file extension u have in mind? vdi, vdh, vdhx, wim, iso or any other?



#3 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 15 May 2023 - 08:36 AM

You mount the image, you resize (shrink) the partition, you unmount the image and then truncate it to the needed size. 

 

Or you can use (on NTFS) sparse files.

 

See if anything in this thread (though the kind of truncating proposed there is different, as it is for Ramdisk use):

http://reboot.pro/to...n-many-ramdisk/

 

can be of use/inspiration.

 

 

:duff:

Wonko



#4 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 15 May 2023 - 09:28 AM

I suggest u use hdclone. A more rough-and-ready alternative would be vhd resizer

#5 TechnicGeek

TechnicGeek

    Newbie

  • Members
  • 14 posts
  • Location:Israel
  • Interests:Computing, home DIY, technology
  •  
    Israel

Posted 16 May 2023 - 08:37 AM

You mount the image, you resize (shrink) the partition, you unmount the image and then truncate it to the needed size. 

 

Or you can use (on NTFS) sparse files.

 

See if anything in this thread (though the kind of truncating proposed there is different, as it is for Ramdisk use):

http://reboot.pro/to...n-many-ramdisk/

 

can be of use/inspiration.

 

 

duff.gif

Wonko

 

I loaded image as virtual drive and tried Computer Management > Storage > Disk Management. Since it cannot do that so I did it with MiniTools Partition Magic but file size did not change even though the partition is now 16MB down from 62MB. Unallocated space still takes space. You can see MRBEFI.vhd and image after shrinking MRBEFI-1.vhd of same size as former. Maybe there is a difference between shrinking and truncation?

 

image.png



#6 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 16 May 2023 - 12:51 PM

I can only repeat what I wrote above - hdclone or vhd resizer



#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 18 May 2023 - 11:24 AM

You started with a .img file (i.e. a RAW image).

Then you converted it to (static) VHD.

This process simply appends one sector (the so-called CONECTIX sector) to the image.

The you mounted the VHD image and (via MiniTools partition manager) you resized the volume inside it.

Now you have a VHD image that has a MBR and a smaller partition + unpartitioned space.

 

Now what you need to do is:

 

 

1) inspect the VHD file MBR partition table and find out the last LBA sector used by that partition

2) unmount the VHD file (it depends on what tools you use for inspecting the MBR, you could also unmount the image first and then inspect the MBR offline)

3) truncate the image to the size calculated[1]

4) by doing this, you will also truncate away the sectoir added at the end of the file by the conversion to VHD, so what will remain will be a smaller .img (RAW) file

 

What tools to use for #3 will depend on what you are familiar with, personally I would use Tiny Hexer (with - shameless plug - my MBR Structure Viewer):

 

http://reboot.pro/fi...xer-mbr-backup/

 

and fsz (part of the dsfok toolkit):

 

:http://reboot.pro/in...=22317&p=215243

 

But you can use any tool capable of showing the values in the MBR partition table and any tool capable to copy parts of a file, like dd for windows or, if you prefer a GUI tool partcopy, this approach is sager as you will copy the file to a new one, so - in case of a mistake - you still have the original file.

 

Maybe even simplier, you can use grub4dos.

 

Try mapping your current MRBEFI.img and MRBEFI.vhd, grub4dos will say nothing about MRBEFI.img but show a Warning about size of the image for MRBEFI.vhd similar to this:

 

http://reboot.pro/in...showtopic=21728

 

which is "normal" as the .vhd has an added sector at the end.

 

Now try mapping the MRBEFI-1.vhd, grub4dos will show a warning for much larger number of excess sectors.

 

So you directly know the size as seen in the MBR and the number of excess sectors without needing to calculate them from the MBR partition table.

 

Hope the above is clear/fetailed enough, if you need further help or have doubts, just ask.

 

:duff:

Wonko

 

 

[1] in a partition table you will have in the LBA values, two values, "Sectors Before" and "Number of sectors", since you have a single partition, the sum of the two will give you the number of sectors, that, multiplied by 512 will give you the exact size to truncate.

 

P.S.: @antonino61 I doubt that the free version of hdclone can do that, very likely one of the commercial licenses are needed:

 

https://www.miray-so...ns/hdclone.html

 

please post a link to the VHD resizer you have in mind, I remember one that used to be at VMToolkit and that is now available here:

 

https://www.bursky.n...vhd-volumesize/

 

In any case it has to be confirmed that these tools have the sector or byte accuracy that is advisable for grub4dos mounting without the warning (or with the warning only relative to the affixed VHD footer/CONECTIX sector)



#8 Tokener

Tokener

    Frequent Member

  • Developer
  • 378 posts

Posted 31 May 2023 - 05:45 PM

Hello TechnicGeek

 

I suggest you zero free space on the drive using sdelete from mark russinovich

before you capture it.

 

Best regards   T.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users