What is windows way to do `mount -o loop,rw,offset=X`?
The below powershell script will take an .iso and mount it to a directory. I assume it will work for .img, too, but am unsure if it will accept writing.
For example, $img_path
of D:\my_stuff\mount_me.iso
, will create a mount point at D:\my_stuff\mount_me\
Note that the command $drive.AddMountPoint
requires admin privileges.
param([Parameter(Mandatory=$true, Position=1)] [string] $img_path)
##
# https://social.technet.microsoft.com/Forums/scriptcenter/en-US/d2faa6c3-35e8-4bad-8ac8-24902bbb6f1a/what-is-the-point-of-nodriveletter-in-mountdiskimage
##
$ErrorActionPreference = "Stop"
$mount_dir_path = Join-Path `
([System.IO.Path]::GetDirectoryName($img_path)) `
([System.IO.Path]::GetFileNameWithoutExtension($img_path))
if(-Not (Test-Path -Path $mount_dir_path -PathType "Container")) {
$null = mkdir $mount_dir_path
}
$img = Mount-DiskImage -ImagePath $img_path -NoDriveLetter -PassThru
$vol = Get-Volume -DiskImage $img
$drive = Get-WmiObject "win32_volume" -Filter "Label = '$($vol.FileSystemLabel)'"
$mount_return = $drive.AddMountPoint($mount_dir_path)
if($mount_return.ReturnValue -ne 0) {
# https://msdn.microsoft.com/en-us/library/aa384762(v=vs.85).aspx
throw $mount_return
}
##