Is that possible to integrate zip and tar.gz files as directory into the file system

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

References

Method 2

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:

GB_tmp_loop=$(
    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.

Method 3

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x