From e74316d14f43e9b52d02609fa32ab7dd1e5af968 Mon Sep 17 00:00:00 2001
From: j1nx
Date: Sun, 23 Apr 2023 18:01:17 +0200
Subject: [PATCH] Changes and fixes for usbmount and systemd
---
.../board/ovos/ova/grub-efi.cfg | 2 +-
.../configs/ova_64-base_defconfig | 5 +-
buildroot-external/kernel/ovos.config | 2 +-
.../base/etc/sysctl.d/99-ovos.conf | 5 +
.../base/etc/usbmount/usbmount.conf | 53 +++++
.../rootfs-overlay/base/media/rfs/ro/.empty | 0
.../rootfs-overlay/base/media/rfs/rw/.empty | 0
.../usr/lib/systemd/system/mnt-overlay.mount | 15 --
.../lib/systemd/system/overlay-bind.service | 15 --
.../lib/systemd/system/overlay-bind.target | 7 -
.../base/usr/lib/tmpfiles.d/samba.conf | 2 +
.../base/usr/lib/udev/rules.d/usbmount.rules | 19 ++
.../base/usr/share/usbmount/usbmount | 199 ++++++++++++++++++
13 files changed, 283 insertions(+), 41 deletions(-)
create mode 100644 buildroot-external/rootfs-overlay/base/etc/usbmount/usbmount.conf
create mode 100644 buildroot-external/rootfs-overlay/base/media/rfs/ro/.empty
create mode 100644 buildroot-external/rootfs-overlay/base/media/rfs/rw/.empty
delete mode 100644 buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/mnt-overlay.mount
delete mode 100644 buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.service
delete mode 100644 buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.target
create mode 100644 buildroot-external/rootfs-overlay/base/usr/lib/tmpfiles.d/samba.conf
create mode 100644 buildroot-external/rootfs-overlay/base/usr/lib/udev/rules.d/usbmount.rules
create mode 100755 buildroot-external/rootfs-overlay/base/usr/share/usbmount/usbmount
diff --git a/buildroot-external/board/ovos/ova/grub-efi.cfg b/buildroot-external/board/ovos/ova/grub-efi.cfg
index 006d1145..1842456c 100644
--- a/buildroot-external/board/ovos/ova/grub-efi.cfg
+++ b/buildroot-external/board/ovos/ova/grub-efi.cfg
@@ -2,5 +2,5 @@ set default="0"
set timeout="3"
menuentry "OpenVoiceOS" {
- linux /bzImage root=PARTUUID=c0932a41-44cf-463b-8152-d43188553ed4 rootfstype=squashfs ro fsck.repair=yes zram.enabled=1 zram.num_devices=4 net.naming-scheme=v250 console=ttyS0 consoleblank=0 loglevel=0 vt.global_cursor_default=0 audit=0 logo.nologo systemd.show_status=0 rootwait quiet
+ linux /bzImage root=PARTUUID=c0932a41-44cf-463b-8152-d43188553ed4 rootfstype=squashfs ro init=/sbin/pre-init fsck.repair=yes zram.enabled=1 zram.num_devices=4 console=ttyS0 consoleblank=0 loglevel=0 vt.global_cursor_default=0 audit=0 logo.nologo systemd.show_status=0 rootwait quiet
}
diff --git a/buildroot-external/configs/ova_64-base_defconfig b/buildroot-external/configs/ova_64-base_defconfig
index 6e213c99..596df9f7 100644
--- a/buildroot-external/configs/ova_64-base_defconfig
+++ b/buildroot-external/configs/ova_64-base_defconfig
@@ -236,8 +236,6 @@ BR2_PACKAGE_GST1_DEVTOOLS=y
BR2_PACKAGE_GST1_INTERPIPE=y
BR2_PACKAGE_GST1_LIBAV=y
BR2_PACKAGE_GST1_PYTHON=y
-BR2_PACKAGE_MIMIC=y
-BR2_PACKAGE_MIMIC_AUDIO_BACKEND_PULSEAUDIO=y
BR2_PACKAGE_MPV=y
BR2_PACKAGE_PULSEAUDIO_DAEMON=y
BR2_PACKAGE_SOX=y
@@ -374,6 +372,7 @@ BR2_PACKAGE_PYTHON_TWISTED_TLS=y
BR2_PACKAGE_PYTHON_VALIDATORS=y
BR2_PACKAGE_PYTHON_WATCHDOG=y
BR2_PACKAGE_PYTHON_WEBSOCKET_CLIENT=y
+BR2_PACKAGE_PYTHON_ZC_LOCKFILE=y
BR2_PACKAGE_ALSA_LIB_PYTHON=y
BR2_PACKAGE_ALSA_PLUGINS=y
BR2_PACKAGE_LIBAO=y
@@ -430,10 +429,12 @@ BR2_PACKAGE_LIBSECCOMP=y
BR2_PACKAGE_LIBUNWIND=y
BR2_PACKAGE_LIBUV=y
BR2_PACKAGE_PROTOBUF=y
+BR2_PACKAGE_ICU=y
BR2_PACKAGE_LIBESTR=y
BR2_PACKAGE_NCURSES_TARGET_PROGS=y
BR2_PACKAGE_PCRE_16=y
BR2_PACKAGE_PCRE_32=y
+BR2_PACKAGE_PCRE2=y
BR2_PACKAGE_RE2=y
BR2_PACKAGE_XUTIL_UTIL_MACROS=y
BR2_PACKAGE_BLUEZ_TOOLS=y
diff --git a/buildroot-external/kernel/ovos.config b/buildroot-external/kernel/ovos.config
index 5ca08d1f..92bf502f 100644
--- a/buildroot-external/kernel/ovos.config
+++ b/buildroot-external/kernel/ovos.config
@@ -1,7 +1,7 @@
CONFIG_KERNEL_LZ4=y
CONFIG_CMDLINE=""
CONFIG_PANIC_TIMEOUT=5
-
+CONFIG_PSI=y
CONFIG_MODULE_COMPRESS_NONE=y
CONFIG_ZRAM=y
diff --git a/buildroot-external/rootfs-overlay/base/etc/sysctl.d/99-ovos.conf b/buildroot-external/rootfs-overlay/base/etc/sysctl.d/99-ovos.conf
index ad7eedd3..8e8dd63c 100644
--- a/buildroot-external/rootfs-overlay/base/etc/sysctl.d/99-ovos.conf
+++ b/buildroot-external/rootfs-overlay/base/etc/sysctl.d/99-ovos.conf
@@ -2,7 +2,12 @@ vm.vfs_cache_pressure = 500
vm.swappiness = 100
vm.dirty_background_ratio = 1
vm.dirty_ratio = 50
+vm.dirty_expire_centisecs = 500
+vm.dirty_writeback_centisecs = 500
kernel.panic = 20
fs.inotify.max_user_instances = 512
fs.inotify.max_user_watches = 524288
kernel.printk = 3 4 1 3
+net.core.rmem_max = 4194304
+net.core.wmem_max = 4194304
+net.ipv4.igmp_max_memberships = 1024
diff --git a/buildroot-external/rootfs-overlay/base/etc/usbmount/usbmount.conf b/buildroot-external/rootfs-overlay/base/etc/usbmount/usbmount.conf
new file mode 100644
index 00000000..43c25316
--- /dev/null
+++ b/buildroot-external/rootfs-overlay/base/etc/usbmount/usbmount.conf
@@ -0,0 +1,53 @@
+# Configuration file for the usbmount package, which mounts removable
+# storage devices when they are plugged in and unmounts them when they
+# are removed.
+
+# Change to zero to disable usbmount
+ENABLED=1
+
+# Mountpoints: These directories are eligible as mointpoints for
+# removable storage devices. A newly plugged in device is mounted on
+# the first directory in this list that exists and on which nothing is
+# mounted yet.
+MOUNTPOINTS="/media/usb0 /media/usb1 /media/usb2 /media/usb3
+ /media/usb4 /media/usb5 /media/usb6 /media/usb7"
+
+# Filesystem types: removable storage devices are only mounted if they
+# contain a filesystem type which is in this list.
+FILESYSTEMS="vfat ntfs ext2 ext3 ext4 hfsplus exfat f2fs"
+
+#############################################################################
+# WARNING! #
+# #
+# The "sync" option may not be a good choice to use with flash drives, as #
+# it forces a greater amount of writing operating on the drive. This makes #
+# the writing speed considerably lower and also leads to a faster wear out #
+# of the disk. #
+# #
+# If you omit it, don't forget to use the command "sync" to synchronize the #
+# data on your disk before removing the drive or you may experience data #
+# loss. #
+# #
+# It is highly recommended that you use the pumount command (as a regular #
+# user) before unplugging the device. It makes calling the "sync" command #
+# and mounting with the sync option unnecessary---this is similar to other #
+# operating system's "safely disconnect the device" option. #
+#############################################################################
+# Mount options: Options passed to the mount command with the -o flag.
+# See the warning above regarding removing "sync" from the options.
+MOUNTOPTIONS="noexec,nodev,noatime,nodiratime"
+
+# Filesystem type specific mount options: This variable contains a space
+# separated list of strings, each which the form "-fstype=TYPE,OPTIONS".
+#
+# If a filesystem with a type listed here is mounted, the corresponding
+# options are appended to those specificed in the MOUNTOPTIONS variable.
+#
+# For example, "-fstype=vfat,gid=floppy,dmask=0007,fmask=0117" would add
+# the options "gid=floppy,dmask=0007,fmask=0117" when a vfat filesystem
+# is mounted.
+FS_MOUNTOPTIONS="fstype=vfat,utf8,uid=1000,gid=1000,umask=022 -fstype=ntfs-3g,nls=utf8,uid=1000,gid=1000,umask=022"
+
+# If set to "yes", more information will be logged via the syslog
+# facility.
+VERBOSE=no
diff --git a/buildroot-external/rootfs-overlay/base/media/rfs/ro/.empty b/buildroot-external/rootfs-overlay/base/media/rfs/ro/.empty
new file mode 100644
index 00000000..e69de29b
diff --git a/buildroot-external/rootfs-overlay/base/media/rfs/rw/.empty b/buildroot-external/rootfs-overlay/base/media/rfs/rw/.empty
new file mode 100644
index 00000000..e69de29b
diff --git a/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/mnt-overlay.mount b/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/mnt-overlay.mount
deleted file mode 100644
index 35cdd502..00000000
--- a/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/mnt-overlay.mount
+++ /dev/null
@@ -1,15 +0,0 @@
-[Unit]
-Description=OpenVoiceOS overlay partition
-DefaultDependencies=no
-Before=umount.target local-fs.target
-Conflicts=umount.target
-After=systemd-fsck@dev-disk-by\x2dpartlabel-overlay\x2dbind.service
-Wants=systemd-fsck@dev-disk-by\x2dpartlabel-overlay\x2dbind.service
-
-[Mount]
-What=/dev/disk/by-partlabel/overlayfs
-Where=/mnt/overlay
-Type=ext4
-
-[Install]
-WantedBy=local-fs.target
diff --git a/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.service b/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.service
deleted file mode 100644
index 46abe26d..00000000
--- a/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.service
+++ /dev/null
@@ -1,15 +0,0 @@
-[Unit]
-Description=OpenVoiceOS rootfs r/w overlay setup
-DefaultDependencies=no
-RefuseManualStart=true
-RefuseManualStop=true
-Before=overlay-bind.target
-After=mnt-overlay.mount
-
-[Service]
-Type=oneshot
-ExecStart=/usr/libexec/overlay-setup
-RemainAfterExit=true
-
-[Install]
-WantedBy=local-fs.target
diff --git a/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.target b/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.target
deleted file mode 100644
index f35560ff..00000000
--- a/buildroot-external/rootfs-overlay/base/usr/lib/systemd/system/overlay-bind.target
+++ /dev/null
@@ -1,7 +0,0 @@
-[Unit]
-Description=OpenVoiceOS rootfs r/w overlay target
-Documentation=man:systemd.target(5)
-Before=sysinit.target
-
-[Install]
-WantedBy=multi-user.target
diff --git a/buildroot-external/rootfs-overlay/base/usr/lib/tmpfiles.d/samba.conf b/buildroot-external/rootfs-overlay/base/usr/lib/tmpfiles.d/samba.conf
new file mode 100644
index 00000000..e497ec38
--- /dev/null
+++ b/buildroot-external/rootfs-overlay/base/usr/lib/tmpfiles.d/samba.conf
@@ -0,0 +1,2 @@
+d /run/samba 755 root root
+d /log/samba 755 root root
diff --git a/buildroot-external/rootfs-overlay/base/usr/lib/udev/rules.d/usbmount.rules b/buildroot-external/rootfs-overlay/base/usr/lib/udev/rules.d/usbmount.rules
new file mode 100644
index 00000000..8c16632c
--- /dev/null
+++ b/buildroot-external/rootfs-overlay/base/usr/lib/udev/rules.d/usbmount.rules
@@ -0,0 +1,19 @@
+# Rules for USBmount -*- conf -*-
+
+# Do not auto mount our own system partitions
+ENV{ID_PART_ENTRY_NAME}=="boot", GOTO="END"
+ENV{ID_PART_ENTRY_UUID}=="9262aee5-2d23-4e09-baac-280591e2e834", GOTO="END"
+ENV{ID_PART_ENTRY_NAME}=="rootfs", GOTO="END"
+ENV{ID_PART_ENTRY_UUID}=="c0932a41-44cf-463b-8152-d43188553ed4", GOTO="END"
+ENV{ID_PART_ENTRY_NAME}=="overlayfs", GOTO="END"
+ENV{ID_PART_ENTRY_UUID}=="f1326040-5236-40eb-b683-aaa100a9afcf", GOTO="END"
+
+KERNEL=="sd*", DRIVERS=="sbp2", ACTION=="add", RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="sd*", SUBSYSTEM=="block", ACTION=="add", RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="ub*", SUBSYSTEM=="block", ACTION=="add", RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="mmcblk*", SUBSYSTEM=="block", ACTION=="add", RUN+="/usr/share/usbmount/usbmount add"
+KERNEL=="sd*", ACTION=="remove", RUN+="/usr/share/usbmount/usbmount remove"
+KERNEL=="ub*", ACTION=="remove", RUN+="/usr/share/usbmount/usbmount remove"
+KERNEL=="mmcblk*", ACTION=="remove", RUN+="/usr/share/usbmount/usbmount remove"
+
+LABEL="END"
diff --git a/buildroot-external/rootfs-overlay/base/usr/share/usbmount/usbmount b/buildroot-external/rootfs-overlay/base/usr/share/usbmount/usbmount
new file mode 100755
index 00000000..51fe1343
--- /dev/null
+++ b/buildroot-external/rootfs-overlay/base/usr/share/usbmount/usbmount
@@ -0,0 +1,199 @@
+#!/bin/sh
+# This script mounts USB mass storage devices when they are plugged in
+# and unmounts them when they are removed.
+# Copyright © 2004, 2005 Martin Dickopp
+# Copyright © 2008, 2009, 2010 Rogério Theodoro de Brito
+#
+# This file is free software; the copyright holder gives unlimited
+# permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+#
+set -e
+exec > /dev/null 2>&1
+
+######################################################################
+# Auxiliary functions
+
+# Log a string via the syslog facility.
+log()
+{
+ if [ $1 != debug ] || expr "$VERBOSE" : "[yY]" > /dev/null; then
+ logger -p user.$1 -t "usbmount[$$]" -- "$2"
+ fi
+}
+
+
+# Test if the first parameter is in the list given by the second
+# parameter.
+in_list()
+{
+ for v in $2; do
+ [ "$1" != "$v" ] || return 0
+ done
+ return 1
+}
+
+
+######################################################################
+# Main program
+
+# Default values for configuration variables.
+ENABLED=1
+MOUNTPOINTS=
+FILESYSTEMS=
+MOUNTOPTIONS=
+FS_MOUNTOPTIONS=
+VERBOSE=no
+
+if [ -r /etc/usbmount/usbmount.conf ]; then
+ . /etc/usbmount/usbmount.conf
+ log debug "loaded usbmount configurations"
+fi
+
+if [ "${ENABLED:-1}" -eq 0 ]; then
+ log info "usbmount is disabled, see /etc/usbmount/usbmount.conf"
+ exit 0
+fi
+
+# Per Policy 9.3.2, directories under /run have to be created
+# after every reboot.
+if [ ! -e /run/usbmount ]; then
+ mkdir -p /run/usbmount
+ log debug "creating /run/usbmount directory"
+fi
+
+umask 022
+
+
+if [ "$1" = add ]; then
+
+ # Acquire lock.
+ log debug "trying to acquire lock /run/usbmount/.mount.lock"
+ lockfile-create --retry 3 /run/usbmount/.mount || \
+ { log err "cannot acquire lock /run/usbmount/.mount.lock"; exit 1; }
+ trap '( lockfile-remove /run/usbmount/.mount )' 0
+ log debug "acquired lock /run/usbmount/.mount.lock"
+
+ if ! echo $ID_FS_USAGE | egrep -q "(filesystem|disklabel)"; then
+ log info "$DEVNAME does not contain a filesystem or disklabel"
+ exit 1
+ fi
+
+ # Try to use specifications in /etc/fstab first.
+ if egrep -q "^[[:blank:]]*$DEVNAME" /etc/fstab; then
+ log info "executing command: mount $DEVNAME"
+ mount $DEVNAME || log err "mount by DEVNAME with $DEVNAME wasn't successful; return code $?"
+
+ elif grep -q "^[[:blank:]]*UUID=$ID_FS_UUID" /etc/fstab; then
+ log info "executing command: mount -U $ID_FS_UUID"
+ mount -U $ID_FS_UUID || log err "mount by UUID with $ID_FS_UUID wasn't successful; return code $?"
+
+ else
+ log debug "$DEVNAME contains filesystem type $ID_FS_TYPE"
+
+ fstype=$ID_FS_TYPE
+ # Test if the filesystem type is in the list of filesystem
+ # types to mount.
+ if in_list "$fstype" "$FILESYSTEMS"; then
+ # Search an available mountpoint.
+ for v in $MOUNTPOINTS; do
+ if [ -d "$v" ] && ! grep -q "^[^ ][^ ]* *$v " /proc/mounts; then
+ mountpoint="$v"
+ log debug "mountpoint $mountpoint is available for $DEVNAME"
+ break
+ fi
+ done
+ if [ -n "$mountpoint" ]; then
+ # Determine mount options.
+ options=
+ for v in $FS_MOUNTOPTIONS; do
+ if expr "$v" : "-fstype=$fstype,."; then
+ options="$(echo "$v" | sed 's/^[^,]*,//')"
+ break
+ fi
+ done
+ if [ -n "$MOUNTOPTIONS" ]; then
+ options="$MOUNTOPTIONS${options:+,$options}"
+ fi
+
+ # Mount the filesystem.
+ log info "executing command: mount -t$fstype ${options:+-o$options} $DEVNAME $mountpoint"
+ mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint"
+
+ # Determine vendor and model.
+ vendor=
+ if [ -r "/sys$DEVPATH/device/vendor" ]; then
+ vendor="`cat \"/sys$DEVPATH/device/vendor\"`"
+ elif [ -r "/sys$DEVPATH/../device/vendor" ]; then
+ vendor="`cat \"/sys$DEVPATH/../device/vendor\"`"
+ elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then
+ vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`"
+ elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then
+ vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`"
+ fi
+ vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
+
+ model=
+ if [ -r "/sys$DEVPATH/device/model" ]; then
+ model="`cat \"/sys$DEVPATH/device/model\"`"
+ elif [ -r "/sys$DEVPATH/../device/model" ]; then
+ model="`cat \"/sys$DEVPATH/../device/model\"`"
+ elif [ -r "/sys$DEVPATH/device/../product" ]; then
+ model="`cat \"/sys$DEVPATH/device/../product\"`"
+ elif [ -r "/sys$DEVPATH/../device/../product" ]; then
+ model="`cat \"/sys$DEVPATH/../device/../product\"`"
+ fi
+ model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
+
+ # Run hook scripts; ignore errors.
+ export UM_DEVICE="$DEVNAME"
+ export UM_UUID="$ID_FS_UUID"
+ export UM_MOUNTPOINT="$mountpoint"
+ export UM_FILESYSTEM="$fstype"
+ export UM_MOUNTOPTIONS="$options"
+ export UM_VENDOR="$vendor"
+ export UM_MODEL="$model"
+ export UM_LABEL="$ID_FS_LABEL"
+ log info "executing command: run-parts /etc/usbmount/mount.d"
+ run-parts /etc/usbmount/mount.d || :
+ else
+ # No suitable mount point found.
+ log warning "no mountpoint found for $DEVNAME"
+ exit 1
+ fi
+ fi
+ fi
+elif [ "$1" = remove ]; then
+
+ # A block or partition device has been removed.
+ # Test if it is mounted.
+ while read device mountpoint fstype remainder; do
+ if [ "$DEVNAME" = "$device" ]; then
+ # If the mountpoint and filesystem type are maintained by
+ # this script, unmount the filesystem.
+ if in_list "$mountpoint" "$MOUNTPOINTS" &&
+ in_list "$fstype" "$FILESYSTEMS"; then
+ log info "executing command: umount -l $mountpoint"
+ umount -l "$mountpoint"
+
+ # Run hook scripts; ignore errors.
+ export UM_DEVICE="$DEVNAME"
+ export UM_MOUNTPOINT="$mountpoint"
+ export UM_FILESYSTEM="$fstype"
+ log info "executing command: run-parts /etc/usbmount/umount.d"
+ run-parts /etc/usbmount/umount.d || :
+ fi
+ break
+ fi
+ done < /proc/mounts
+else
+ log err "unexpected: action '$1'"
+ exit 1
+fi
+
+log debug "usbmount execution finished"