fix storage mounting

This commit is contained in:
jr-k 2024-07-21 19:42:27 +02:00
parent dcd8c2002e
commit c082338d72
5 changed files with 52 additions and 26 deletions

View File

@ -1,25 +0,0 @@
# normally we start at sdb to ignore the system hard drive but we're in rpi, sdcard is the system hard drive
KERNEL!="sd[a-z]*", GOTO="obscreen_automount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="obscreen_automount_end"
# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"
# set mountpoint directory output
ENV{dir_name}="/home/pi/obscreen/var/run/storage"
ACTION=="add", RUN+="/bin/mkdir -p '%E{dir_name}'"
# global mount options
ACTION=="add", ENV{mount_options}="relatime"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/usr/bin/systemd-mount --no-block --automount=yes --collect -o %E{mount_options} /dev/%k '%E{dir_name}'"
# clean up after device removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/systemd-umount '%E{dir_name}'"
# exit
LABEL="obscreen_automount_end"

0
system/autostart-browser-x11.sh Normal file → Executable file
View File

View File

@ -0,0 +1,6 @@
KERNEL!="sd[a-z][0-9]*", GOTO="obscreen_automount_end"
ENV{dir_name}="/home/pi/obscreen/var/run/storage"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="obscreen_automount_end"
ACTION=="add", RUN+="/home/pi/obscreen/system/external-storage/obscreen-media-automount.sh /dev/%k '%E{dir_name}'"
ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/systemd-umount '%E{dir_name}'"
LABEL="obscreen_automount_end"

View File

@ -0,0 +1,45 @@
#!/bin/bash
MOUNT_DIR=$2
get_partition_size() {
local partition=$1
lsblk -bno SIZE "$partition"
}
find_largest_partition() {
local device=$1
local largest_partition=""
local largest_size=0
for partition in $(lsblk -lnp "$device" | awk '{print $1}'); do
size=$(get_partition_size "$partition")
if (( size > largest_size )); then
largest_size=$size
largest_partition=$partition
fi
done
echo $largest_partition
}
# Get device (e.g., /dev/sda)
base_device=$(echo $1 | sed 's/[0-9]*$//')
largest_partition=$(find_largest_partition "$base_device")
# Mount largest partition
if [ -n "$largest_partition" ]; then
mkdir -p "$MOUNT_DIR"
mount_options="relatime"
if blkid -o value -s TYPE "$largest_partition" | grep -qE "vfat|ntfs"; then
mount_options="$mount_options,gid=100,dmask=000,fmask=111,utf8"
if blkid -o value -s TYPE "$largest_partition" | grep -q "ntfs"; then
systemd-mount -t ntfs-3g --no-block --automount=yes --collect -o $mount_options "$largest_partition" "$MOUNT_DIR"
else
systemd-mount -t auto --no-block --automount=yes --collect -o $mount_options "$largest_partition" "$MOUNT_DIR"
fi
else
systemd-mount -t auto --no-block --automount=yes --collect -o $mount_options "$largest_partition" "$MOUNT_DIR"
fi
logger "Mounted $largest_partition with filesystem type $(blkid -o value -s TYPE "$largest_partition")"
fi

2
system/install-autorun-rpi.sh Normal file → Executable file
View File

@ -73,7 +73,7 @@ grep -qxF "needs_root_rights=yes" /etc/X11/Xwrapper.config || echo "needs_root_r
curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/obscreen-player.service | sed "s#/home/pi#$WORKING_DIR#g" | sed "s#=pi#=$OWNER#g" | tee /etc/systemd/system/obscreen-player.service curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/obscreen-player.service | sed "s#/home/pi#$WORKING_DIR#g" | sed "s#=pi#=$OWNER#g" | tee /etc/systemd/system/obscreen-player.service
# Configure external storage automount # Configure external storage automount
curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/10-obscreen-media-automount.rules | sed "s#/home/pi#$WORKING_DIR#g" | tee /etc/udev/rules.d/10-obscreen-media-automount.rules curl https://raw.githubusercontent.com/jr-k/obscreen/master/system/external-storage/10-obscreen-media-automount.rules | sed "s#/home/pi#$WORKING_DIR#g" | tee /etc/udev/rules.d/10-obscreen-media-automount.rules
udevadm control --reload-rules udevadm control --reload-rules
systemctl restart udev systemctl restart udev
udevadm trigger udevadm trigger