Recently, I used Clonezilla to snap a copy of my laptop before I moved from Ubuntu to Arch Linux, just in case it went so sideways that I needed to get a properly working operating system back on the lappy in a hurry.
Clonezilla is a wonderful utility to image disks with and includes lots of awesome features. That aside, after I got my new Arch Linux laptop up and running, I realized that I had some stuff on the OLD hard drive (that had been wiped out by the OS change) that I needed. I could have just as easily used Clonezilla to make an image of my current (Arch) system, reimage to the old (Ubuntu), boot it up, grab the data and put it somewhere accessible, then re-reimage to the Arch system again.
This honestly wouldn’t have taken very long; the imaging process only takes about 15 minutes each way. However, I didn’t want to do that, and figured that it should be perfectly possible to simply mount the Clonezilla hard drive image on my current system, open it up, grab what I needed, then close it back up again.
The other possibility would have been to make a virtual machine, boot Clonezilla, image the Ubuntu system into the VM, boot the VM, grab the data, and then delete the VM; however, in this particular case, this wasn’t an option.
As it turns out, I was right; it IS possible to mount a Clonezilla image and read it, but I needed to do some SERIOUS messing around to get it to work just right. (honestly, it WAS probably more work than it was worth in light of just re-imaging things twice or using a VM; but this is a good thing to know how to do in case you’re trying to restore a system that you don’t have the original hardware for or any number of other silly things).
My task was made even more difficult because the laptop I was on was not connected to the internet; I needed a few packages first, and ended up having to do a bunch of USB-key-fu (read: download a file onto a USB key then move it across to the laptop) to get what I needed on the laptop. After that, I had to compile partclone from source in order to have the right utility to actually reconstruct the image into a file that could be read properly.
First off, credit where it’s due: the procedure for this comes mostly from this thread, which I modified for an EXT4 file system rather than NTFS.
- My Clonezilla image was split into several 2GB files and gzipped (you can find out what kind of compression, if any, is used on the file in one of a few ways: use the command
file filenameand read the output; read the filename itself (in my case, there’s a .gz in there which indicates gzip); read the
Info-packages.txtfile created by Clonezilla in the directory your image files are in; inside that file is usually a hit about what kind of compression was used on the file). Combine them into one and unzip:
cat sda1.ext4-ptcl-img.gz.a* | gzip -d -c > sda1.img.
- Install partclone, partimage, or ntfsclone (depending on what you need or have access to). As I mentioned, in my case I had to compile partclone.extfs from source before I could do anything else.
- Using the correct partclone variant (in my case, partclone.extfs), build a disk image file that is in the proper format to be read by a loop device:
partclone.extfs -r -s sda1.img -o sda1-extfs.img --restore_raw_file(note that your command may vary; I have updated this command based on a comment below).
- Mount the image file somewhere useful:
mount -o loop sda1-extfs.img /mnt/image
Now all you have to do is navigate into
/mnt/image (or wherever you have the disk image mounted), go find your data, and make copies as desired.
You can probably combine steps 2 and 4 into one long command, as long as you have partclone installed (e.g
cat sda1.ext4-ptcl-img.gz.a* | gzip -d -c | partclone.extfs -r -o sda1-extfs.img --restore_raw_file (command updated per comment below). I didn’t do it that way because I thought I had partclone installed before I started but didn’t; so, while the first step was running, I did the rest of what I needed to in order to get partclone onto the system. The command above MAY NOT WORK – I haven’t tested it, though it should work just fine.