This is not related to a problem but it just a neat idea.
A script in the dietpi menu which will automatically add fstab entries =)
@diveyez
Many thanks for your request.
There is autofs which automatically mounts attached drives. But it does not create the fstab entries, AFAIK.
The issue is that either we need to recognize kernel events (which is not easily possible with shell scripts, AFAIK) or we need a daemon that constantly checks for attached drives, which would lead to a too high constant CPU usage. So it is 3rd party tools like the above that we need to go with. But perhaps we can implement them into the drive manager, e.g. enable/disable automount and such by installing+configuring such a tool.
As root user, mount all drive, run the following command, then nano /etc/fstab
Review all changes, and uncomment the lines at the bottom if they are correct.
However, upon booting I still have no userland access to the drives.
(Explains why we needed openmediavault in this household to begin with)
blkid | grep /dev/sd | sed -e 's/:.* UUID/;UUID/' -e 's/ TYPE.*//' | while read re; do sed -i "s;$re;" /etc/fstab; done
Updated to explain +1
Actually dietpi-drive_manager already does what we want. But we cannot run an additional process in the background that is constantly scanning for new drives, that would be a complete overhead and overkill.
Actually udev rules should do it:
echo 'ACTION=="add", KERNEL=="sd[a-z]", RUN+="/DietPi/dietpi/dietpi-drive_manager 3"' > /etc/udev/rules.d/99-dietpi-auto_mount.rules
udevadm control --reload-rules
But I need to add the argument 3 that only does the drive scan + fstab creation loop and then exits.
Can you @diveyez notify when this is pushed to stable/master? I really need the lady to be able to do this as, she cannot run a CLI for *NIX or *Win lol
@diveyez
Jep will do.
Did a start: https://github.com/MichaIng/DietPi/commit/73a555639cff1ff418cbdc942b60a20ed9dff512
However currently unmounted drives are added in commented way to fstab. We need to adjust the input argument so that unmounted drives are added un-commented and mounted automatically.
This would actually render autofs/automount obsolete on DietPi 馃槂. I hope the udev method works reliable.
The commenting is for a reason ;)
its
"beta"
in formation lol
echo 'ACTION=="add", KERNEL=="sd[a-z]", RUN+="/DietPi/dietpi/dietpi-drive_manager 3"' > /etc/udev/rules.d/99-dietpi-auto_mount.rules
udevadm control --reload-rules
That's what I really need, but it doesn't work
root@DietPi:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 484M 0 484M 0% /dev
tmpfs 99M 5.7M 94M 6% /run
/dev/mmcblk1p1 2.9G 1.9G 973M 67% /
tmpfs 495M 0 495M 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 495M 0 495M 0% /sys/fs/cgroup
tmpfs 10M 1.4M 8.7M 14% /DietPi
tmpfs 50M 20K 50M 1% /var/log
tmpfs 1023M 4.0K 1023M 1% /tmp
root@DietPi:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
鈹斺攢sda1 8:1 0 931.5G 0 part
mtdblock0 31:0 0 1.5M 0 disk
mtdblock1 31:1 0 64K 0 disk
mtdblock2 31:2 0 2.4M 0 disk
mmcblk0 179:0 0 3.7G 0 disk
鈹斺攢mmcblk0p1 179:1 0 3.7G 0 part
mmcblk0boot0 179:8 0 2M 1 disk
mmcblk0boot1 179:16 0 2M 1 disk
mmcblk1 179:24 0 29.7G 0 disk
鈹斺攢mmcblk1p1 179:25 0 3G 0 part /
@hifitime
This feature (argument 3) has not yet been added to drive manager :wink:. It cannot work yet.
bump. especially reconnecting usb drives that have been (e.g. accidentally) plugged out or not plugged in at boot are very annoying to setup for noobs (i.e. udev rules)
dietpi-drive_manager 3 now works to re-scan drives and rewrite fstab. What I didn't think about is that it does not mount the drive by default. The following could work:
echo 'SUBSYSTEM=="block", KERNEL="sd[a-z][1-9]", ACTION=="add", RUN+="mount /dev/%k || { mkdir -p /mnt/%k && mount /dev/%k /mnt/%k && /boot/dietpi/dietpi-drive_manager 3 && mount -o remount /mnt/%k; }"' > /etc/udev/rules.d/99-dietpi-auto_mount.rules
udevadm control --reload-rules
I adjusted the rule a bit so that it matches only partitions, no raw drives and only block devices, just to be sure. It mounts the drive, if it is present already in fstab (mount command without mount point succeeds), else it creates a new mount point based on the device name (I couldn't find a way to get UUID from within udev rules easily), mounts the drive with default options to that mount point and then runs dietpi-drive_manager to have the fstab entry created with mount options based on drive details, then remounts the drive to apply mount options 馃槄. Requires some testing, especially how it behaves at boot where we don't want that overhead.
dietpi-drive_manager creates a commented fstab entry for non-mounted drives. So another possibility would be to run /boot/dietpi/dietpi-drive_manager 3 first, then uncomment commented fstab entries (a sed call) and then mount the drive.
dietpi-drive_manager 3now works to re-scan drives and rewrite fstab. What I didn't think about is that it does not mount the drive by default. The following could work:echo 'SUBSYSTEM=="block", KERNEL="sd[a-z][1-9]", ACTION=="add", RUN+="mount /dev/%k || { mkdir -p /mnt/%k && mount /dev/%k /mnt/%k && /boot/dietpi/dietpi-drive_manager 3 && mount -o remount /mnt/%k; }"' > /etc/udev/rules.d/99-dietpi-auto_mount.rules udevadm control --reload-rulesI adjusted the rule a bit so that it matches only partitions, no raw drives and only block devices, just to be sure. It mounts the drive, if it is present already in fstab (mount command without mount point succeeds), else it creates a new mount point based on the device name (I couldn't find a way to get UUID from within udev rules easily), mounts the drive with default options to that mount point and then runs
dietpi-drive_managerto have the fstab entry created with mount options based on drive details, then remounts the drive to apply mount options 馃槄. Requires some testing, especially how it behaves at boot where we don't want that overhead.
dietpi-drive_managercreates a commented fstab entry for non-mounted drives. So another possibility would be to run/boot/dietpi/dietpi-drive_manager 3first, then uncomment commented fstab entries (asedcall) and then mount the drive.
wow, thanks a lot. Somehow this doesn't work for me (ntfs drive...). I don't get any errors, it just doesn't mount it. U/Mounting it manually works
this question/answers were very helpful. For my purposes I used pmount like described there to load the ntfs volume. This was somewhat helpful.
Thanks for sharing. Yes a real script is probably better since I am not even sure it that shell syntax I added to the udev rule is even correctly interpreted (curly brackets etc). Wrapping it into a systemd unit has the benefit that the output is not lost but can be reviewed via journalctl -u usb-mount. udev otherwise does not log anywhere, AFAIK. But the same could be archived from within the script itselt.
What I wonder is why everyone uses SUBSYSTEM=="usb" while in my case checking all USB-attached drives clearly state SUBSYSTEM=block: udevadm info /dev/sda | grep SUBSYSTEM
But yeah, all a matter of testing, at least we have collected some ideas.
@diveyez @hifitime in case time allows for it