I'm writing a Python program to mount a partition inside a dd image.
I know that there is code elsewhere (f.ex. https://raw.github.com/ox-it/python-libmount/master/libmount/mounting.py ) to mount a device or a file that contain a filesystem. But these solutions expect the filesystem to be at the beginning of the file or device.
My filesystem is NOT at the beginning of the file, but at a determined offset, so I need to specify an offset to the mount command that points to the start of that partitions.
libc mount command is not clear for me. losetup.py module is not clear either.
Is it possible to mount a partition inside a file or device, at a determined offset, using Python (with ctypes + libc mount command, losetup.py or another solution)?
Thanks in advance.
In linux, you can use losetup -o
Let's say you have image file off.img, its file system start from offset 100 bytes. So first you build a loop dev:
Then you mount this loop dev, we assume it is ext2 type:
You can wrap this in python code with subprocess.Popen if you want. The losetup I mention here is a utility of linux, not losetup.py. If you check losetup.py, it also support offset in its LoopDevice.mount, but I do not test it.