# How to create Linux-styled *.img from within Windows?

8 replies to this topic

### #1 IAmTheTrueMeaningOfCovfefe

IAmTheTrueMeaningOfCovfefe

Silver Member

• 589 posts
• Location:In hiding
• Interests:An investigation is underway to determine whether Trump has any ties to America.
•
United States

Posted 07 February 2017 - 03:04 AM

I'm looking to create a *.img file with Windows-based utilities. I do believe an img is nothing more than a raw disk image that can hold multiple partitions/filesystems (I only need one).

My eventual intent is to copy the image file onto an exFAT-formatted MicroSD, to be used with Android. It will be mounted as a loopback device, with BusyBox or an app doing the actual mounting.

Once the image is created, I will copy it to a Linux install so it can be mounted, create a single partition, then format that partition with the command:

mkfs.ext4 -m 0 -O ^has_journal /dev/***

This will create an ext4 FS, but without journaling or reserved superblocks for root.

Can this be done with ImDisk? If not, what other tools are available?

Thanks!

Edit: This is just for testing an idea. I originally got this idea from a "systemless" modding tool called Magisk, which creates an img at /data/magisk.img, then mounts that img as a loopback device at boot, to /magisk. Deleting mods is as simple as adding to/deleting from the img. Storing the IMG to /data/ and mounting it somewhere in the root FS is convenient, since the data partition is made available very early in the boot sequence. Magisk makes use of patching Android's boot image to do its' work, which in turn turn requires the device to have an unlocked bootloader, but neither of these points are relevant in my case.

Also, how can I non-destructively resize (expand) an existing img and the FS contained within, but without data loss?

### #2 Wonko the Sane

Wonko the Sane

The Finder

• 13924 posts
• Location:The Outside of the Asylum (gate is closed)
•
Italy

Posted 07 February 2017 - 09:07 AM

Why not creating the image directly on Linux, if all the fun happens there?

You can use dd alright in Linux.

Until the image is partitioned (and the volume in it is formatted) it will be just a (huge) file filled with 00's.

The easiest/fastest/better tool to create a file of arbitrary size under Windows is fsz part of the dsfok toolkit):
http://members.ozema...eezip/freeware/

But you can use any of the n existing utilities to create such a file of arbitrary size, including those normally coming with Virtual Machines, like qemu-img, or - fsutil.

Imdisk will access a volume (not a whole disk) image, and though it will allow exporting the image to an image with MBR and "sectors before", it does not "connect" to the Windows Disk Manager (and in any case from it you won't be able to make an EXT 4 partition entry in the partition table) as it won't expose the "\\.PhysicalDriveN".

If you want to actually mount it (exposing the \\.\PhysicalDrive) in Windows you will need a lower level driver than Imdisk, such as the MS VSS dirver, Arsenal Image Mounter or the Kernsafe Totalmounter.

Wonko

### #3 IAmTheTrueMeaningOfCovfefe

IAmTheTrueMeaningOfCovfefe

Silver Member

• 589 posts
• Location:In hiding
• Interests:An investigation is underway to determine whether Trump has any ties to America.
•
United States

Posted 07 February 2017 - 11:20 AM

I have no use for mounting the img in Windows, was just checking to see if there are Windows tools available to create a *nix-compatible img file. I wouldnt trust Windows to create an ext4 FS either. Windows can barely manage itself.

I can run dd on my rooted Android devices too, but I get a "read only filesystem" error, even after issuing the "su" command (in a terminal emulator app) to ensure that dd runs with superuser privileges. I can also run the "mkfs.ext4" command, all of Android's important partitions are ext4 anyway (usually).

Even the most powerful Android devices, with quad+ CPUs and multi-gigs RAM, still arent as powerful as an average PC. It's time-consuming and battery-intensive. Which is why I would rather do the image creation and formatting on a PC. If my device's kernel supported ext4-formatted MicroSDs then this wouldnt be an issue, I'll have to compiling a custom kernel with the correct modules, but that's another project. Mounting can still be achieved manually, via a script, or programattically, with 3rd-party tools.

### #4 Wonko the Sane

Wonko the Sane

The Finder

• 13924 posts
• Location:The Outside of the Asylum (gate is closed)
•
Italy

Posted 07 February 2017 - 11:49 AM

Well Android, is not *exactly* Linux.

Still dd should work fine in it:
http://superuser.com...d-with-terminal

Anyway, as I told you before, until the image is not partitioned it is just a zero filled file, independently if under Windows, Linux or Android, i.e. there is really no "*nix compatible img", just  zero filled file of a given size, that may be either allocated or sparse.

Under Linux you can also use truncate or fallocate:
http://stackoverflow...n-size-in-linux

but cannot say if same or similar commands are available in Android, and particularly in your whatever Android setup.

Wonko

### #5 misty

misty

Silver Member

• Developer
• 778 posts
•
United Kingdom

Posted 07 February 2017 - 07:38 PM

How about dd for Windows? Example command(s) for 1 GB raw disk image -
dd bs=1M count=1024 if=/dev/zero of=path\to\disk.ima --progress
dd bs=1G count=1 if=/dev/zero of=path\to\disk.ima --progress

Or maybe experiment with Olof's Zero and Random device driver

Or use diskpart to create a fixed type VHD and zero (or delete) the 1 sector footer?

Misty

### #6 erwan.l

erwan.l

Gold Member

• Developer
• 2105 posts
• Location:Nantes - France
•
France

Posted 07 February 2017 - 07:57 PM

I use minitool partition wizard under windows everytime i need to deal with "linux" filesystems.

As for mounting a disk image, windows VHD builtin feature will cover most need (go for fixed disks and simply ignore or delete the footer afterwards if need be).

EDIT : looks like Misty beat me by a few mns

### #7 Wonko the Sane

Wonko the Sane

The Finder

• 13924 posts
• Location:The Outside of the Asylum (gate is closed)
•
Italy

Posted 07 February 2017 - 08:10 PM

It will be much slower than fsz (or than mksparse or fsutil), just like dd in linux will be slower than truncate or fallocate ...
Try  running:

@ECHO OFF
IF EXIST test.img DEL test.img
ECHO Start fsz %time%
fsz test.img 1073741824
ECHO End fsz %time%
IF EXIST test.img DEL test.img
ECHO.
ECHO Start dd %time%
dd bs=1M count=1024 if=/dev/zero of=test.img --progress
ECHO End dd %time%
IF EXIST test.img DEL test.img
ECHO Start fsutil %time%
fsutil file createnew test.img 1073741824
ECHO End fsutil %time%
IF EXIST test.img DEL test.img
PAUSE

To give you an idea, the above takes here roughly 0.32 seconds for fsz and 33.53 for dd, and 0.32 seconds for fsutil.
If you try the same with target a slow device (such as an SD card or USB stick) time difference will increase ...

@erwan.l
But there is not (yet) a filesystem (Linux or other OS) here, not even a MBR/Partition table.
BTW, cannot Clonedisk create an empty file of given size?

Wonko

### #8 erwan.l

erwan.l

Gold Member

• Developer
• 2105 posts
• Location:Nantes - France
•
France

Posted 07 February 2017 - 08:20 PM

It will be much slower than fsz (or than mksparse or fsutil), just like dd in linux will be slower than truncate or fallocate ...
Try  running:

@ECHO OFF
IF EXIST test.img DEL test.img
ECHO Start fsz %time%
fsz test.img 1073741824
ECHO End fsz %time%
IF EXIST test.img DEL test.img
ECHO.
ECHO Start dd %time%
dd bs=1M count=1024 if=/dev/zero of=test.img --progress
ECHO End dd %time%
IF EXIST test.img DEL test.img
ECHO Start fsutil %time%
fsutil file createnew test.img 1073741824
ECHO End fsutil %time%
IF EXIST test.img DEL test.img
PAUSE

To give you an idea, the above takes here roughly 0.32 seconds for fsz and 33.53 for dd, and 0.32 seconds for fsutil.
If you try the same with target a slow device (such as an SD card or USB stick) time difference will increase ...

@erwan.l
But there is not (yet) a filesystem (Linux or other OS) here, not even a MBR/Partition table.
BTW, cannot Clonedisk create an empty file of given size?

Wonko

CloneDisk can create an empty file with a given size and optionally use sparse files.

### #9 cdob

cdob

Gold Member

• Expert
• 1366 posts

Posted 07 February 2017 - 10:10 PM

I'm looking to create a *.img file with Windows-based utilities. I do believe an img is nothing more than a raw disk image that can hold multiple partitions/filesystems (I only need one).

Try PartitionGuru http://www.eassos.co...onguru-free.php
Creating .img and ext4 are supported. However mounting this created image may work or fail.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users