0

I would like to take a dm snapshot of a drive. I do not want to take the snapshot of the unused and deallocated blocks. Is there any way of determining the used blocks and sectors of a hard drive without being file system aware. I would like to take a snapshot without having the empty parts of my disk backed up.

  • 1
    That's how snapshots work; only the blocks that are written to after creating the snapshot are copied. Initially no space is used, regardless of how much is used/free in the origin. – psusi May 28 '13 at 19:06
  • If I understand that correctly these are two questions / problems not related to each other. – Hauke Laging May 28 '13 at 21:58
1

Without being filesystem aware, the best you can get is probably something like this:

  1. Take a snapshot.
  2. fsck the snapshot if needed. Then mount it.
  3. Fill all free space in the snapshot with 0's (e.g., cp /dev/zero tmpfile; rm tmpfile). This will take a lot of I/O, and also will require you to have plenty of space allocated to the snapshot.
  4. Unmount the snapshot.

You can then assume that any sectors filled with 0's are unused. Or, at least, need not be backed up; you can just fill them with 0's again. (You could also feed the image to gzip, it should compress fairly well).

Much faster would be to use tools like partimage or partclone that do understand the filesystem. Or, just use tar.

  • If your disk is a SSD, be aware that writing useless blocks on it each time you do a snapshot might not be such a great idea... – lgeorget May 28 '13 at 22:54
  • @lgeorget Indeed it wouldn't be, but unfortunately the trim tools are filesystem specific. The final paragraph is what I'd do. – derobert May 29 '13 at 15:22

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.