Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 100 GB image file which is created using dd. This image file is mounted via a loop device as read-write.

I want to store a backup of this image file at a remote location. I have a script which compresses the image file (using zip) and copies the zip file to the remote storage (scheduled using cron).

Now, my question is: should I make my script unmount the image file before zipping it? (If some read-write operation is in progress, then I would not be able to unmount it and the script would thus fail).

Or is it okay to zip it when it is still mounted? What happens if there is some write operation in progress when the zipping starts? Would the image file still be consistent?

I would appreciate some insights.

share|improve this question
up vote 2 down vote accepted

If you copy a filesystem image while it is mounted read&write, you will get an inconsistent copy. This is true whether the image is a file underlying a loop device or, more simply, a normal block device. It is not okay to zip it while it is still mounted.

By the way, zip seems like an unlikely choice for compressing a single large file. The streaming nature of the more commonly used tools gzip or bzip2 seems more appropriate.

Instead of accessing a live image, you will want to take a snapshot of it instead. One option would be to use a LVM LV instead of a file-backed loopback device. Then you could take an LVM snapshot of the LV before compressing it. LVM's snapshotting capability automatically communicates with the filesystem to ensure a consistent snapshot, if the filesystem supports it (xfs and, I think, ext4 support this).

share|improve this answer
To use LVM, I need to re-partition my physical disk to setup LVM PVs and LVs on the physical disk, right? Or am I missing something here? – Anjan Oct 25 '12 at 18:41
Well, technically you could create an PVM PV on top of a file-backed loop device, and create a VG and some LVs in that, but that is even quite a lot more overhead than you already have! I do recommend using LVM directly on your physical disk, especially if you deal with filesystem images as large as 100GB and their backups, because creating those as LVs would save the overhead of using file-backed loopbacks. In fact on Linux servers, I always use LVM because it's so much more flexible and user friendly than disk partitions. But you're right: you have to make that decision from the start. – Celada Oct 25 '12 at 19:27
without LVM, is there some way to consistently suspend the r/w operation to make the copy manually? I think, may be, the mount "remount" option could be used ? – Aquarius Power Jan 21 '15 at 20:20
@AquariusPower yes, you can use fsfreeze to temporarily lock the filesystem in a consistent state. Without a snapshot, you must wait until the copy is finished before you thaw the filesystem. With a snapshot, you can thaw as soon as the snapshot is taken. fsfreeze uses the same interface as LVM uses when it makes its snapshots. – Celada Jan 22 '15 at 2:15
@AquariusPower kill -SIGSTOP is different. It does stop a process from running, but it doesn't make the filesystem promise to write outstanding data to disk. kill -SIGSTOP of all processes that could potentially write to the affected filesystem plus running sync would come closer, but fsfreeze is both easier and offers a more robust guarantee. – Celada Jan 23 '15 at 2:01

Your Answer


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.