0

I have a system.img android's image file that has ext4 filesystem in it. I mount it as

sudo mount -o ro system.img /mnt

I have two questions:

  1. Why do I need root access to mount the image file?

Mounting the image file as user gives me the following error:

mount: /mnt: mount failed: Permission denied.

The user has full access to the system.img as it is the owner of file:

ls -l system.img
-rwxr-xr-x 1 user users 4877225984 Apr 12 19:13 system.img

The user doesn't have permission to mount the image file even if the user is the owner of the the directory to which I try to mount the image, like that:

$ mkdir system_mount
$ mount -o ro system.img system_mount
mount: system_mount: mount failed: Permission denied.
$ ls -l
drwxr-xr-x 2 user users       4096 Apr 12 19:38  system_mount 

So why mounting always requires root access?

  1. When mounted, the user still may not have access to some directories/files in the mounted filesystem if in the filesystem itself the permissions are not given to the user.

Access to some directories is not permitted, like init.container.rc file (others have no permissions):

-rwxr-x---  1 root 2000  3583 Dec 31  2008 init.container.rc

Trying to get contents of that file fails:

$ cat /mnt/init.container.rc
cat: /mnt/init.container.rc: Permission denied

I still can access that directory as root. And I could access it as user if I used chmod -R 755 if the system was mounted as writable. But as it's not, I get the following kind of errors when I use chmod command:

chmod: changing permissions of '/mnt/d/tracing': Read-only file system

I want to give the user temporary read permissions to the whole filesystem WITHOUT modifying the system.img file (having it mounted as read-only), without actually changing the permissions in the filesystem.

How can I do that?

g00dds
  • 43
  • 4
  • 1
    [`fuse2fs`](https://manpages.ubuntu.com/manpages/jammy/man1/fuse2fs.1.html) – Kamil Maciorowski Apr 12 '23 at 17:51
  • @KamilMaciorowski, yeah, that is exactly what I wanted. Thank you! – g00dds Apr 12 '23 at 18:04
  • In the title there is "users" (plural). You may want to check this: [How to mount FUSE so that all users will have access to it?](https://superuser.com/q/1758100/432690) – Kamil Maciorowski Apr 12 '23 at 18:07
  • 1
    Does this answer your question? [How to mount FUSE (e.g. unionfs) so that all users will have access to it?](https://superuser.com/questions/1758100/how-to-mount-fuse-e-g-unionfs-so-that-all-users-will-have-access-to-it) – Greenonline Apr 12 '23 at 19:45
  • https://unix.stackexchange.com/questions/32008/how-to-mount-an-image-file-without-root-permission – harrymc Apr 12 '23 at 19:57

1 Answers1

-1

Kamil Maciorowski's solution, to use fuse2fs.

g00dds
  • 43
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 12 '23 at 18:09
  • A one liner will probably get deleted. Please edit your post and show us how you used it. And you are allowed to tick your own answer – Rohit Gupta Apr 12 '23 at 20:20
  • I'm not the one who voted down, but I agree that sole "use `fuse2fs`" makes a low quality answer. This is why I posted the hint as a comment (I had no time for proper answer at the time). We want answers to be educative. Your answer is there and it can be improved ([edit]ed), so I'm not going to post a competing answer. Possible improvements: what `fuse2fs` is; link to documentation; what FUSE is; security considerations; how to mount; how to unmount. See [this answer of mine](https://superuser.com/a/1557062/432690) which is more than "use `curlftpfs`"; this is what I mean. – Kamil Maciorowski Apr 13 '23 at 07:56