Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

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.