Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
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 –  James Andino Jul 21 '11 at 16:37
add comment

3 Answers

up vote 8 down vote accepted

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.

share|improve this answer
    
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. –  James Andino Sep 3 '11 at 18:22
1  
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
add comment

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.

share|improve this answer
    
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. –  James Andino Oct 29 '13 at 1:08
add comment

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

share|improve this answer
2  
This doesn't look remotely relevant. Did you misread the question? –  Gilles Aug 22 '11 at 13:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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