i started a generic podman
container with: podman run --privileged -it ubuntu:latest bash
where i created an empty .img
file:
dd if=/dev/zero of=myImage.img bs=1M count=2048 # 1. Generate an Empty 2GB Image File
mkfs.ext4 myImage.img # 2. Format the Image File as ext4
mkdir -p /mnt/data
mount myImage.img /mnt/data # 3. Mount the Image File
But I keep getting hit with the error:
mount: /mnt/data: mount failed: No such file or directory.
But i've also checked and both myImage.img
and /mnt/data
exists.
These steps were successful in docker, but not sure what is happening on podman. Any thoughts?
These steps were successful in docker, but not sure what is happening on podman. Any thoughts?
There is a fundamental difference between podman and docker: when you run the docker
command, you are interacting with the Docker daemon, which is running as root
. When you run podman
, you aren't interacting with any pre-existing service; you are running the command under your own user id.
Your user doesn't have permission to interact with the loop device, which is necessary for mounting files as block devices. Try running the same mount command as yourself outside of the container, and it should fail (although hopefully with a more useful error message):
$ mount somefile /mnt
mount: /mnt: failed to setup loop device for /home/lars/somefile.
Running a --privileged
container cannot grant you more privileges than you have outside of the container. If you need to interact with system devices that require root
access, you'll need to run Podman as root
:
$ sudo podman run -it --rm --privileged docker.io/ubuntu:latest
root@5b13872baae4:/# truncate -s 500M myimage.img
root@5b13872baae4:/# mkfs.ext4 myimage.img
mke2fs 1.47.0 (5-Feb-2023)
Discarding device blocks: done
Creating filesystem with 128000 4k blocks and 128000 inodes
Filesystem UUID: 8e376abb-cc54-4954-8a48-fb346cab8559
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@5b13872baae4:/# mount myimage.img /mnt
root@5b13872baae4:/#