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.

I ran these commands:

VBoxManage clonehd d6b9f0a5-98df-48ca-83c8-91a0809ec349 --format RAW Debian.raw
sudo dd if=~/.VirtualBox/HardDisks/Debian.raw of=/dev/sda5

When I try to mount the partition, I get this complaint:

EXT4-fs (sda5): VFS: Can't find ext4 filesystem

Now I know that the VM had an ext4 partition. What did I do wrong?

share|improve this question
add comment

1 Answer

Your image is a disk image, not a filesystem image. The filesystem is on a partition inside that image (unless you did something really unusual). You can confirm this by running file Debian.raw and fdisk -l Debian.raw.

The easiest way to access this partition is to associate it with a loop device. If you can, make sure your loop driver supports and is loaded with the max_parts option; you may need to run rmmod loop; modprobe loop max_part=63. Then associate the disk image with a loop device, and voilà:

losetup -fs Debian.raw     # prints /dev/loop0 (or some other number)
mount /dev/loop0p1 /mnt    # 0 as above, 1 is the partition number

If you can't get the loop driver to use partitions, you need to find out the offset of the partition in the disk image. Run fdisk -lu Debian.raw to list the partitions and find out its starting sector S (a sector is 512 bytes). Then tell losetup you want the loop device to start at this offset:

fdisk -lu Debian.raw  # note starting sector $S
losetup -fs -o $(($S * 512)) Debian.raw
mount /dev/loop0 /mnt  # /dev/loop0 or whatever losetup prints

If you want to copy the partition from the VM image to your system, determine its starting ($S) and ending ($E) offsets with fdisk -lu as above. Then copy just the partition:

<Debian.raw tail -c +$((512*$S)) | dd of=/dev/sda5 bs=4M

(If the source and the destination are not on the same disk, don't bother with dd, just redirect tail's output to /dev/sda5. If they are on the same disk, dd with a large bs parameter is a lot faster.)

share|improve this answer
    
I'm attempting this exact procedure, and I've gotten the loop mount to work, but after using tail and dd, mount still cannot find a filesystem on the raw device. any ideas? –  TREE May 1 '11 at 13:34
    
@TREE: Did you use the loop driver's partition support (/dev/loop0p1), or a user-specified offset (losetup -o)? What is the output of <Debian.raw file -, of <Debian.raw tail -c +$((512*s)) | file -, or file - on any relevant intermediate stage? –  Gilles May 1 '11 at 13:48
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.