Mounting multiple img files as single loop device

I don't think you can do it in place but if you have enough space this should work:

# Create the files that will hold your data
dd if=/dev/zero of=part-00 bs=1M count=4k
dd if=/dev/zero of=part-01 bs=1M count=4k

# Create the loop devices
losetup /dev/loop0 part-00
losetup /dev/loop1 part-01

# Create a RAID array
mdadm --create /dev/md0 --level=linear --raid-devices=2 /dev/loop0 /dev/loop1

# Copy the original filesystem
dd if=original-file-00 of=/dev/md0 bs=512
# Look at the records written value
dd if=original-file-01 of=/dev/md0 bs=512 seek=<sum of records written values so far>

# Mount the new filesystem
mount /dev/md0 /mnt

You can't simply create a RAID array from the original files because the RAID disks have a specific header where the number of disks, RAID level, etc is stored. If you do it that part of your original files will be overwritten.

You can use the mdadm --build to create an array without metadata but then you really should make a backup first. Or if read-only mount is enough:

losetup -r /dev/loop0 original-00
losetup -r /dev/loop1 original-11
mdadm --build /dev/md0 --level=linear --raid-devices=2 /dev/loop0 /dev/loop1
mount /dev/md0 /mnt

Why do you want to do this? If your filesystem can't handle >4GB files you should just switch to a sane one.


To mount a split disk image (or partition image) you should use affuse from the afftools which are currently maintained here: https://github.com/sshock/AFFLIBv3

So, if you have a file, split up into several subfiles test_img.000, test_img.001, test_img.002, test_img.003, test_img.004, test_img.005, test_img.006, test_img.007, test_img.008, test_img.009

then you can join them virtually with affuse

# affuse test_img.000 /mnt/combine
# ls -lh /mnt/combine
total 0
-r--r--r-- 1 root root 2.0G 1969-12-31 16:00 test_img.000.raw

(this combines all files together starting with file 000, then 001, 002, …)

And then mount the image

mount -o ro,loop,offset=329043456 /mnt/combine/test_img.000.raw /mnt/test

The usage is described here and some examples here. A manpage is also available after compiling and installing, or here.

PS: For me affuse only worked if the split files had a size which was a multiple of 512 bytes.