[SOLVED] How to shrink .img file size

Anston06

Reputable
Apr 21, 2020
37
0
4,560
I have a .img file that has about 100mb of files in it, but the total size of it is 2gb. How can I shrink its size in Windows down to ~100mb?
 
Solution
You can make a second disk image with dosbox-x you just have to go to the "DOS" menu, and select "Create blank disk image…" it is limited to some pre set sizes with the smallest being 250Mb.
If you want better control of the size you will need to download bochs and learn how to use bximage.

After you have your second image you mount it to D, or whatever letter you like, then you run fdisk to create a primary main partition on that image.
Lastly you would use a cloning tool like norton ghost to copy everything over and then the second image would be the same as the first other than the size.
Incomplete solution (haven't tested backup of mbr myself):
  • Get Gparted (bootable iso file, 32bit variant).
  • Attach the ISO-file to the VM (should boot from it without user need to manually alter boot order)
  • Make copy/backup of the img file!
  • When Gparted is running, use that to manually shrink size of the partition. This will probably not alter the img file itself as it reflect the size of a physical disk, so further steps is required.
  • In VM (when no OS runs) - create a new img file. This must be big enough so that the OS can actually run.
  • Get a clone tool - I tend to use Clonezilla (32bit preferably in your case) (also bootable iso file)
  • Boot VM where Clonezilla is attached to CD drive and BOTH img files attached to VM.
  • Start the process of cloning from one partition to another (boot sector not included)
Ok - the hard step for a non-Linux user is to backup the MBR. some sources on web:
https://tecadmin.net/drive-and-partition-backup-examples-with-dd-command/ See bottom of the page.
Other online suggestion goes toward using the UBCD toolkit to restore MBR, if this works for W95, I don't know.
 

Anston06

Reputable
Apr 21, 2020
37
0
4,560
Incomplete solution (haven't tested backup of mbr myself):
  • Get Gparted (bootable iso file, 32bit variant).
  • Attach the ISO-file to the VM (should boot from it without user need to manually alter boot order)
  • Make copy/backup of the img file!
  • When Gparted is running, use that to manually shrink size of the partition. This will probably not alter the img file itself as it reflect the size of a physical disk, so further steps is required.
  • In VM (when no OS runs) - create a new img file. This must be big enough so that the OS can actually run.
  • Get a clone tool - I tend to use Clonezilla (32bit preferably in your case) (also bootable iso file)
  • Boot VM where Clonezilla is attached to CD drive and BOTH img files attached to VM.
  • Start the process of cloning from one partition to another (boot sector not included)
Ok - the hard step for a non-Linux user is to backup the MBR. some sources on web:
https://tecadmin.net/drive-and-partition-backup-examples-with-dd-command/ See bottom of the page.
Other online suggestion goes toward using the UBCD toolkit to restore MBR, if this works for W95, I don't know.
This sounds complicated. Sorry, I forgot to mention I could use WSL. Is there a simpler way to decrease the .img file's size that way?
 
You can make a second disk image with dosbox-x you just have to go to the "DOS" menu, and select "Create blank disk image…" it is limited to some pre set sizes with the smallest being 250Mb.
If you want better control of the size you will need to download bochs and learn how to use bximage.

After you have your second image you mount it to D, or whatever letter you like, then you run fdisk to create a primary main partition on that image.
Lastly you would use a cloning tool like norton ghost to copy everything over and then the second image would be the same as the first other than the size.
 
Solution

Anston06

Reputable
Apr 21, 2020
37
0
4,560
You can make a second disk image with dosbox-x you just have to go to the "DOS" menu, and select "Create blank disk image…" it is limited to some pre set sizes with the smallest being 250Mb.
If you want better control of the size you will need to download bochs and learn how to use bximage.

After you have your second image you mount it to D, or whatever letter you like, then you run fdisk to create a primary main partition on that image.
Lastly you would use a cloning tool like norton ghost to copy everything over and then the second image would be the same as the first other than the size.
Awesome. When I got to ghost, I just pressed disk, then to disk, and it worked perfectly. Thanks!
 
Last edited: