Skip to content

Instantly share code, notes, and snippets.

@vasi
Last active February 18, 2025 01:27
Show Gist options
  • Save vasi/b6285221a153be2aa973d5700e708de7 to your computer and use it in GitHub Desktop.
Save vasi/b6285221a153be2aa973d5700e708de7 to your computer and use it in GitHub Desktop.
Mounting Clonezilla images with FUSE

Mounting Clonezilla images with FUSE

I love to make backups with Clonezilla. But often, I'll back up my system, wipe my Linux partition and try another distro—only to realize that I need access to just one file from the old installation. For example, maybe I made an interesting change to my .zshrc or Samba configuration, which I want to re-use on the new system.

The obvious solutions aren't my favorites. It's easy to restore an image to a spare disk, but it takes a long time, and requires a spare disk I'm willing to wipe. I could extract an entire image, but that also takes lots of time and space. Wouldn't it be nice to just look inside my compressed Clonezilla image, just like I can do with a zip file or squashfs archive?

It turns out it's possible, with clever use of user-space filesystems!

Walkthrough

Here's a quick walkthrough of how to do this, once you have all the software you need. I've only ever tried this on Linux, and it's easiest as root.

Let's say my Clonezilla image is at the path /home/partimag/my-image/nvme0n1p5.ext4-ptcl-img.xz

  1. Create some mountpoints:
# mkdir -p mnt1 mnt2 mnt3
  1. My image is compressed, so transform it into decompressed form:
# lzopfs /home/partimag/my-image/nvme0n1p5.ext4-ptcl-img.xz mnt1
# ls mnt1
nvme0n1p5.ext4-ptcl-img
  1. Now it's in a format called Partclone. Convert it to a normal, raw disk image like I'd get from dd:
# vpartclone -m mnt2 mnt1/nvme0n1p5.ext4-ptcl-img
# file mnt2/nvme0n1p5.ext4-ptcl-img
mnt2/nvme0n1p5.ext4-ptcl-img: Linux rev 1.0 ext4 filesystem data ...
  1. Loop mount this image, to make it a real browsable filesystem:
# mount -o loop,ro mnt2/nvme0n1p5.ext4-ptcl-img mnt3
  1. I can read all the data I need! Even though my Clonezilla image is compressed, I can now browse it like a regular directory:
# ls mnt3
bin dev etc home lib ...
# cat mnt3/etc/os-release
NAME="Debian GNU/Linux"
...
# xdg-open mnt3    # browse it in your graphical file manager
  1. Once I'm done readin or copying files, clean up:
# umount mnt3 mnt2 mnt1

Getting the software

I used some uncommon tools to do this. If you want to try, you'll need at least these two:

  1. lzopfs is a tool I wrote to mount a compressed file as if it's uncompressed. You can download executables here, as AppImages.
  2. vpartclone is part of imagebackup, and can make a Partclone image look like a regular disk. There's several ways to install it, but my favorite is with pipx: pipx install imagebackup.

There's also some other alternative tools you could use.

Tips and tricks

Making changes to the image

Sorry, you can't do this! Mounting compressed data such that it's writable is really hard, and not possible with any of the formats Clonezilla suports.

Choosing the right Clonezilla format

When I create an image with Clonezilla, it asks a lot of questions. Some answers work better than others for mounting the resulting image. My quick preferences:

  • Compression: Choose "parallel xz compression", which Clonezilla also calls z5p or z5.
    • You may also want to edit the config file /etc/drbl/drbl-ocs.conf to set extra_xz_opt=-0, so your backups are faster.
  • Splitting the images into multiple files: Enter 0, to not split images.
  • Checking the image after running: Only enable if you have a new version of xz, 5.4.0 or higher. You probably have this if your distro shipped in 2024 or later.
  • Encryption: I rarely enable this. If you do, you'll need to add an extra step to mounting, to decompress the ecryptfs directory where your image is stored.

For more advanced details, check out the appendix.

Running as non-root

This should generally work as non-root, except for the loop-mounting step, and unmounting. However, you'll need to configure your system specially for this: In /etc/fuse.conf, add a line that simply says user_allow_other.

Filesystem recovery

If the partition you imaged wasn't cleanly unmounted, you may get errors when you attempt the loop mount as your system tries to handle the filesystem journal. Should this happen to you, add -o norecovery to your loop mount command-line, to tell your system not to bother with the journal.

Appendices

Appendix A: Alternative tools

The tools I mentioned may not be your only options:

  • For mounting a compressed file as if it's decompressed, you may also try ratarmount. I wasn't able to get this to work on large images, though, and it insists on slow scans.
  • For turning a Partclone file into a raw image, you could also try the imagemount tool from partclone-utils, or partclone-nbd. But these are both hard to install, and require use of NBD block devices, which makes them more complex.

Appendix B: Clonezilla option details

Compression:

  • Most compression formats require a slow scan of the entire image in order to transparently mount it in decompressed form. But xz doesn't need a scan at all, so it's much faster to mount! It gives high compression too when creating the image.
  • Since xz can be slow to compress, setting the -0 argument to xz makes image creation much faster. You still get better compression than most formats, even at the zero'th level.
  • If you need the fastest possible compression, lzo (aka z3) is probably the next best option. It needs a scan on mount, but it's a fairly quick scan.
  • Gzip or bzip2 can both work, but will be rather slow to scan.
  • Other options like zstd, lzma, lzip won't work for transparent decompression.

Splitting:

  • It's easiest to mount a single file.
  • If for some reason you've split your files, you can just concatenate them with cat into a single large file. Clonezilla should handle it fine.
  • If you really need files to be split, you may be able to use concat-fuse to make them appear merged.

Checking the image:

  • Older versions of xz only have single-threaded decompression, so they'll take a very long time to check the image. Newer xz can do this in parallel!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment