1

How can I mount a specific block range from a block device (or byte range from a file), or at least expose it as a loop device without loading the full MBR/GPT ?

I have a few use relevant use cases :

  • Given a hard drive with a broken MBR/GPT, I want to mount a partition whose start/end sectors are known (as well as block size of course), but dd'ing it first isn't an option, due to partition size for example

  • I have a backup image of a full disk (with partition table) in a file, i want to mount a specific partition from it without exposing all partitions as devices

  • I want to do some ill-advised steganography by hiding a FS in a block device or file with start/end offsets to make it less obvious (I know it's not a good option due to entropy and access mappings, that's not the point here)

Last use case is more of a hack inspired by first and second use cases, which are actual problems I encountered.

I found a few related questions, like those :

But the (valid) answers to these questions are often to dd partition or recreate MBR which is not an option here.

3

There's a comment under this already linked question:

I found an answer which is using losetup with -o and --sizelimit options.

Also modern mount can do this. About loop devices in man mount:

This type of mount knows about four options, namely loop, offset, sizelimit and encryption, that are really options to losetup.

So the syntax is like:

mount -o offset=OFFSET,other,options,here /image/file /mnt/foo

where OFFSET is in bytes. One usually knows the offset in 512-byte sectors. If starting sector is e.g. 2048 then this is useful:

mount -o offset=$((512*2048)),other,options,here /image/file /mnt/foo

In practice you hardly ever need sizelimit with mount because the filesystem you mount knows its own size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.