我有一个用 mksquashfs 创建的 squashfs 文件。如何从容器内挂载存档?我正在使用 Podman 3.4.1 版并且在计算机系统上有一个普通用户(所以我正在运行无根 Podman)。
问问题
209 次
1 回答
0
squashfuse可用于在容器内安装 squashfs 存档。
Fedora 34 计算机上的示例
从这个 Dockerfile 构建一个 squashfuse 容器镜像
FROM docker.io/library/fedora RUN dnf install -y squashfuse fuse
使用podman 构建
[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 ~]$
使用mksquashfs创建一个 squashfs 文件 ( data.squash )
[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 ~]$
运行podman run然后使用squashfuse挂载 squashfs 存档
[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 ~]$
一行上的相同命令。(删除
-ti
此非交互式版本):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"
于 2021-10-31T11:07:39.587 回答