Is there a way to take a disk img file that is broken up into parts and mount it as a single loop device?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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.
Method 3
You could write your own block storage device extension (think of fuse-like extension) and perform seeks dependently on what’s the address.
Here you can find example of how to use fuse
https://github.com/libfuse/python-fuse/blob/master/example/hello.py
Method 4
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.
Method 5
Under BSD you can use the union option to mount.
Under Linux you can give a try to unionFS.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0