Is there a way to take a disk img file that is broken up into parts and mount it as a single loop device?

  • 1
    How is it broken? What format is it? There might be some fuse magic for this if it's a special format, but I suspect the answer is to cat them together! – Caleb Jul 20 '11 at 18:57
  • I am restricted by the format of the device to files that are less the 4 gigs. I have root access though to the device. Is there something I can with LVM – Arcabard Jul 21 '11 at 16:37

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.

  • Might be able to do it with device mapper too, but the above is easier. – Wodin Aug 20 '11 at 23:22
  • Sorry for taking so long to accept, very good answer.I would not do this under normal circumstance, its more of an adventure mode question. – Arcabard Sep 3 '11 at 18:22
  • 2
    You probably want to use truncate instead of dd as it is much faster (it does not perform actual write to FS but just allocates inodes and mark file as just containing hole). – Maciej Piechotka Sep 18 '11 at 22:56
  • Nice. I didn't know that. – stribika Sep 23 '11 at 17:40
  • From experience, if you use large capacity cloud-based backup or syncing solutions like CrashPlan or paid Google Drive it is a very, very good idea to use small split files instead of a single huge file. In the event of a failed file download, you will only have to re-download, say, 1 GB instead of the whole 100 GB thing. – RAKK Apr 14 '17 at 19:50

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.

  • 2
    I just tried this method. It has a major caveat: it will only allow you to mount your image as read only. – RAKK May 9 '17 at 8:26

The closest thing I know so far to a solution is to create a VMware VM. You start a Linux live CD like Rescatux or Knoppix, you create a SMB shared folder on your host computer, you mount that SMB share on your VM, and then you dd the image into the virtual HD. VMware by default saves its disk images as split files, so this is the closest thing to reading directly a disk image split into multiple files.

Later, if you want to access the files from your host computer, you can try adding a second virtual HD to the image and copying the files there. Then you set up a SMB shared folder on the VM and connect to it from your host. This way you can, for example, violate the 4 GB file limit of FAT32 in the event that you're using an iPod Classic (which only groks fat32), or your smartphone's SD card (usually you have to install a custom ROM in order to use Ext3 or NTFS on the external storage, for this you require a phone from a popular manufacturer like Samsung or Motorola, so if you have a Chinese smartphone you're stumped).

It is admittedly not an efficient solution, however, but since I've been limited by not being able to use any FS other than fat32 on my iPod Classic or my Samsung smartphones with stock ROM, I have scoured pretty much the entire internet in the past and still am not able to find an efficient solution to this. I might even have to write it myself.

PS: Forgot to mention, that if you're on Windows this might be the only way to do this.

  • It's been some time since I visited this problem. I still have it. Also I have it exactly the same reason you do. I wonder if you can bring up a process that has it's own custom file system, honestly I would love to attempt this. I know I can do it in node. I've had success bringing the interpreter up in rooted. I don't know if this solves your problem though if I did. On my hardware samsung galaxies this is fine. Tell me would you like to work on something for this problem together. – Arcabard Oct 29 '13 at 1:08

Under BSD you can use the union option to mount. Under Linux you can give a try to unionFS.

  • 2
    This doesn't look remotely relevant. Did you misread the question? – Gilles Aug 22 '11 at 13:27

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.