Home > *nix, linux, windows > Mount file images on Windows

Mount file images on Windows

This post shows how to mount ext2 or ext3 image files on Windows 7

On GNU/Linux you can let an ordinary file represent a block device (disk/iso image etc.) and mount it as if it was the physical thing. On Windows you can do it too. However mounting Linux file systems will presently loose you file permissions. More on that later.

What we’ll achieve by the end of this tutorial is the effect in Linux achieved by the following commands:

$ dd bs=1M count=100 if=/dev/zero of=disk
$ mkdir mnt
# mount -o loop disk mnt
$ ls mnt
=> lost+found

Tools we’ll need (“free as in beer”)

  • Cygwin with the packages coreutils and e2fsprogs.
    These give us the programs dd and mke2fs.
  • Ext2 Installable File System for Windows, a driver that makes windows able to read and write ext-file systems. However, the driver will not preserve file permissions, so anything read or modified through the driver will get a hard coded set of permissions and upon write, assign those permissions to the file or directory on the ext filesystem. Also special files such as device nodes will not be understood, so the driver is only suitable for operating on “ordinary” files.
    Note: To install this program on Windows 7, set the installer to compatibility mode for Windows Vista SP2. The driver is signed and works perfectly well on Windows 7, but the installer doesn’t recognize Win7 as a valid OS, so we must trick it.
  • OFSMount, for mounting files as devices. Serves the purpose of “mount -o loop” in Linux.

I’m assuming you’ve installed cygwin into c:\cygwin for the tutorial. If you’ve installed it somewhere else, then revise the path to the commands accordingly.

  1. Create an empty file which will host whatever filesystem you want to place on it.
    c:\cygwin\bin\dd bs=1M count=100 if=/dev/zero of=disk
  2. Create a filesystem on the block of space allocated in the file.
    c:\cygwin\usr\sbin\mke2fs -t ext2 -F disk
  3. ofsmount-screenMount the file as a block device in Windows using OFSMount and pick a drive letter to mount it on.During the mount procedure, the Ext2IFS driver will recognize the file system as ext and will interpret it for the Windows kernel, allowing Windows to treat the block device (disk file) as an ordinary “disk”.
  4. Optional: mount the new “drive” in a directory to completely mimic the Linux example.
    md mnt
    mklink /D mnt <drive letter used in OFSMount>:\
    dir /B mnt
    => lost+found

To unmount the loopback device simply unmount the disk via OFSMount.

I have just one beef with this solution and that’s with Ext2IFS and it not being able to retain file permissions. I do understand the technical challenge, but if the ACL metadata could be made to piggy-back on some other data structure, perhaps hijacking the Windows ACL API, then user land tools could be enhanced in Cygwin to correctly translate that into Unix file permissions.

As it stands this little excursion of mine into loop-back mounting was triggered by me wanting to use shared folders with Vagrant, not only on my macbook but also on windows. If I loose file permissions then this solution is pretty useless from a DevOps perspective. Otoh. if it solves some problem for you, then I at least didn’t just waste two hours coming up with this recipe.

Do let me know if you find a solution to the permission problem of using an ext-driver on Windows. I’d be happy to hear if anyone’s cracked it.

Categories: *nix, linux, windows Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment