Ext3: permissions of the mountpoint change when I mount

ext3mount

I need ordinary users to be able to mount /dev/loop0p1 and /dev/loop0p2 on my machine. /dev/loop0p1 is always going to be a FAT32 partition and loop0p2 – a ext3.

To that end, I have:

1) created directories /tmp/loop0p1 and /tmp/loop0p2 (in startup script, I know those disappear after reboot):

[root@machine tmp]$ ls -l
(...)
drwxrwxrwx 2 root       root       80 Jul 22 00:25 loop0p1
drwxrwxrwx 2 root       root       40 Jul 22 00:50 loop0p2

2) added the following lines to /etc/fstab:

/dev/loop0p1  /tmp/loop0p1  vfat defaults,loop,users,noauto  0 0
/dev/loop0p2  /tmp/loop0p2  ext3 defaults,loop,users,noauto  0 0

3) Now as an ordinary user I am able to mount them , no problem.

Problem is with permissions of the loop0p2 Ext3 partition – before the mount, as you can see above, the /tmp/loop0p2 mountpoint is has permissions '777', but after the 'mount /dev/loop0p2', thos suddenly magically change to '755':

[root@machine tmp]$ ls -l /tmp
(...)
drwxrwxrwx 2 user user 16384 Jan  1  1970 loop0p1
drwxr-xr-x 3 root root  1024 Jul 22 00:37 loop0p2

and, needless to say, my user cannot write anything inside the /tmp/loop0p2 mountpoint, which is useless.

Why do the permissions change and is there a ext3 mount option which would give me full access? gid, uid, umask all seem unsupported by this damn ext3!!

Best Answer

Thanks for all the answers, I understand now the permissions of the mountpoint come from the mounted directory.

This thing is that what I am mounting is not a directory, but an image of a block device in a file. The point is to be able to create an image of a USB disk in memory (that's why we are mounting it to TMPFS in /tmp, that's much much faster than writing to an actual block device)

Normal users need to be able to run a script that does this.

So here's the big picture:

1) I create a mount point /tmp/loop0p1

2) I add the following to /etc/fstab (so that normal users can mount /dev/loop0p1):

/dev/loop0p1  /tmp/loop0p1  ext3 defaults,loop,users,noauto  0 0

I run the following script (simplified to show the essence of the problem):

#!/bin/sh

dd if=/dev/zero of=usb.img bs=1M seek=9 count=1

sfdisk usb.img << EOF 
,20480,83
EOF

losetup -P /dev/loop0 usb.img
sleep 2

mkfs.ext3 /dev/loop0p1

mount /dev/loop0p1
echo "loop0p1" > /tmp/loop0p1/p1.txt
umount /tmp/loop0p1

losetup -d /tmp/loop0

The script, as you can see, creates a empty 10MB file, sets up a Linux (type '83') partition in it, loop-mounts this to /dev/loop0, creates a Ext3 filesystem in it, then mounts that to /tmp/loop0p1, and attempts to write a file there.

The problem is that the script fails with 'Permission denied' trying to write the file to /tmp/loop0p1, and no wonder, because like I already said - when I mount, the permissions of /tmp/loop0p1 change to 755 root:root, so obviously as a normal user I cannot write anything to there.

The thing I am mounting is just created out of nothing by 'dd', 'sfdisk' and 'mkfs.ext3'. What exactly should I change so that the user who's been running the script actually has write access?