Setup installation
This commit is contained in:
490
examples/smb-configuration/setup-smb.sh
Normal file
490
examples/smb-configuration/setup-smb.sh
Normal file
@@ -0,0 +1,490 @@
|
||||
#!/bin/bash
|
||||
# USB-SSD Management System - SMB Setup Script
|
||||
# Automatische Konfiguration von Samba für USB-C SSD Freigaben
|
||||
#
|
||||
# Verwendung:
|
||||
# sudo ./setup-smb.sh [OPTIONS]
|
||||
#
|
||||
# Optionen:
|
||||
# --install-samba Samba-Pakete installieren
|
||||
# --configure-users Benutzer und Gruppen konfigurieren
|
||||
# --setup-shares Freigaben konfigurieren
|
||||
# --enable-services Services aktivieren und starten
|
||||
# --all Alle Schritte ausführen
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ============================================================================
|
||||
# Konfiguration
|
||||
# ============================================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SMB_CONF="/etc/samba/smb.conf"
|
||||
SMB_CONF_BACKUP="/etc/samba/smb.conf.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
SSD_MOUNT_POINT="/mnt/ssd-storage"
|
||||
LOG_FILE="/var/log/ssd-smb-setup.log"
|
||||
|
||||
# Farben für Output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# ============================================================================
|
||||
# Logging-Funktionen
|
||||
# ============================================================================
|
||||
|
||||
log() {
|
||||
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] $1${NC}" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] WARNING: $1${NC}" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: $1${NC}" | tee -a "$LOG_FILE"
|
||||
exit 1
|
||||
}
|
||||
|
||||
info() {
|
||||
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')] INFO: $1${NC}" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Hilfsfunktionen
|
||||
# ============================================================================
|
||||
|
||||
check_root() {
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
error "Dieses Script muss als root ausgeführt werden (sudo)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_mount_point() {
|
||||
if [[ ! -d "$SSD_MOUNT_POINT" ]]; then
|
||||
warn "Mount-Point $SSD_MOUNT_POINT existiert nicht - wird erstellt"
|
||||
mkdir -p "$SSD_MOUNT_POINT"
|
||||
chmod 755 "$SSD_MOUNT_POINT"
|
||||
fi
|
||||
}
|
||||
|
||||
detect_os() {
|
||||
if [[ -f /etc/os-release ]]; then
|
||||
. /etc/os-release
|
||||
OS=$ID
|
||||
VERSION=$VERSION_ID
|
||||
else
|
||||
error "Betriebssystem konnte nicht erkannt werden"
|
||||
fi
|
||||
|
||||
log "Erkanntes OS: $OS $VERSION"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Samba-Installation
|
||||
# ============================================================================
|
||||
|
||||
install_samba() {
|
||||
log "Installiere Samba-Pakete..."
|
||||
|
||||
case "$OS" in
|
||||
ubuntu|debian)
|
||||
apt update
|
||||
apt install -y samba samba-common-bin smbclient cifs-utils
|
||||
;;
|
||||
centos|rhel|fedora)
|
||||
if command -v dnf &> /dev/null; then
|
||||
dnf install -y samba samba-common samba-client cifs-utils
|
||||
else
|
||||
yum install -y samba samba-common samba-client cifs-utils
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
error "Nicht unterstütztes Betriebssystem: $OS"
|
||||
;;
|
||||
esac
|
||||
|
||||
log "Samba-Installation abgeschlossen"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Benutzer und Gruppen
|
||||
# ============================================================================
|
||||
|
||||
configure_users() {
|
||||
log "Konfiguriere Benutzer und Gruppen..."
|
||||
|
||||
# Gruppen erstellen
|
||||
local groups=(
|
||||
"ssd-users:Benutzer mit SSD-Zugriff"
|
||||
"ssd-admins:SSD-Administratoren"
|
||||
"ssd-readonly:Nur-Lese-Zugriff auf SSD"
|
||||
"backup-users:Backup-Benutzer"
|
||||
"backup-admins:Backup-Administratoren"
|
||||
"media-users:Media-Benutzer"
|
||||
"developers:Entwickler"
|
||||
"dev-leads:Entwicklungsleiter"
|
||||
"archive-admins:Archiv-Administratoren"
|
||||
)
|
||||
|
||||
for group_info in "${groups[@]}"; do
|
||||
local group_name="${group_info%%:*}"
|
||||
local group_desc="${group_info##*:}"
|
||||
|
||||
if ! getent group "$group_name" &>/dev/null; then
|
||||
groupadd "$group_name"
|
||||
log "Gruppe erstellt: $group_name ($group_desc)"
|
||||
else
|
||||
info "Gruppe existiert bereits: $group_name"
|
||||
fi
|
||||
done
|
||||
|
||||
# Standard-Benutzer zu ssd-users hinzufügen
|
||||
if [[ -n "${SUDO_USER:-}" ]]; then
|
||||
usermod -a -G ssd-users "$SUDO_USER"
|
||||
log "Benutzer $SUDO_USER zu ssd-users hinzugefügt"
|
||||
fi
|
||||
|
||||
# Service-Benutzer erstellen
|
||||
if ! id "ssd-service" &>/dev/null; then
|
||||
useradd -r -s /bin/false -d /var/lib/ssd-service -c "SSD Service User" ssd-service
|
||||
usermod -a -G ssd-users ssd-service
|
||||
log "Service-Benutzer ssd-service erstellt"
|
||||
fi
|
||||
|
||||
log "Benutzer- und Gruppen-Konfiguration abgeschlossen"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Verzeichnis-Struktur
|
||||
# ============================================================================
|
||||
|
||||
setup_directories() {
|
||||
log "Erstelle Verzeichnis-Struktur..."
|
||||
|
||||
local directories=(
|
||||
"$SSD_MOUNT_POINT"
|
||||
"$SSD_MOUNT_POINT/backup"
|
||||
"$SSD_MOUNT_POINT/archive"
|
||||
"$SSD_MOUNT_POINT/media"
|
||||
"$SSD_MOUNT_POINT/development"
|
||||
"$SSD_MOUNT_POINT/temp"
|
||||
"$SSD_MOUNT_POINT/home"
|
||||
)
|
||||
|
||||
for dir in "${directories[@]}"; do
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
mkdir -p "$dir"
|
||||
log "Verzeichnis erstellt: $dir"
|
||||
fi
|
||||
done
|
||||
|
||||
# Berechtigungen setzen
|
||||
chown -R root:ssd-users "$SSD_MOUNT_POINT"
|
||||
chmod -R 775 "$SSD_MOUNT_POINT"
|
||||
|
||||
# Spezielle Berechtigungen
|
||||
chmod 755 "$SSD_MOUNT_POINT/backup"
|
||||
chown root:backup-users "$SSD_MOUNT_POINT/backup"
|
||||
|
||||
chmod 755 "$SSD_MOUNT_POINT/archive"
|
||||
chown root:archive-admins "$SSD_MOUNT_POINT/archive"
|
||||
|
||||
chmod 777 "$SSD_MOUNT_POINT/temp"
|
||||
|
||||
log "Verzeichnis-Struktur konfiguriert"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# SMB-Konfiguration
|
||||
# ============================================================================
|
||||
|
||||
backup_smb_config() {
|
||||
if [[ -f "$SMB_CONF" ]]; then
|
||||
cp "$SMB_CONF" "$SMB_CONF_BACKUP"
|
||||
log "SMB-Konfiguration gesichert: $SMB_CONF_BACKUP"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_smb_config() {
|
||||
log "Konfiguriere Samba..."
|
||||
|
||||
backup_smb_config
|
||||
|
||||
# Neue Konfiguration kopieren
|
||||
if [[ -f "$SCRIPT_DIR/smb.conf.example" ]]; then
|
||||
cp "$SCRIPT_DIR/smb.conf.example" "$SMB_CONF"
|
||||
log "SMB-Konfiguration installiert"
|
||||
else
|
||||
error "SMB-Konfigurationsdatei nicht gefunden: $SCRIPT_DIR/smb.conf.example"
|
||||
fi
|
||||
|
||||
# Mount-Point in Konfiguration anpassen
|
||||
sed -i "s|/mnt/ssd-storage|$SSD_MOUNT_POINT|g" "$SMB_CONF"
|
||||
|
||||
# Konfiguration validieren
|
||||
if testparm -s "$SMB_CONF" &>/dev/null; then
|
||||
log "SMB-Konfiguration ist gültig"
|
||||
else
|
||||
error "SMB-Konfiguration ist ungültig"
|
||||
fi
|
||||
|
||||
log "SMB-Konfiguration abgeschlossen"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Service-Konfiguration
|
||||
# ============================================================================
|
||||
|
||||
enable_services() {
|
||||
log "Aktiviere und starte Services..."
|
||||
|
||||
local services=("smbd" "nmbd")
|
||||
|
||||
for service in "${services[@]}"; do
|
||||
systemctl enable "$service"
|
||||
systemctl restart "$service"
|
||||
|
||||
if systemctl is-active --quiet "$service"; then
|
||||
log "Service $service ist aktiv"
|
||||
else
|
||||
error "Service $service konnte nicht gestartet werden"
|
||||
fi
|
||||
done
|
||||
|
||||
# Firewall-Konfiguration (falls UFW aktiv)
|
||||
if command -v ufw &> /dev/null && ufw status | grep -q "Status: active"; then
|
||||
ufw allow samba
|
||||
log "Firewall-Regel für Samba hinzugefügt"
|
||||
fi
|
||||
|
||||
log "Service-Konfiguration abgeschlossen"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Benutzer-Setup
|
||||
# ============================================================================
|
||||
|
||||
setup_samba_users() {
|
||||
log "Konfiguriere Samba-Benutzer..."
|
||||
|
||||
# Aktueller Benutzer (falls vorhanden)
|
||||
if [[ -n "${SUDO_USER:-}" ]]; then
|
||||
echo "Samba-Passwort für Benutzer $SUDO_USER setzen:"
|
||||
smbpasswd -a "$SUDO_USER"
|
||||
smbpasswd -e "$SUDO_USER"
|
||||
log "Samba-Benutzer $SUDO_USER konfiguriert"
|
||||
fi
|
||||
|
||||
# Service-Benutzer (ohne Passwort-Login)
|
||||
smbpasswd -a ssd-service -n
|
||||
smbpasswd -d ssd-service
|
||||
|
||||
log "Samba-Benutzer-Konfiguration abgeschlossen"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Tests und Validierung
|
||||
# ============================================================================
|
||||
|
||||
test_smb_config() {
|
||||
log "Teste SMB-Konfiguration..."
|
||||
|
||||
# Konfiguration testen
|
||||
if ! testparm -s &>/dev/null; then
|
||||
error "SMB-Konfiguration ist ungültig"
|
||||
fi
|
||||
|
||||
# Services testen
|
||||
for service in smbd nmbd; do
|
||||
if ! systemctl is-active --quiet "$service"; then
|
||||
error "Service $service ist nicht aktiv"
|
||||
fi
|
||||
done
|
||||
|
||||
# Freigaben testen
|
||||
if ! smbclient -L localhost -N &>/dev/null; then
|
||||
warn "SMB-Freigaben sind nicht erreichbar"
|
||||
else
|
||||
log "SMB-Freigaben sind erreichbar"
|
||||
fi
|
||||
|
||||
log "SMB-Tests abgeschlossen"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Cleanup und Wartung
|
||||
# ============================================================================
|
||||
|
||||
setup_maintenance() {
|
||||
log "Konfiguriere Wartungs-Scripts..."
|
||||
|
||||
# Temp-Verzeichnis Cleanup
|
||||
cat > /etc/cron.daily/ssd-temp-cleanup << 'EOF'
|
||||
#!/bin/bash
|
||||
# Bereinige temporäre SSD-Dateien (älter als 7 Tage)
|
||||
find /mnt/ssd-storage/temp -type f -mtime +7 -delete 2>/dev/null || true
|
||||
find /mnt/ssd-storage/temp -type d -empty -delete 2>/dev/null || true
|
||||
EOF
|
||||
|
||||
chmod +x /etc/cron.daily/ssd-temp-cleanup
|
||||
|
||||
# Log-Rotation für SMB-Logs
|
||||
cat > /etc/logrotate.d/ssd-smb << 'EOF'
|
||||
/var/log/samba/*.log {
|
||||
daily
|
||||
rotate 30
|
||||
compress
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
create 644 root root
|
||||
postrotate
|
||||
systemctl reload smbd nmbd 2>/dev/null || true
|
||||
endscript
|
||||
}
|
||||
EOF
|
||||
|
||||
log "Wartungs-Scripts konfiguriert"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# Hauptfunktionen
|
||||
# ============================================================================
|
||||
|
||||
show_usage() {
|
||||
cat << EOF
|
||||
USB-SSD SMB Setup Script
|
||||
|
||||
Verwendung: $0 [OPTIONEN]
|
||||
|
||||
Optionen:
|
||||
--install-samba Samba-Pakete installieren
|
||||
--configure-users Benutzer und Gruppen konfigurieren
|
||||
--setup-shares Freigaben konfigurieren
|
||||
--enable-services Services aktivieren und starten
|
||||
--all Alle Schritte ausführen
|
||||
--help Diese Hilfe anzeigen
|
||||
|
||||
Beispiele:
|
||||
$0 --all # Vollständige Installation
|
||||
$0 --install-samba # Nur Samba installieren
|
||||
$0 --configure-users # Nur Benutzer konfigurieren
|
||||
$0 --setup-shares # Nur Freigaben konfigurieren
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
local install_samba=false
|
||||
local configure_users=false
|
||||
local setup_shares=false
|
||||
local enable_services=false
|
||||
local all_steps=false
|
||||
|
||||
# Parameter parsen
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--install-samba)
|
||||
install_samba=true
|
||||
shift
|
||||
;;
|
||||
--configure-users)
|
||||
configure_users=true
|
||||
shift
|
||||
;;
|
||||
--setup-shares)
|
||||
setup_shares=true
|
||||
shift
|
||||
;;
|
||||
--enable-services)
|
||||
enable_services=true
|
||||
shift
|
||||
;;
|
||||
--all)
|
||||
all_steps=true
|
||||
shift
|
||||
;;
|
||||
--help)
|
||||
show_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
error "Unbekannte Option: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Wenn keine spezifischen Optionen, zeige Hilfe
|
||||
if [[ "$install_samba" == false && "$configure_users" == false && "$setup_shares" == false && "$enable_services" == false && "$all_steps" == false ]]; then
|
||||
show_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Root-Berechtigung prüfen
|
||||
check_root
|
||||
|
||||
# OS erkennen
|
||||
detect_os
|
||||
|
||||
# Mount-Point prüfen
|
||||
check_mount_point
|
||||
|
||||
# Log-Datei initialisieren
|
||||
mkdir -p "$(dirname "$LOG_FILE")"
|
||||
touch "$LOG_FILE"
|
||||
|
||||
log "USB-SSD SMB Setup gestartet"
|
||||
|
||||
# Schritte ausführen
|
||||
if [[ "$all_steps" == true || "$install_samba" == true ]]; then
|
||||
install_samba
|
||||
fi
|
||||
|
||||
if [[ "$all_steps" == true || "$configure_users" == true ]]; then
|
||||
configure_users
|
||||
setup_directories
|
||||
fi
|
||||
|
||||
if [[ "$all_steps" == true || "$setup_shares" == true ]]; then
|
||||
setup_smb_config
|
||||
setup_samba_users
|
||||
setup_maintenance
|
||||
fi
|
||||
|
||||
if [[ "$all_steps" == true || "$enable_services" == true ]]; then
|
||||
enable_services
|
||||
test_smb_config
|
||||
fi
|
||||
|
||||
log "USB-SSD SMB Setup abgeschlossen"
|
||||
|
||||
# Zusammenfassung
|
||||
cat << EOF
|
||||
|
||||
${GREEN}=== Setup-Zusammenfassung ===${NC}
|
||||
|
||||
SMB-Freigaben:
|
||||
- //$(hostname)/ssd-storage (Haupt-Freigabe)
|
||||
- //$(hostname)/ssd-backup (Backup-Speicher)
|
||||
- //$(hostname)/ssd-archive (Archiv, Read-Only)
|
||||
- //$(hostname)/ssd-media (Media-Dateien)
|
||||
- //$(hostname)/ssd-dev (Entwicklung)
|
||||
- //$(hostname)/ssd-temp (Temporäre Dateien)
|
||||
|
||||
Nächste Schritte:
|
||||
1. USB-SSD anschließen und mounten: ssd-mount-manager.sh mount
|
||||
2. SMB-Freigaben testen: smbclient -L localhost -U $USER
|
||||
3. Von Windows: \\\\$(hostname)\\ssd-storage
|
||||
|
||||
Log-Datei: $LOG_FILE
|
||||
Konfiguration: $SMB_CONF
|
||||
Backup: $SMB_CONF_BACKUP
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Script ausführen
|
||||
main "$@"
|
338
examples/smb-configuration/smb.conf.example
Normal file
338
examples/smb-configuration/smb.conf.example
Normal file
@@ -0,0 +1,338 @@
|
||||
# USB-SSD Management System - SMB Configuration Example
|
||||
# Optimierte Samba-Konfiguration für USB-C SSD Freigaben
|
||||
#
|
||||
# Installation:
|
||||
# sudo cp smb.conf.example /etc/samba/smb.conf
|
||||
# sudo systemctl restart smbd nmbd
|
||||
# sudo smbpasswd -a $USER
|
||||
|
||||
# ============================================================================
|
||||
# Global Configuration
|
||||
# ============================================================================
|
||||
|
||||
[global]
|
||||
# Server-Identifikation
|
||||
workgroup = WORKGROUP
|
||||
server string = USB-SSD File Server
|
||||
netbios name = SSD-SERVER
|
||||
|
||||
# Protokoll-Versionen (SMB2/3 für bessere Performance)
|
||||
server min protocol = SMB2
|
||||
server max protocol = SMB3
|
||||
client min protocol = SMB2
|
||||
client max protocol = SMB3
|
||||
|
||||
# Security-Konfiguration
|
||||
security = user
|
||||
map to guest = bad user
|
||||
guest account = nobody
|
||||
|
||||
# Logging
|
||||
log file = /var/log/samba/log.%m
|
||||
log level = 1
|
||||
max log size = 1000
|
||||
|
||||
# Performance-Optimierungen
|
||||
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
|
||||
read raw = yes
|
||||
write raw = yes
|
||||
max xmit = 65535
|
||||
dead time = 15
|
||||
getwd cache = yes
|
||||
|
||||
# Unicode und Charset
|
||||
unix charset = UTF-8
|
||||
display charset = UTF-8
|
||||
dos charset = CP850
|
||||
|
||||
# Erweiterte Attribute für NTFS-Kompatibilität
|
||||
ea support = yes
|
||||
store dos attributes = yes
|
||||
map archive = no
|
||||
map hidden = no
|
||||
map read only = no
|
||||
map system = no
|
||||
|
||||
# Locking-Optimierungen
|
||||
kernel oplocks = no
|
||||
level2 oplocks = yes
|
||||
oplocks = yes
|
||||
|
||||
# Name-Resolution
|
||||
name resolve order = lmhosts wins bcast host
|
||||
dns proxy = no
|
||||
|
||||
# Printing (deaktiviert für SSD-Server)
|
||||
load printers = no
|
||||
printing = bsd
|
||||
printcap name = /dev/null
|
||||
disable spoolss = yes
|
||||
|
||||
# ============================================================================
|
||||
# USB-SSD Storage Share
|
||||
# ============================================================================
|
||||
|
||||
[ssd-storage]
|
||||
# Basis-Konfiguration
|
||||
comment = USB-C SSD Storage
|
||||
path = /mnt/ssd-storage
|
||||
browseable = yes
|
||||
writable = yes
|
||||
guest ok = no
|
||||
|
||||
# Benutzer-Zugriff
|
||||
valid users = @ssd-users, @disk
|
||||
admin users = @ssd-admins
|
||||
write list = @ssd-users
|
||||
read list = @ssd-users, @ssd-readonly
|
||||
|
||||
# Permissions
|
||||
create mask = 0664
|
||||
directory mask = 0775
|
||||
force create mode = 0664
|
||||
force directory mode = 0775
|
||||
force user = ssd-user
|
||||
force group = ssd-users
|
||||
|
||||
# Performance-Optimierungen für USB-SSD
|
||||
strict allocate = yes
|
||||
allocation roundup size = 1048576
|
||||
read raw = yes
|
||||
write raw = yes
|
||||
|
||||
# NTFS-Kompatibilität
|
||||
store dos attributes = yes
|
||||
map archive = no
|
||||
map hidden = no
|
||||
map read only = no
|
||||
map system = no
|
||||
|
||||
# Erweiterte Attribute
|
||||
ea support = yes
|
||||
acl allow execute always = yes
|
||||
|
||||
# Locking für Multi-User Zugriff
|
||||
oplocks = yes
|
||||
level2 oplocks = yes
|
||||
kernel oplocks = no
|
||||
locking = yes
|
||||
strict locking = no
|
||||
|
||||
# Veto-Dateien (Systemdateien ausschließen)
|
||||
veto files = /._*/.DS_Store/Thumbs.db/desktop.ini/
|
||||
delete veto files = yes
|
||||
|
||||
# Recycle-Bin (optional)
|
||||
# vfs objects = recycle
|
||||
# recycle:repository = .recycle
|
||||
# recycle:keeptree = yes
|
||||
# recycle:versions = yes
|
||||
|
||||
# ============================================================================
|
||||
# Backup-spezifische Freigabe
|
||||
# ============================================================================
|
||||
|
||||
[ssd-backup]
|
||||
comment = USB-SSD Backup Storage
|
||||
path = /mnt/ssd-storage/backup
|
||||
browseable = yes
|
||||
writable = yes
|
||||
guest ok = no
|
||||
|
||||
# Nur Backup-Benutzer
|
||||
valid users = @backup-users
|
||||
admin users = @backup-admins
|
||||
write list = @backup-users
|
||||
|
||||
# Restriktive Permissions
|
||||
create mask = 0640
|
||||
directory mask = 0750
|
||||
force create mode = 0640
|
||||
force directory mode = 0750
|
||||
|
||||
# Backup-optimierte Einstellungen
|
||||
strict allocate = yes
|
||||
sync always = yes
|
||||
strict sync = yes
|
||||
|
||||
# Audit-Logging
|
||||
full_audit:prefix = %u|%I|%S
|
||||
full_audit:success = open opendir write unlink mkdir rmdir rename
|
||||
full_audit:failure = all
|
||||
vfs objects = full_audit
|
||||
|
||||
# ============================================================================
|
||||
# Read-Only Archive Share
|
||||
# ============================================================================
|
||||
|
||||
[ssd-archive]
|
||||
comment = USB-SSD Archive (Read-Only)
|
||||
path = /mnt/ssd-storage/archive
|
||||
browseable = yes
|
||||
writable = no
|
||||
guest ok = yes
|
||||
|
||||
# Read-Only Zugriff
|
||||
read only = yes
|
||||
write list = @archive-admins
|
||||
|
||||
# Optimiert für große Dateien
|
||||
read raw = yes
|
||||
large readwrite = yes
|
||||
|
||||
# Caching für bessere Performance
|
||||
kernel share modes = yes
|
||||
posix locking = no
|
||||
|
||||
# ============================================================================
|
||||
# Media-Server Integration
|
||||
# ============================================================================
|
||||
|
||||
[ssd-media]
|
||||
comment = USB-SSD Media Storage
|
||||
path = /mnt/ssd-storage/media
|
||||
browseable = yes
|
||||
writable = yes
|
||||
guest ok = yes
|
||||
|
||||
# Media-optimierte Einstellungen
|
||||
valid users = @media-users, guest
|
||||
write list = @media-admins
|
||||
|
||||
# Große Dateien optimiert
|
||||
read raw = yes
|
||||
write raw = yes
|
||||
large readwrite = yes
|
||||
|
||||
# Media-spezifische Veto-Files
|
||||
veto files = /._*/.DS_Store/Thumbs.db/.@__thumb/
|
||||
delete veto files = yes
|
||||
|
||||
# Streaming-Optimierungen
|
||||
strict allocate = no
|
||||
allocation roundup size = 4096
|
||||
|
||||
# DLNA/UPnP Kompatibilität
|
||||
store dos attributes = no
|
||||
map archive = no
|
||||
map hidden = no
|
||||
|
||||
# ============================================================================
|
||||
# Development Share
|
||||
# ============================================================================
|
||||
|
||||
[ssd-dev]
|
||||
comment = USB-SSD Development Storage
|
||||
path = /mnt/ssd-storage/development
|
||||
browseable = yes
|
||||
writable = yes
|
||||
guest ok = no
|
||||
|
||||
# Entwickler-Zugriff
|
||||
valid users = @developers
|
||||
admin users = @dev-leads
|
||||
write list = @developers
|
||||
|
||||
# Entwickler-freundliche Permissions
|
||||
create mask = 0664
|
||||
directory mask = 0775
|
||||
force create mode = 0664
|
||||
force directory mode = 0775
|
||||
|
||||
# Git-Repository Unterstützung
|
||||
store dos attributes = no
|
||||
map archive = no
|
||||
map hidden = no
|
||||
map read only = no
|
||||
map system = no
|
||||
|
||||
# Symlink-Unterstützung
|
||||
follow symlinks = yes
|
||||
wide links = no
|
||||
unix extensions = yes
|
||||
|
||||
# Case-Sensitivity für Entwicklung
|
||||
case sensitive = auto
|
||||
default case = lower
|
||||
preserve case = yes
|
||||
short preserve case = yes
|
||||
|
||||
# ============================================================================
|
||||
# Temporäre Freigabe
|
||||
# ============================================================================
|
||||
|
||||
[ssd-temp]
|
||||
comment = USB-SSD Temporary Storage
|
||||
path = /mnt/ssd-storage/temp
|
||||
browseable = yes
|
||||
writable = yes
|
||||
guest ok = yes
|
||||
|
||||
# Temporärer Zugriff
|
||||
valid users = @ssd-users, guest
|
||||
|
||||
# Temporäre Dateien
|
||||
create mask = 0666
|
||||
directory mask = 0777
|
||||
|
||||
# Automatische Bereinigung (via Cron)
|
||||
# 0 2 * * * find /mnt/ssd-storage/temp -type f -mtime +7 -delete
|
||||
|
||||
# Keine Attribute speichern
|
||||
store dos attributes = no
|
||||
ea support = no
|
||||
|
||||
# ============================================================================
|
||||
# Administrative Freigabe
|
||||
# ============================================================================
|
||||
|
||||
[ssd-admin]
|
||||
comment = USB-SSD Administrative Access
|
||||
path = /mnt/ssd-storage
|
||||
browseable = no
|
||||
writable = yes
|
||||
guest ok = no
|
||||
|
||||
# Nur Administratoren
|
||||
valid users = @ssd-admins
|
||||
admin users = @ssd-admins
|
||||
|
||||
# Vollzugriff
|
||||
create mask = 0664
|
||||
directory mask = 0775
|
||||
|
||||
# Audit-Logging für Admin-Zugriffe
|
||||
full_audit:prefix = ADMIN|%u|%I|%S
|
||||
full_audit:success = all
|
||||
full_audit:failure = all
|
||||
vfs objects = full_audit
|
||||
|
||||
# Erweiterte Funktionen
|
||||
ea support = yes
|
||||
acl allow execute always = yes
|
||||
nt acl support = yes
|
||||
|
||||
# ============================================================================
|
||||
# Homes-Integration (optional)
|
||||
# ============================================================================
|
||||
|
||||
[homes]
|
||||
comment = Home Directories on USB-SSD
|
||||
browseable = no
|
||||
writable = yes
|
||||
guest ok = no
|
||||
|
||||
# Benutzer-spezifische Pfade
|
||||
path = /mnt/ssd-storage/home/%S
|
||||
valid users = %S
|
||||
|
||||
# Standard-Permissions
|
||||
create mask = 0600
|
||||
directory mask = 0700
|
||||
|
||||
# Privacy-Einstellungen
|
||||
hide dot files = yes
|
||||
hide files = /desktop.ini/thumbs.db/
|
||||
|
||||
# Quota-Unterstützung (falls aktiviert)
|
||||
# preexec = /usr/local/bin/setup-user-quota.sh %S
|
287
examples/systemd-services/README.md
Normal file
287
examples/systemd-services/README.md
Normal file
@@ -0,0 +1,287 @@
|
||||
# Systemd Service Templates
|
||||
|
||||
## Übersicht
|
||||
|
||||
Diese Verzeichnis enthält Systemd-Service-Templates für die automatische Integration des USB-SSD Management Systems in die Linux-Systemd-Infrastruktur.
|
||||
|
||||
## Verfügbare Services
|
||||
|
||||
### `ssd-detection.service`
|
||||
**Zweck**: Kontinuierliche USB-C SSD Erkennung und Überwachung
|
||||
|
||||
**Funktionen**:
|
||||
- Automatische Erkennung neu angeschlossener SSDs
|
||||
- Kontinuierliche Überwachung im 5-Sekunden-Intervall
|
||||
- Integration mit udev-Events
|
||||
- Systemd-Journal Logging
|
||||
- Automatischer Restart bei Fehlern
|
||||
|
||||
**Installation**:
|
||||
```bash
|
||||
sudo cp ssd-detection.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable ssd-detection.service
|
||||
sudo systemctl start ssd-detection.service
|
||||
```
|
||||
|
||||
### `ssd-automount.service`
|
||||
**Zweck**: Automatisches Mounting erkannter SSDs
|
||||
|
||||
**Funktionen**:
|
||||
- Automatisches Mounting auf `/mnt/ssd-storage`
|
||||
- Abhängigkeit von `ssd-detection.service`
|
||||
- Graceful Shutdown mit Safe-Eject
|
||||
- Remount-Funktionalität
|
||||
- PID-File Management
|
||||
|
||||
**Installation**:
|
||||
```bash
|
||||
sudo cp ssd-automount.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable ssd-automount.service
|
||||
sudo systemctl start ssd-automount.service
|
||||
```
|
||||
|
||||
### `ssd-mount@.service`
|
||||
**Zweck**: Template-Service für spezifische Device-Mounting
|
||||
|
||||
**Funktionen**:
|
||||
- Template-basiertes Mounting für spezifische Devices
|
||||
- Device-Binding mit `BindsTo=`
|
||||
- Oneshot-Service mit `RemainAfterExit=yes`
|
||||
- Automatisches Cleanup bei Device-Entfernung
|
||||
|
||||
**Verwendung**:
|
||||
```bash
|
||||
# Service für spezifisches Device starten
|
||||
sudo systemctl start ssd-mount@sdb1.service
|
||||
|
||||
# Service für spezifisches Device aktivieren
|
||||
sudo systemctl enable ssd-mount@sdb1.service
|
||||
|
||||
# Status prüfen
|
||||
sudo systemctl status ssd-mount@sdb1.service
|
||||
```
|
||||
|
||||
## Service-Konfiguration
|
||||
|
||||
### Anpassung der Services
|
||||
|
||||
#### Environment-Variables
|
||||
```bash
|
||||
# Service-Konfiguration bearbeiten
|
||||
sudo systemctl edit ssd-detection.service
|
||||
|
||||
# Beispiel-Konfiguration:
|
||||
[Service]
|
||||
Environment=SSD_LOG_LEVEL=DEBUG
|
||||
Environment=SSD_MONITOR_INTERVAL=10
|
||||
Environment=SSD_USE_SYSLOG=true
|
||||
```
|
||||
|
||||
#### Mount-Point anpassen
|
||||
```bash
|
||||
# Automount-Service anpassen
|
||||
sudo systemctl edit ssd-automount.service
|
||||
|
||||
[Service]
|
||||
Environment=SSD_MOUNT_POINT=/custom/mount/point
|
||||
```
|
||||
|
||||
#### Security-Einstellungen
|
||||
```bash
|
||||
# Zusätzliche Security-Optionen
|
||||
sudo systemctl edit ssd-detection.service
|
||||
|
||||
[Service]
|
||||
# Zusätzliche Device-Zugriffe
|
||||
DeviceAllow=/dev/nvme* rw
|
||||
DeviceAllow=/dev/mmcblk* rw
|
||||
|
||||
# Zusätzliche Pfad-Zugriffe
|
||||
ReadWritePaths=/custom/path
|
||||
```
|
||||
|
||||
## Service-Management
|
||||
|
||||
### Standard-Operationen
|
||||
```bash
|
||||
# Services aktivieren
|
||||
sudo systemctl enable ssd-detection.service ssd-automount.service
|
||||
|
||||
# Services starten
|
||||
sudo systemctl start ssd-detection.service ssd-automount.service
|
||||
|
||||
# Status prüfen
|
||||
sudo systemctl status ssd-detection.service
|
||||
sudo systemctl status ssd-automount.service
|
||||
|
||||
# Services stoppen
|
||||
sudo systemctl stop ssd-detection.service ssd-automount.service
|
||||
|
||||
# Services deaktivieren
|
||||
sudo systemctl disable ssd-detection.service ssd-automount.service
|
||||
```
|
||||
|
||||
### Logs und Monitoring
|
||||
```bash
|
||||
# Service-Logs anzeigen
|
||||
sudo journalctl -u ssd-detection.service -f
|
||||
sudo journalctl -u ssd-automount.service --since "1 hour ago"
|
||||
|
||||
# Alle SSD-Services
|
||||
sudo journalctl -u "ssd-*" --since today
|
||||
|
||||
# Service-Status überwachen
|
||||
watch -n 5 'systemctl status ssd-detection.service ssd-automount.service'
|
||||
```
|
||||
|
||||
### Troubleshooting
|
||||
```bash
|
||||
# Service-Konfiguration validieren
|
||||
sudo systemd-analyze verify /etc/systemd/system/ssd-detection.service
|
||||
|
||||
# Service-Dependencies anzeigen
|
||||
sudo systemctl list-dependencies ssd-automount.service
|
||||
|
||||
# Failed-Services anzeigen
|
||||
sudo systemctl --failed | grep ssd
|
||||
|
||||
# Service neu starten
|
||||
sudo systemctl restart ssd-detection.service
|
||||
```
|
||||
|
||||
## Erweiterte Konfiguration
|
||||
|
||||
### Custom-Service erstellen
|
||||
```bash
|
||||
# Basis-Template kopieren
|
||||
sudo cp ssd-detection.service /etc/systemd/system/ssd-custom.service
|
||||
|
||||
# Service anpassen
|
||||
sudo nano /etc/systemd/system/ssd-custom.service
|
||||
|
||||
# Service aktivieren
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable ssd-custom.service
|
||||
```
|
||||
|
||||
### Multi-Device Support
|
||||
```bash
|
||||
# Template-Service für mehrere Devices
|
||||
sudo systemctl enable ssd-mount@sdb1.service
|
||||
sudo systemctl enable ssd-mount@sdc1.service
|
||||
sudo systemctl enable ssd-mount@sdd1.service
|
||||
|
||||
# Alle Template-Services starten
|
||||
sudo systemctl start ssd-mount@*.service
|
||||
```
|
||||
|
||||
### Timer-basierte Services
|
||||
```bash
|
||||
# Timer für regelmäßige Tests erstellen
|
||||
sudo nano /etc/systemd/system/ssd-test.service
|
||||
sudo nano /etc/systemd/system/ssd-test.timer
|
||||
|
||||
# Timer aktivieren
|
||||
sudo systemctl enable ssd-test.timer
|
||||
sudo systemctl start ssd-test.timer
|
||||
```
|
||||
|
||||
## Security-Konfiguration
|
||||
|
||||
### Hardening-Optionen
|
||||
```ini
|
||||
[Service]
|
||||
# Zusätzliche Security-Features
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectControlGroups=true
|
||||
RestrictRealtime=true
|
||||
RestrictSUIDSGID=true
|
||||
LockPersonality=true
|
||||
MemoryDenyWriteExecute=true
|
||||
RestrictNamespaces=true
|
||||
```
|
||||
|
||||
### Capability-Management
|
||||
```ini
|
||||
[Service]
|
||||
# Minimale Capabilities
|
||||
CapabilityBoundingSet=CAP_SYS_ADMIN CAP_DAC_OVERRIDE
|
||||
AmbientCapabilities=CAP_SYS_ADMIN CAP_DAC_OVERRIDE
|
||||
```
|
||||
|
||||
### User/Group-Konfiguration
|
||||
```bash
|
||||
# Dedicated Service-User erstellen
|
||||
sudo useradd -r -s /bin/false ssd-service
|
||||
sudo usermod -a -G disk ssd-service
|
||||
|
||||
# Service-Konfiguration anpassen
|
||||
[Service]
|
||||
User=ssd-service
|
||||
Group=disk
|
||||
```
|
||||
|
||||
## Integration mit anderen Services
|
||||
|
||||
### SMB-Integration
|
||||
```ini
|
||||
[Unit]
|
||||
# SMB-Service nach SSD-Mount starten
|
||||
Before=smbd.service
|
||||
PartOf=smbd.service
|
||||
|
||||
[Service]
|
||||
# SMB-Reload nach Mount
|
||||
ExecStartPost=/bin/systemctl reload-or-restart smbd.service
|
||||
```
|
||||
|
||||
### Backup-Integration
|
||||
```ini
|
||||
[Unit]
|
||||
# Backup-Service nach SSD-Mount starten
|
||||
Before=backup.service
|
||||
|
||||
[Service]
|
||||
# Backup-Trigger nach Mount
|
||||
ExecStartPost=/usr/local/bin/trigger-backup.sh
|
||||
```
|
||||
|
||||
### Monitoring-Integration
|
||||
```ini
|
||||
[Service]
|
||||
# Prometheus-Metriken exportieren
|
||||
ExecStartPost=/usr/local/bin/export-ssd-metrics.sh
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Produktionsumgebung
|
||||
1. **Immer `systemctl daemon-reload`** nach Service-Änderungen
|
||||
2. **Service-Dependencies** korrekt konfigurieren
|
||||
3. **Logging-Level** für Produktion auf INFO setzen
|
||||
4. **Security-Features** aktivieren
|
||||
5. **Monitoring** für Service-Status einrichten
|
||||
|
||||
### Entwicklungsumgebung
|
||||
1. **Debug-Logging** aktivieren
|
||||
2. **Manual-Start** für Tests verwenden
|
||||
3. **Service-Isolation** für Entwicklung
|
||||
4. **Frequent-Reload** für Änderungen
|
||||
|
||||
### Monitoring und Alerting
|
||||
1. **Systemd-Status** überwachen
|
||||
2. **Service-Logs** analysieren
|
||||
3. **Performance-Metriken** sammeln
|
||||
4. **Failure-Alerts** konfigurieren
|
||||
|
||||
## Changelog
|
||||
|
||||
### Version 0.1.0
|
||||
- Basis-Service Templates
|
||||
- Security-Hardening
|
||||
- Multi-Device Support
|
||||
- Integration-Beispiele
|
||||
- Comprehensive Documentation
|
45
examples/systemd-services/ssd-automount.service
Normal file
45
examples/systemd-services/ssd-automount.service
Normal file
@@ -0,0 +1,45 @@
|
||||
[Unit]
|
||||
Description=Automatic SSD Mounting Service
|
||||
Documentation=https://git.gitcover.de/KMU/usb-ssd
|
||||
After=ssd-detection.service
|
||||
Requires=ssd-detection.service
|
||||
BindsTo=ssd-detection.service
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart=/usr/local/bin/ssd-mount-manager.sh mount --auto-mount
|
||||
ExecStop=/usr/local/bin/ssd-safe-eject.sh --all
|
||||
ExecReload=/usr/local/bin/ssd-mount-manager.sh remount
|
||||
PIDFile=/var/run/ssd-automount.pid
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
TimeoutStartSec=60
|
||||
TimeoutStopSec=30
|
||||
|
||||
# Logging
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=ssd-automount
|
||||
|
||||
# Security
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/var/log /var/run /mnt /media
|
||||
PrivateTmp=true
|
||||
PrivateDevices=false
|
||||
DevicePolicy=closed
|
||||
DeviceAllow=/dev/sd* rw
|
||||
DeviceAllow=/dev/disk/by-uuid/* rw
|
||||
|
||||
# Environment
|
||||
Environment=SSD_LOG_LEVEL=INFO
|
||||
Environment=SSD_USE_SYSLOG=true
|
||||
Environment=SSD_AUTO_MOUNT=true
|
||||
Environment=SSD_MOUNT_POINT=/mnt/ssd-storage
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Also=ssd-detection.service
|
42
examples/systemd-services/ssd-detection.service
Normal file
42
examples/systemd-services/ssd-detection.service
Normal file
@@ -0,0 +1,42 @@
|
||||
[Unit]
|
||||
Description=USB-C SSD Detection Service
|
||||
Documentation=https://git.gitcover.de/KMU/usb-ssd
|
||||
After=local-fs.target
|
||||
Wants=systemd-udevd.service
|
||||
After=systemd-udevd.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart=/usr/local/bin/ssd-detect.sh --monitor --interval 5
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutStartSec=30
|
||||
TimeoutStopSec=10
|
||||
|
||||
# Logging
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=ssd-detection
|
||||
|
||||
# Security
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/var/log /var/run /mnt
|
||||
PrivateTmp=true
|
||||
PrivateDevices=false
|
||||
DevicePolicy=closed
|
||||
DeviceAllow=/dev/sd* rw
|
||||
DeviceAllow=/dev/disk/by-uuid/* rw
|
||||
|
||||
# Environment
|
||||
Environment=SSD_LOG_LEVEL=INFO
|
||||
Environment=SSD_USE_SYSLOG=true
|
||||
Environment=SSD_MONITOR_INTERVAL=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Alias=ssd-detect.service
|
38
examples/systemd-services/ssd-mount@.service
Normal file
38
examples/systemd-services/ssd-mount@.service
Normal file
@@ -0,0 +1,38 @@
|
||||
[Unit]
|
||||
Description=SSD Mount Manager for %i
|
||||
Documentation=https://git.gitcover.de/KMU/usb-ssd
|
||||
After=local-fs.target
|
||||
BindsTo=dev-%i.device
|
||||
After=dev-%i.device
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart=/usr/local/bin/ssd-mount-manager.sh mount --device /dev/%i
|
||||
ExecStop=/usr/local/bin/ssd-safe-eject.sh --device /dev/%i
|
||||
TimeoutStartSec=30
|
||||
TimeoutStopSec=15
|
||||
|
||||
# Logging
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=ssd-mount
|
||||
|
||||
# Security
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/var/log /var/run /mnt
|
||||
PrivateTmp=true
|
||||
PrivateDevices=false
|
||||
DevicePolicy=closed
|
||||
DeviceAllow=/dev/%i rw
|
||||
|
||||
# Environment
|
||||
Environment=SSD_LOG_LEVEL=INFO
|
||||
Environment=SSD_USE_SYSLOG=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
158
examples/udev-rules/99-ssd-automount.rules
Normal file
158
examples/udev-rules/99-ssd-automount.rules
Normal file
@@ -0,0 +1,158 @@
|
||||
# USB-SSD Management System - Udev Rules
|
||||
# Automatische Erkennung und Mounting von USB-C SSDs
|
||||
#
|
||||
# Installation:
|
||||
# sudo cp 99-ssd-automount.rules /etc/udev/rules.d/
|
||||
# sudo udevadm control --reload-rules
|
||||
# sudo udevadm trigger
|
||||
|
||||
# ============================================================================
|
||||
# USB Storage Device Detection
|
||||
# ============================================================================
|
||||
|
||||
# USB Mass Storage Devices - Automatische Erkennung
|
||||
SUBSYSTEM=="block", ATTRS{removable}=="1", ENV{ID_BUS}=="usb", ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --udev-mode"
|
||||
|
||||
# USB Storage Devices - Entfernung
|
||||
SUBSYSTEM=="block", ATTRS{removable}=="1", ENV{ID_BUS}=="usb", ACTION=="remove", \
|
||||
RUN+="/usr/local/bin/ssd-safe-eject.sh --device %k --udev-mode"
|
||||
|
||||
# ============================================================================
|
||||
# NTFS Filesystem Detection
|
||||
# ============================================================================
|
||||
|
||||
# NTFS Partitionen - Automatisches Mounting
|
||||
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_BUS}=="usb", ACTION=="add", \
|
||||
ATTRS{removable}=="1", \
|
||||
RUN+="/usr/local/bin/ssd-mount-manager.sh mount --device /dev/%k --auto-mount"
|
||||
|
||||
# exFAT Partitionen - Alternative Unterstützung
|
||||
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="exfat", ENV{ID_BUS}=="usb", ACTION=="add", \
|
||||
ATTRS{removable}=="1", \
|
||||
RUN+="/usr/local/bin/ssd-mount-manager.sh mount --device /dev/%k --auto-mount"
|
||||
|
||||
# ============================================================================
|
||||
# Device Permissions und Ownership
|
||||
# ============================================================================
|
||||
|
||||
# USB Storage Devices - Berechtigungen setzen
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
GROUP="disk", MODE="0660"
|
||||
|
||||
# Device-Nodes für SSD-Management Gruppe
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{ID_FS_TYPE}=="ntfs|exfat", \
|
||||
GROUP="ssd-users", MODE="0664"
|
||||
|
||||
# ============================================================================
|
||||
# Symlink Creation
|
||||
# ============================================================================
|
||||
|
||||
# Persistente Symlinks basierend auf UUID
|
||||
SUBSYSTEM=="block", ENV{ID_FS_UUID}!="", ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", \
|
||||
SYMLINK+="disk/by-ssd-uuid/$env{ID_FS_UUID}"
|
||||
|
||||
# Symlinks basierend auf Label
|
||||
SUBSYSTEM=="block", ENV{ID_FS_LABEL}!="", ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", \
|
||||
SYMLINK+="disk/by-ssd-label/$env{ID_FS_LABEL}"
|
||||
|
||||
# ============================================================================
|
||||
# Spezifische Vendor/Product Rules
|
||||
# ============================================================================
|
||||
|
||||
# Samsung USB-C SSDs
|
||||
SUBSYSTEM=="block", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="61f*", \
|
||||
ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --vendor samsung"
|
||||
|
||||
# SanDisk USB-C SSDs
|
||||
SUBSYSTEM=="block", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="55*", \
|
||||
ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --vendor sandisk"
|
||||
|
||||
# Generic USB 3.0+ Storage
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{bcdUSB}=="0300|0310|0320", \
|
||||
ATTRS{removable}=="1", ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --usb3-mode"
|
||||
|
||||
# ============================================================================
|
||||
# Environment Variables für Scripts
|
||||
# ============================================================================
|
||||
|
||||
# Udev-Modus für alle SSD-Scripts
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{SSD_UDEV_MODE}="true", \
|
||||
ENV{SSD_LOG_LEVEL}="INFO", \
|
||||
ENV{SSD_USE_SYSLOG}="true"
|
||||
|
||||
# Device-Informationen für Scripts
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{SSD_DEVICE_PATH}="/dev/%k", \
|
||||
ENV{SSD_DEVICE_UUID}="$env{ID_FS_UUID}", \
|
||||
ENV{SSD_DEVICE_LABEL}="$env{ID_FS_LABEL}", \
|
||||
ENV{SSD_DEVICE_TYPE}="$env{ID_FS_TYPE}"
|
||||
|
||||
# ============================================================================
|
||||
# Systemd Service Integration
|
||||
# ============================================================================
|
||||
|
||||
# Systemd-Service für spezifische Devices starten
|
||||
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", ACTION=="add", \
|
||||
TAG+="systemd", ENV{SYSTEMD_WANTS}="ssd-mount@%k.service"
|
||||
|
||||
# Systemd-Service bei Device-Entfernung stoppen
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/bin/systemctl stop ssd-mount@%k.service"
|
||||
|
||||
# ============================================================================
|
||||
# Logging und Debugging
|
||||
# ============================================================================
|
||||
|
||||
# Debug-Informationen loggen (nur bei Debug-Modus)
|
||||
# SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
# RUN+="/usr/bin/logger -t udev-ssd 'Device %k: Action=%E{ACTION}, Type=%E{ID_FS_TYPE}, UUID=%E{ID_FS_UUID}'"
|
||||
|
||||
# ============================================================================
|
||||
# Sicherheits-Rules
|
||||
# ============================================================================
|
||||
|
||||
# Nur autorisierte Benutzer können auf SSD-Devices zugreifen
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{ID_FS_TYPE}=="ntfs|exfat", \
|
||||
TEST!="/etc/ssd-management/authorized_users", \
|
||||
GROUP="root", MODE="0600"
|
||||
|
||||
# Blacklist für bekannte problematische Devices
|
||||
SUBSYSTEM=="block", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0000", \
|
||||
ENV{UDISKS_IGNORE}="1"
|
||||
|
||||
# ============================================================================
|
||||
# Performance-Optimierungen
|
||||
# ============================================================================
|
||||
|
||||
# I/O-Scheduler für USB-SSDs optimieren
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ATTR{queue/scheduler}="mq-deadline"
|
||||
|
||||
# Read-Ahead für USB-SSDs optimieren
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ATTR{queue/read_ahead_kb}="1024"
|
||||
|
||||
# ============================================================================
|
||||
# Cleanup und Maintenance
|
||||
# ============================================================================
|
||||
|
||||
# Alte Mount-Points bereinigen bei Device-Entfernung
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/usr/local/bin/ssd-mount-manager.sh cleanup --device %k"
|
||||
|
||||
# Temporäre Dateien bereinigen
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/bin/rm -f /tmp/ssd-%k-*"
|
343
examples/udev-rules/README.md
Normal file
343
examples/udev-rules/README.md
Normal file
@@ -0,0 +1,343 @@
|
||||
# Udev Rules für USB-SSD Management
|
||||
|
||||
## Übersicht
|
||||
|
||||
Diese Udev-Rules ermöglichen die automatische Erkennung und Verarbeitung von USB-C SSDs auf Linux-Systemen. Sie integrieren sich nahtlos mit dem USB-SSD Management System und bieten Hardware-Event-basierte Automatisierung.
|
||||
|
||||
## Verfügbare Rules
|
||||
|
||||
### `99-ssd-automount.rules`
|
||||
**Zweck**: Umfassende Udev-Rules für automatische SSD-Erkennung und -Management
|
||||
|
||||
**Hauptfunktionen**:
|
||||
- Automatische USB Storage Device Erkennung
|
||||
- NTFS/exFAT Filesystem Detection
|
||||
- Device-Permissions und Ownership Management
|
||||
- Persistente Symlink-Erstellung
|
||||
- Systemd-Service Integration
|
||||
- Performance-Optimierungen
|
||||
- Security-Features
|
||||
|
||||
## Installation
|
||||
|
||||
### Standard-Installation
|
||||
```bash
|
||||
# Rules-Datei kopieren
|
||||
sudo cp 99-ssd-automount.rules /etc/udev/rules.d/
|
||||
|
||||
# Udev-Rules neu laden
|
||||
sudo udevadm control --reload-rules
|
||||
|
||||
# Bestehende Devices neu triggern
|
||||
sudo udevadm trigger
|
||||
|
||||
# Installation verifizieren
|
||||
ls -la /etc/udev/rules.d/99-ssd-*
|
||||
```
|
||||
|
||||
### Test der Installation
|
||||
```bash
|
||||
# USB-SSD anschließen und Events überwachen
|
||||
sudo udevadm monitor --environment --udev
|
||||
|
||||
# Spezifisches Device testen
|
||||
sudo udevadm test /sys/block/sdb
|
||||
|
||||
# Rule-Syntax validieren
|
||||
sudo udevadm test --action=add /sys/block/sdb
|
||||
```
|
||||
|
||||
## Rule-Kategorien
|
||||
|
||||
### 1. USB Storage Device Detection
|
||||
```bash
|
||||
# Automatische Erkennung bei USB-Device-Anschluss
|
||||
SUBSYSTEM=="block", ATTRS{removable}=="1", ENV{ID_BUS}=="usb", ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --udev-mode"
|
||||
|
||||
# Automatische Behandlung bei Device-Entfernung
|
||||
SUBSYSTEM=="block", ATTRS{removable}=="1", ENV{ID_BUS}=="usb", ACTION=="remove", \
|
||||
RUN+="/usr/local/bin/ssd-safe-eject.sh --device %k --udev-mode"
|
||||
```
|
||||
|
||||
### 2. Filesystem-spezifische Rules
|
||||
```bash
|
||||
# NTFS-Partitionen automatisch mounten
|
||||
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_BUS}=="usb", ACTION=="add", \
|
||||
ATTRS{removable}=="1", \
|
||||
RUN+="/usr/local/bin/ssd-mount-manager.sh mount --device /dev/%k --auto-mount"
|
||||
|
||||
# exFAT-Support
|
||||
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="exfat", ENV{ID_BUS}=="usb", ACTION=="add", \
|
||||
ATTRS{removable}=="1", \
|
||||
RUN+="/usr/local/bin/ssd-mount-manager.sh mount --device /dev/%k --auto-mount"
|
||||
```
|
||||
|
||||
### 3. Device-Permissions
|
||||
```bash
|
||||
# Basis-Berechtigungen für USB Storage
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
GROUP="disk", MODE="0660"
|
||||
|
||||
# Erweiterte Berechtigungen für SSD-Management
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{ID_FS_TYPE}=="ntfs|exfat", \
|
||||
GROUP="ssd-users", MODE="0664"
|
||||
```
|
||||
|
||||
### 4. Symlink-Management
|
||||
```bash
|
||||
# UUID-basierte Symlinks
|
||||
SUBSYSTEM=="block", ENV{ID_FS_UUID}!="", ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", \
|
||||
SYMLINK+="disk/by-ssd-uuid/$env{ID_FS_UUID}"
|
||||
|
||||
# Label-basierte Symlinks
|
||||
SUBSYSTEM=="block", ENV{ID_FS_LABEL}!="", ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", \
|
||||
SYMLINK+="disk/by-ssd-label/$env{ID_FS_LABEL}"
|
||||
```
|
||||
|
||||
## Vendor-spezifische Rules
|
||||
|
||||
### Samsung USB-C SSDs
|
||||
```bash
|
||||
# Samsung-spezifische Erkennung
|
||||
SUBSYSTEM=="block", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="61f*", \
|
||||
ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --vendor samsung"
|
||||
```
|
||||
|
||||
### SanDisk USB-C SSDs
|
||||
```bash
|
||||
# SanDisk-spezifische Erkennung
|
||||
SUBSYSTEM=="block", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="55*", \
|
||||
ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --vendor sandisk"
|
||||
```
|
||||
|
||||
### Generic USB 3.0+ Storage
|
||||
```bash
|
||||
# USB 3.0+ Devices
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{bcdUSB}=="0300|0310|0320", \
|
||||
ATTRS{removable}=="1", ACTION=="add", \
|
||||
RUN+="/usr/local/bin/ssd-detect.sh --device %k --usb3-mode"
|
||||
```
|
||||
|
||||
## Systemd-Integration
|
||||
|
||||
### Service-Aktivierung
|
||||
```bash
|
||||
# Systemd-Service für spezifische Devices
|
||||
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ntfs", ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", ACTION=="add", \
|
||||
TAG+="systemd", ENV{SYSTEMD_WANTS}="ssd-mount@%k.service"
|
||||
|
||||
# Service-Deaktivierung bei Entfernung
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/bin/systemctl stop ssd-mount@%k.service"
|
||||
```
|
||||
|
||||
## Performance-Optimierungen
|
||||
|
||||
### I/O-Scheduler
|
||||
```bash
|
||||
# Optimaler I/O-Scheduler für USB-SSDs
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ATTR{queue/scheduler}="mq-deadline"
|
||||
```
|
||||
|
||||
### Read-Ahead Tuning
|
||||
```bash
|
||||
# Read-Ahead Buffer optimieren
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ATTR{queue/read_ahead_kb}="1024"
|
||||
```
|
||||
|
||||
## Security-Features
|
||||
|
||||
### Autorisierte Benutzer
|
||||
```bash
|
||||
# Zugriff nur für autorisierte Benutzer
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{ID_FS_TYPE}=="ntfs|exfat", \
|
||||
TEST!="/etc/ssd-management/authorized_users", \
|
||||
GROUP="root", MODE="0600"
|
||||
```
|
||||
|
||||
### Device-Blacklist
|
||||
```bash
|
||||
# Problematische Devices ignorieren
|
||||
SUBSYSTEM=="block", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0000", \
|
||||
ENV{UDISKS_IGNORE}="1"
|
||||
```
|
||||
|
||||
## Environment-Variables
|
||||
|
||||
### Script-Konfiguration
|
||||
```bash
|
||||
# Udev-Modus für alle SSD-Scripts
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{SSD_UDEV_MODE}="true", \
|
||||
ENV{SSD_LOG_LEVEL}="INFO", \
|
||||
ENV{SSD_USE_SYSLOG}="true"
|
||||
```
|
||||
|
||||
### Device-Informationen
|
||||
```bash
|
||||
# Device-Details für Scripts
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{SSD_DEVICE_PATH}="/dev/%k", \
|
||||
ENV{SSD_DEVICE_UUID}="$env{ID_FS_UUID}", \
|
||||
ENV{SSD_DEVICE_LABEL}="$env{ID_FS_LABEL}", \
|
||||
ENV{SSD_DEVICE_TYPE}="$env{ID_FS_TYPE}"
|
||||
```
|
||||
|
||||
## Debugging und Troubleshooting
|
||||
|
||||
### Debug-Modus aktivieren
|
||||
```bash
|
||||
# Debug-Logging aktivieren (auskommentiert in Produktion)
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
RUN+="/usr/bin/logger -t udev-ssd 'Device %k: Action=%E{ACTION}, Type=%E{ID_FS_TYPE}, UUID=%E{ID_FS_UUID}'"
|
||||
```
|
||||
|
||||
### Event-Monitoring
|
||||
```bash
|
||||
# Udev-Events in Echtzeit überwachen
|
||||
sudo udevadm monitor --environment --udev
|
||||
|
||||
# Spezifische Events filtern
|
||||
sudo udevadm monitor --subsystem-match=block --property-match=ID_BUS=usb
|
||||
|
||||
# Event-Details anzeigen
|
||||
sudo udevadm info --query=all --name=/dev/sdb1
|
||||
```
|
||||
|
||||
### Rule-Testing
|
||||
```bash
|
||||
# Rule-Syntax testen
|
||||
sudo udevadm test /sys/block/sdb
|
||||
|
||||
# Spezifische Action testen
|
||||
sudo udevadm test --action=add /sys/block/sdb
|
||||
|
||||
# Rule-Matching prüfen
|
||||
sudo udevadm test --action=add /sys/block/sdb 2>&1 | grep "RUN"
|
||||
```
|
||||
|
||||
## Custom-Rules erstellen
|
||||
|
||||
### Basis-Template
|
||||
```bash
|
||||
# Custom-Rule Template
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ENV{ID_FS_TYPE}=="ntfs", \
|
||||
ATTRS{idVendor}=="YOUR_VENDOR", \
|
||||
ACTION=="add", \
|
||||
RUN+="/path/to/your/script.sh --device %k"
|
||||
```
|
||||
|
||||
### Erweiterte Matching-Kriterien
|
||||
```bash
|
||||
# Mehrere Kriterien kombinieren
|
||||
SUBSYSTEM=="block", \
|
||||
ENV{ID_BUS}=="usb", \
|
||||
ATTRS{removable}=="1", \
|
||||
ENV{ID_FS_TYPE}=="ntfs", \
|
||||
ENV{ID_FS_LABEL}=="BACKUP*", \
|
||||
ATTRS{size}=="976773168", \
|
||||
ACTION=="add", \
|
||||
RUN+="/usr/local/bin/backup-ssd-handler.sh --device %k"
|
||||
```
|
||||
|
||||
## Maintenance und Cleanup
|
||||
|
||||
### Automatische Bereinigung
|
||||
```bash
|
||||
# Mount-Points bereinigen
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/usr/local/bin/ssd-mount-manager.sh cleanup --device %k"
|
||||
|
||||
# Temporäre Dateien entfernen
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/bin/rm -f /tmp/ssd-%k-*"
|
||||
```
|
||||
|
||||
### Log-Rotation
|
||||
```bash
|
||||
# Log-Dateien rotieren
|
||||
SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ATTRS{removable}=="1", \
|
||||
ACTION=="remove", \
|
||||
RUN+="/usr/sbin/logrotate -f /etc/logrotate.d/ssd-management"
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Produktionsumgebung
|
||||
1. **Minimale Rules**: Nur notwendige Rules aktivieren
|
||||
2. **Performance**: I/O-Optimierungen für kritische Systeme
|
||||
3. **Security**: Strenge Berechtigungen und Autorisierung
|
||||
4. **Logging**: Produktions-geeignetes Log-Level
|
||||
5. **Testing**: Umfassende Tests vor Deployment
|
||||
|
||||
### Entwicklungsumgebung
|
||||
1. **Debug-Logging**: Erweiterte Logging-Rules aktivieren
|
||||
2. **Flexible-Matching**: Weniger restriktive Matching-Kriterien
|
||||
3. **Rapid-Testing**: Schnelle Rule-Reload-Zyklen
|
||||
4. **Monitoring**: Kontinuierliche Event-Überwachung
|
||||
|
||||
### Sicherheit
|
||||
1. **Principle of Least Privilege**: Minimale Berechtigungen
|
||||
2. **Device-Validation**: Nur vertrauenswürdige Devices
|
||||
3. **Audit-Logging**: Vollständige Event-Protokollierung
|
||||
4. **Access-Control**: Benutzer-basierte Zugriffskontrolle
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Häufige Probleme
|
||||
|
||||
#### Rules werden nicht ausgeführt
|
||||
```bash
|
||||
# Rules-Syntax prüfen
|
||||
sudo udevadm test /sys/block/sdb
|
||||
|
||||
# Rules neu laden
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
|
||||
# Permissions prüfen
|
||||
ls -la /etc/udev/rules.d/99-ssd-*
|
||||
```
|
||||
|
||||
#### Scripts werden nicht gefunden
|
||||
```bash
|
||||
# Script-Pfade prüfen
|
||||
which ssd-detect.sh
|
||||
ls -la /usr/local/bin/ssd-*
|
||||
|
||||
# Permissions prüfen
|
||||
ls -la /usr/local/bin/ssd-detect.sh
|
||||
```
|
||||
|
||||
#### Device-Matching funktioniert nicht
|
||||
```bash
|
||||
# Device-Eigenschaften anzeigen
|
||||
sudo udevadm info --query=all --name=/dev/sdb1
|
||||
|
||||
# Matching-Kriterien testen
|
||||
sudo udevadm test --action=add /sys/block/sdb1
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
### Version 0.1.0
|
||||
- Umfassende USB-SSD Detection Rules
|
||||
- Systemd-Service Integration
|
||||
- Performance-Optimierungen
|
||||
- Security-Features
|
||||
- Vendor-spezifische Rules
|
||||
- Debugging und Troubleshooting Support
|
Reference in New Issue
Block a user