Created
February 5, 2011 19:40
-
-
Save migerh/812716 to your computer and use it in GitHub Desktop.
Mount a VirtualBox .vdi HDD Image File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
import subprocess | |
def usage(): | |
print "Usage:\n\n " + sys.argv[0] + " <vdi-File> <mount point>" | |
if len(sys.argv) < 3: | |
usage() | |
quit(1) | |
file = sys.argv[1] | |
mpt = sys.argv[2] | |
if not (os.path.exists(file) and os.path.isfile(file)): | |
print "File " + file + " does not exist." | |
usage() | |
quit(1) | |
if not os.path.exists(mpt): | |
print "Folder " + mpt + " does not exist." | |
usage() | |
quit(1) | |
cmp_str = "0xeb0x520x900x4e0x540x460x53" | |
idx = 0 | |
fsz = os.path.getsize(file) | |
f = open(file, 'r') | |
ptr = "".join(map(hex, map(ord, list(f.read(7))))) | |
while ptr != cmp_str and idx < fsz: | |
idx = idx+1 | |
f.seek(idx) | |
ptr = "".join(map(hex, map(ord, list(f.read(7))))) | |
f.close() | |
subprocess.Popen(["sudo", "mount", "-t", "ntfs", "-o", "loop,offset=" + hex(idx), file, mpt]) | |
print "Use\n sudo umount " + mpt + "\nto unmount the file." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment