site  contact  subhomenews

Problem with mount utility when non-root

October 27, 2022 — BarryK

Posting about this, in case anyone else is puzzled by the behaviour of the 'mount' utility when running non-root.

I am working on running EasyOS as user "zeus", where zeus has administrator rights. That means you don't have to prepend "sudo" to do stuff, such as mount a partition.

No problem with 'mount' in busybox, mounting and unmounting work when running as user zeus. Busybox in Easy is currently version 1.32.0.

The 'util-linux' package is version 2.35.1, and it has the "full" 'mount' utility, currently named /bin/mount-FULL

I do intend to get rid of that weird name, just have the one /bin/mount. Busybox mount does almost everything the "full" mount does, except "mount -t ext4 -o offset=<number> imagefile mntpt" does not work -- that "offset" parameter isn't recognized. However, I looked at the source for version 1.35.0 and it looks like that parameter is now supported.

It will mean that can use the busybox mount and umount, and retired them from the util-linux package.

The reason I would want to do that, is 'mount' in util-linux is hardcoded to test UID==0, and if not then either refuses to work, with "must be superuser to use mount". Or, can work as a non-root user, but in an incredibly constrained way...

I found that an entry has to be created in /etc/fstab, for example:

/dev/sda1 /mnt/sda1 ext4 rw,user 0 0

Then, mount will work:

$ mount-FULL /mnt/sda1

The slightest variations, that should work, don't. For example, there is a commandline option to specify a different fstab file; nup, doesn't work. If more specs are in the command, say "mount-FULL -t ext4 /dev/sda1 /mnt/sda1" with the commandline option to force reading /etc/fstab also; nup no good again.

There is a lot of advice on the Internet about this problem. One recurring advice is to set the SUID bit. However, that seems to be for an older version of util-linux. That no longer works.

It is annoying. There are so many scripts and apps that just expect 'mount' to work. I have considered /etc/fstab to be deprecated for many years, and always specify all required parameters on the commandline. I do not want to be forced create an /etc/fstab just to get mounting to work.

So, the plan is to compile Busybox 1.35.0 and test that it does indeed support the "offset=" parameter, and still works for a non-root user. If so, will probably retire the util-linux 'mount-FULL' and 'umount-FULL' utilities.     

Tags: easy