I have a squashfs file that was created with mksquashfs. How can I mount the archive from within a container? I'm using Podman version 3.4.1 and have a normal user on the computer system (so I'm running rootless Podman).
Asked
Active
Viewed 1,614 times
1 Answers
0
squashfuse can be used to mount a squashfs archive inside a container.
Example on a Fedora 34 computer
Build a squashfuse container image from this Dockerfile
FROM docker.io/library/fedora RUN dnf install -y squashfuse fuse
with podman build
[testuser@laptop ~]$ mkdir squashfuse_container [testuser@laptop ~]$ emacs -nw squashfuse_container/Dockerfile [testuser@laptop ~]$ cat squashfuse_container/Dockerfile FROM docker.io/library/fedora RUN dnf install -y squashfuse fuse [testuser@laptop ~]$ podman --version podman version 3.4.1 [testuser@laptop ~]$ podman build -q -t squashfuse squashfuse_container/ 1c2a97ccd71698978973ddc534b96f955a96aad89aef447456d3d327957faeb6 [testuser@laptop ~]$
Create a squashfs file (data.squash) with mksquashfs
[testuser@laptop ~]$ mkdir data [testuser@laptop ~]$ echo foo > data/file1.txt [testuser@laptop ~]$ echo bar > data/file2.txt [testuser@laptop ~]$ mkdir res [testuser@laptop ~]$ mksquashfs data res/data.squash Parallel mksquashfs: Using 8 processors Creating 4.0 filesystem on res/data.squash, block size 131072. [================================================================|] 2/2 100% Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072 compressed data, compressed metadata, compressed fragments, compressed xattrs, compressed ids duplicates are removed Filesystem size 0.35 Kbytes (0.00 Mbytes) 76.28% of uncompressed filesystem size (0.46 Kbytes) Inode table size 55 bytes (0.05 Kbytes) 35.71% of uncompressed inode table size (154 bytes) Directory table size 36 bytes (0.04 Kbytes) 75.00% of uncompressed directory table size (48 bytes) Xattr table size 54 bytes (0.05 Kbytes) 100.00% of uncompressed xattr table size (54 bytes) Number of duplicate files found 0 Number of inodes 3 Number of files 2 Number of fragments 1 Number of symbolic links 0 Number of device nodes 0 Number of fifo nodes 0 Number of socket nodes 0 Number of directories 1 Number of ids (unique uids + gids) 1 Number of uids 1 testuser (1007) Number of gids 1 testuser (1007) [testuser@laptop ~]$ ls -l res/ total 4 -rw-r--r--. 1 testuser testuser 4096 Oct 31 11:06 data.squash [testuser@laptop ~]$
Run podman run and then use squashfuse to mount the squashfs archive
[testuser@laptop ~]$ podman run --rm \ --cap-add=sys_admin \ --device /dev/fuse \ -v ./res/data.squash:/a:Z \ -ti localhost/squashfuse [root@1e6860530222 /]# mkdir /mnt/dir [root@1e6860530222 /]# squashfuse /a /mnt/dir [root@1e6860530222 /]# ls -l /mnt/dir total 0 -rw-r--r--. 1 1007 1007 4 Oct 31 09:31 file1.txt -rw-r--r--. 1 1007 1007 4 Oct 31 09:31 file2.txt [root@1e6860530222 /]# cat /mnt/dir/file1.txt foo [root@1e6860530222 /]# cat /mnt/dir/file2.txt bar [root@1e6860530222 /]# exit exit [testuser@laptop ~]$
The same commands on one line. (Removing
-ti
for this non-interactive version):podman run --rm --cap-add=sys_admin --device /dev/fuse -v ./res/data.squash:/a:Z localhost/squashfuse /bin/bash -c "mkdir /mnt/dir ; squashfuse /a /mnt/dir; ls -l /mnt/dir; cat /mnt/dir/file1.txt; cat /mnt/dir/file2.txt"

Erik Sjölund
- 10,690
- 7
- 46
- 74