3

My hard drive seems to be failing and I suspect some data may be already damaged, so I decided to make an entire drive backup with Clonezilla using dd. I have chosen bzip2 compression to fit entire 750 GB drive on a 500 GB one. The image is split into 4000 MB chunks.

Right now I'm working off a portable drive and I don't want to put too much strain on the dying drive. I want to recover some files onto that portable drive from the Clonezilla image I've made. My idea is to mount the compressed image so I can copy required files off it.

I already know how to access compressed image without extracting it first (AVFS), so I just need to mount the dd image. The problem is I have no extra space available, as the smaller drive is almost full (7 GB free), so cat-ing archive chunks together is not an option.

Is there any way to cat archive chunks on the fly, so I can mount the image that's inside the archive? I have found this solution, but I guess AVFS will need to seek the file. Or maybe there's some simplier solution?

2
  • 2
    Next time, use a qcow2 compressed image (with qemu-img convert -c -O qcow2) instead of a split bzip2ed raw image. Commented Nov 30, 2013 at 15:37
  • qcow2 is actually a really cool idea. You might even be able to pull it off with 7GB free space and 4GB chunks, for the in place conversion of bzip2 to qcow2. If their compression rate is similar... Commented Nov 30, 2013 at 16:09

3 Answers 3

3

What you're asking for is not trivial. It's possible, I just don't know an existing implementation of the solution you need. AVFS probably won't work.

There is seek-bzip ( https://github.com/cscott/seek-bzip ) and similar projects which attempt to provide random block access to bzip2 archives. Creating the table for that will take about as long as uncompressing the entire thing; actual I/O will require the correct block to be found, uncompressed and held in memory, and if it's needed again later on, uncompressed again. I currently do not know of any way to employ that solution to your problem directly, though.

To my knowledge there also isn't any program that would take a filesystem image in a pipe (not seekable) and extract files out of it.

You'd have to implement this in NBD, fuse, or similar. AVFS goes in that direction, but it does not mention seekability of bzip2 files. If it does not employ this technology (and the source code doesn't look like it), it will work for smallish files only or for application that read the entire thing linear (such as cp or tar would). Any random access I/O (such as you have with a mounted filesystem image) would get you out of memory or the access would be so slow it's completely unusable (i.e. it would extract 450GB of data for a 4k read at the end of the disk).

There's cloop but it's not widely available (Knoppix only?) and it'd require you to convert your existing bz2 image to the cloop format first. If you do the conversion in-place and it fails, your image is gone.

Sometimes, buying a larger HDD is the preferable solution.

2
  • Thanks for detailed answer, I appreciate it. I'm going to RMA this disk and I just want to temporarily backup it for later restoration and have access to my files until I get a new one; if I were to buy a new disk I'd just clone the old one directly. Do you think that qcow2 conversion would be possible if I had, say, 70 GB of free space?
    – gronostaj
    Commented Nov 30, 2013 at 17:21
  • Might work. Have a care with the exact method, as you still have the risk of losing the image, if something goes wrong. I don't have time right now to experiment with it, but I'll be happy to do so next week if you can't figure it out by then (and remind me). Commented Nov 30, 2013 at 17:42
3

You can mount a Clonezilla partition image read-only using concat-fuse, ratarmount and imagemount (from the partclone-utils package) in combination to concatenate the chunks, decompress and mount the filesystem image on the fly. This method does not write anything to disk besides the index that is built to randomly access the compressed data. Generating the index may take a while but that step must only be done once.

python3 -m ratarmount -oallow_other $(cfconcat sda7.ext4-ptcl-img.gz.*) <mountpoint_1>

sudo modprobe nbd
sudo imagemount -d /dev/nbd1 -f <mountpoint_1>/*

sudo mount -oro,noload /dev/nbd1 <mountpoint_2>
3
  • Sounds cool! I'll keep this in mind next time I'm in similar situation, thanks a lot.
    – gronostaj
    Commented Nov 8, 2020 at 20:04
  • Note that if you really want, you can use ratarmount --index-file :memory: to avoid writing out the index file to disk if there really is no space. But, normally you should have more disk space than memory.
    – mxmlnkn
    Commented Oct 10, 2021 at 19:43
  • Note that -oallow_other is required, you'll get a permission denied otherwise (even as root)
    – piegames
    Commented Feb 15, 2022 at 21:40
-1

Well, first of all you need to put all the chunks into one file.

Afterwards you will be able to mount this "total" image through a loop device without.

Here's an example for doing so with use of gzip - you simply may apply it to the use of bzip :

So Clonezilla uses partclone you may find additional info on project's website too :

2
  • I've googled that already, but it doesn't solve my problem. I want to extract single files without restoring entire drive or partition and without permanently cat-ing chunks, because I have only 6-7 GB of disk space available. Also, I have chosen dd mode instead of partclone. Please read my question more carefully.
    – gronostaj
    Commented Nov 30, 2013 at 14:40
  • dd/bzip/gzip that doesn't matter you always mount these type of images via the loop-device, so you are able to restore single files from within. BUT you need to combine the cunks.
    – domi27
    Commented Nov 30, 2013 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .