I wonder if there is a way to integrate (it's a bit different from mounting, I think) compressed files as directories into the file system?

E.g., one could download a compressed-file.tar.gz to his local hard drive, then do cd compressed-file.tar.gz and run a script from within the compressed folder or do cp some-file .. to extract one of the files.

I know that Btrfs supports compression, but I don't want to change the file system that I have (ext3) to support this feature.

3 Answers 3


You can use the command archivemount to mount archives such as .tar.gz.

$ ls
files.tgz    mnt/

$ archivemount files.tgz mnt

$ ls mnt
file1    file2

[... Perform desired read/write operations on the archive via mnt/ ...]

$ umount mnt

[... Any changes are saved to the archive ...]

See the man page for archivemount for more info. It's often times not installed so you'll likely need to install the package. It's also called archivemount. On Fedora 19, for example:

$ sudo yum install archivemount



You're either talking about a FUSE filesystem (filesystem in userspace - Linus calls them toys) or a custom compiled kernel OR squashfs. Squash is not exactly as you describe - you cannot simply mount a tarball for instance - not with the kernel supported VFS, anyway - but you can certainly mksquash any number of files or directories and mount the resulting archive read-only. You have the choice of xz, lzma, or gz compression. Squash is used all of the time - if you've ever used a live linux image chances are very good it was squashed.

I'll tell you one trick I use with squashfs. I like to create a btrfs image file and use btrfstune -S 1 to make it a seed volume. I then put that image in a squashfs archive. From there I can mount -o loop the image.sfs and from within that mount -o loop the btrfs image.

The btrfs seed volume will initially mount as read-only - which is to be expected considering that it's contained within a squashed loop mount. But if I then do:

    fallocate -l $((1024*1024*1024)) /tmp/1GB_tmp.img &&
    losetup -f --show $_
btrfs device add "$GB_tmp_loop" "${btrfs_seed=/path/to/btrfs_image_mount}"
umount "$btrfs_seed"
mount -o compress-force=lzo,autodefrag,rw "$GB_tmp_loop" "$btrfs_seed"

Suddenly I'm taking advantage of btrfss copy-on-write functionality and automatic write compression AND squashfss superior compression all in RAM AND in-kernel.

  • thank you mikeserv, this is a nice answer and I learned a lot from it, but I accepted the other answer because that one is more to the point.
    – Helium
    Commented Apr 5, 2014 at 21:22
  • 2
    @Mohsen - I totally understand and I probably would have done the same - it was more to the point. Sometimes the answers we ask for are not the ones we get - and that's probably a good thing, since we're the ones that need to ask in the first place. In any case, I appreciate the comment very much.
    – mikeserv
    Commented Apr 5, 2014 at 21:25

You can use avfs and then use a shell function to make it easier to use (e.g. acd compressed-file.tar.gz).

You must log in to answer this question.

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