Как смонтировать файл squashfs в контейнер при запуске безродного Podman?

#fuse #podman #squashfs

Вопрос:

У меня есть файл squashfs, созданный с помощью mksquashfs. Как я могу смонтировать архив из контейнера? Я использую Podman версии 3.4.1, и в компьютерной системе есть обычный пользователь (поэтому я запускаю Podman без корней).

Ответ №1:

squashfuse можно использовать для монтирования архива squashfs внутри контейнера.

Пример на компьютере Fedora 34

  1. Создайте образ контейнера squashfuse из этого файла Dockerfile
     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 ~]$  
  2. Создайте файл squashfs (data.squash) с помощью mksquashfs
     [testuser@laptop ~]$ mkdir data [testuser@laptop ~]$ echo foo gt; data/file1.txt [testuser@laptop ~]$ echo bar gt; 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 ~]$   
  3. Запустите 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"