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 created an image of an NTFS partition using dd.

I wonder if I can unload/unpack the files and directories in the image to any partition whose size is larger than the image size, so that I can access the files and directories just in the same way as accessing the original partition?

If yes, how shall I do it?


Added:

Just found something useful from a link :

To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of". For example, restore the first partition of /dev/sda from the image file "disk2.img":

dd if=disk2.img of=/dev/sda1
  1. I wonder what will happen, if the partition for of is not the original partition from where the image is created?

    • Consider the cases when the partition for of is smaller or larger than the original partition.
    • Also consider the cases when the partition for of already has some data in it. Is it possible to restore from a particular position in the partition, so to avoid overwriting any existing data on the partition for of?
  2. Can the restoration from an image created by dd used by other similar applications, even by Windows software? In other words, does the image created by dd have some format specific to dd?

Thanks!

share|improve this question

2 Answers 2

That's not exactly how to go about it.

What you'll want to do is mount the disk image as a loopback device:

mount -o ro,loop -t ntfs disk.image /mnt/test

The contents of the image will be available in /mnt/test (but you can choose to mount it anywhere you like). You can copy individual files (or entire directory trees) from it. Use umount /mnt/test1 to unmount it.

As far as restoring the image to a new disk, you need to restore it in the same way that you created it. I.e., if you created an image of an entire block device (e.g., sda) then restore to an entire block device. If you created it from a partition (e.g., sda1) then restore it only to a partition.

That being said, if you are doing partitions you'll need to create them on the destination device before restoring. The destination device also needs to be equal size or larger than the image you created.

If you're dealing with partitions then you can create the partition exactly the same size and you'll be fine. You can create other partitions out of any blocks not already allocated to a partition. If you're dealing with an entire block device restore first, then use gparted* to modify the partitions.


* I'm pretty sure gparted can resize partitions in the disk image directly, but I prefer to keep the disk images pristine.

share|improve this answer
    
Thanks! What does loopback device mean? –  steveO Sep 10 '12 at 21:49
    
@steveO - read this –  don_crissti Sep 10 '12 at 22:39
    
Thanks, @don_crissti and bahamat! I just found that I can restore from an image to a partition. But I wonder what if the destination partition and the original partition from which the image was created are different? See my added part to my post. Thanks! –  steveO Sep 10 '12 at 23:11
    
I've updated my answer to include restoring the image. –  bahamat Sep 11 '12 at 0:04
    
If you prefer to keep the images pristine I'd use -r to mount read only. –  David Kohen Sep 11 '12 at 13:58

Bahamat's already given a good answer on how to extract files from a disk-image file (i.e. loopback mount it and then copy them), so i'll make a generic answer about cloning filesystems.

If your purpose is to backup and restore, or clone a filesystem from one computer to another then:

  1. For linux and unix, you're almost always better off doing file-based backups rather than disk or partition image backups. There are many tools you can use to do this, including cpio, tar, and (my favourite) rsync.

    If you're backing up the root filesystem then you'll need to reinstall the grub bootloader into the MBR when you restore. See the grub documentation for details, in particular the grub-install command.

  2. for NTFS, use a tool like ntfsclone from the ntfs-3g package. It can clone and resize NTFS partitions.

  3. Clonezilla is a great bootable CD for backup/restore and cloning of disk and partition images. It wraps tools like parted, dd, resize2fs, ntfsclone and many others with an easy-to-use text-mode dialog and menu system. E.g. it can clone a partition or disk to another partition or disk, or to a compressed image file on a network file share (e.g. NFS or samba), and restore from same.

share|improve this answer
    
Thanks, Craig! I would like to upvote your reply, but my reputation is too low to do that. I was motivated to ask a question about byte-level and file-level backups: unix.stackexchange.com/questions/47770/… –  steveO Sep 11 '12 at 1:07
    
My favorite is rsync too, but it has lots of memory management issues which makes it fill up the server memory when copying lots of files, keep that in mind. –  David Kohen Sep 11 '12 at 14:01

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.