I want to allow a user script to remount
a drive as "ro" or "rw".
By using the user
option in the fstab, I can successfully mount and unmount the drive as a user but the -o remount,rw
fails.
Is it not possible for the user to use the remount
option?!?
/etc/fstab
reads...
UUID=789f-4b3a-b0b2-c05955d7c5ad /mnt/nasbackup auto rw,user,noexec 0 2
but...
john@johnbox /mnt> mount UUID=789f-4b3a-b0b2-c05955d7c5ad
john@johnbox /mnt> mount | grep nvme
/dev/nvme0n1 on /mnt/nasbackup type ext4 (rw,nosuid,nodev,noexec,relatime,stripe=4,user=john)
john@johnbox /mnt> mount -o remount,ro UUID=789f-4b3a-b0b2-c05955d7c5ad
mount: /mnt/nasbackup: must be superuser to use mount.
dmesg(1) may have more information after failed mount system call.
john@johnbox /mnt [32]> umount UUID=789f-4b3a-b0b2-c05955d7c5ad
john@johnbox /mnt>
This is a architectural limitation of
mount
. As a workaround you can use C to write some suid wrappers. Shell scripts won't work because Bash refuses to keep suid.sudo apt install build-essential
remountro.c
remountrw.c
:make remountrw remountro
remountro
orremountrw
to fix those exact two commandsYou still need the
user
part in/etc/fstab
so the non-remount commands keep working like before. Alternatively, you can edit/etc/sudoers
, but it's more complicated to ensure that the parameter restriction rules you write forsudo
remain secure.