Ciao roglio, benvenuto :smile:
Il DNS ha un'architettura firmware relativamente semplice e il sistema operativo che utilizza non comprende udev. Il DNS ha due porte SATA e una porta USB. Ha una seconda USB "nascosta" che può essere resa disponibile solo con un hacking estremo. Comunque parlerò solo della USB installata dalla fabbrica.
Le periferiche di memorizzazione esterne alla RAM o alla FLASH sono solo tre: le due SATA e la USB. Le due SATA sono viste come sda e sdb. La USB è di norma la sdc. Il problema è che se tu hai un "buco" in mezzo, ovvero hai installato solo una drive SATA, la USB diventa automaticamente sdb. E se non hai SATA, la usb diventa sda. In altre parole, uno script ottimizzato dovrebbe tener conto di quale periferica è montata dove. Ti posto uno script sh che ho creato che monta tutte le partizioni della periferica USB e le rende disponibili in rete. Però parte dal presupposto che la USB sia sdc, ovvero che siano installati due drive SATA nel DNS.
#!/bin/sh
# This script will share the USB flash drive, if inserted, through the net.
# It creates a log file named as /tmp/usb-share.report. If nothing happens,
# just read it and behave accordingly.
###################
# BIG FAT WARNING #
###################
# DMESG IS ACTUALLY *NOT* A GOOD WAY TO OBTAIN
# INFORMATIONS FROM THE KERNEL.
# dmesg output may be nulled by issuing "dmesg -c" at cmdline.
# After this every dmesg reading has no meaning. Not even using
# workarounds like "/var/log/messages", since an admin user can easily
# wipe out its contents. The DNS has no true sysfs, thus no udev.
# So, there is no real way to get around this for now.
SMBCONF="/etc/samba/smb.conf"
SMBPATH="/mnt/flash"
USBTMP="/tmp/$(basename $0).report"
USBMODDIR="/sys/crfs/scsi/"
USBMOD="usb-storage.ko"
USBPATH=$USBMODDIR$USBMOD
touch $USBTMP
# -- we have the usb-storage module
if [ ! -e $USBPATH ]; then
echo "Module $USBMOD was not found in $USBMODDIR." >> $USBTMP
echo "-- Hint: is $USBMODDIR the right path, or $USBMOD" >> $USBTMP
echo "-- the right module name?" >> $USBTMP
echo "-- The pathname was $USBPATH." >> $USBTMP
exit 1
fi
lsmod | grep -q usb_storage
if [ $? -ne 0 ]; then
echo "Module usb-storage was not loaded." >> $USBTMP
echo "-- Hint: is /etc/rc.sh properly configured, or" >> $USBTMP
echo "-- is the module properly installed?" >> $USBTMP
exit 1
fi
# -- we have a USB key physically installed
# This is relatively simple, I simply ask the kernel if it found
# an USB mass storage device.
dmesg | grep -q usb-storage
if [ $? -ne 0 ]; then
echo "I did not find an USB key phisycally installed." >> $USBTMP
echo "-- Hint: check the flash key." >> $USBTMP
exit 1
fi
# -- the USB key is seen as "sdc"
# Actually this should not be necessary. USB flash key should always be
# 'sdc' on DNS-323. Hence, I could erase some (many?)
# useless block devices.
# -- the USB key is partitioned
# If it has a filesystem I am not 100% sure that the key
# is partitioned. You know, you can do a single flash USB partition
# without partitioning the device. Something like floppy disks.
# By default, Windows machines do not partition USB flash devices.
echo "Trying to mount /dev/sdc as filesystem." >> $USBTMP
mkdir $SMBPATH 2>/dev/null
mount /dev/sdc $SMBPATH 2>/dev/null
# If the mount was successful, we modify the smb.conf file
if [ $? -eq 0 ]; then
echo "I was able to mount /dev/sdc as single filesystem." >> $USBTMP
echo >> $SMBCONF
echo "[flash]" >> $SMBCONF
echo >> $SMBCONF
echo " comment = Flash USB" >> $SMBCONF
echo " path = $SMBPATH" >> $SMBCONF
echo " browseable = yes" >> $SMBCONF
echo " writeable = yes" >> $SMBCONF
echo " guest ok = yes" >> $SMBCONF
echo " create mask = 0644" >> $SMBCONF
exit 0
else
echo "Could not mount /dev/sdc as single filesystem." >> $USBTMP
rm -r $SMBPATH
fi
# -- the USB key only has one partition
# This is not necessary either. I could mount every partition under
# a different mountpoint in /mnt.
# We should first check if the flash USB is partitioned.
echo "Trying to mount /dev/sdc partition(s)." >> $USBTMP
for NUM in `fdisk -l /dev/sdc | \\
grep ^/dev | \\
awk '{ print $1 }' | \\
sed 's&/dev/sdc&&g'`
do
mkdir $SMBPATH${NUM} 2>/dev/null
mount /dev/sdc${NUM} $SMBPATH${NUM} 2>/dev/null
if [ $? -eq 0 ]; then
# Here we go with smb.conf tampering
echo "Mounted /dev/sdc${NUM}." >> $USBTMP
echo >> $SMBCONF
echo "[flash${NUM}]" >> $SMBCONF
echo >> $SMBCONF
echo " comment = DNS Flash USB ${NUM}" >> $SMBCONF
echo " path = $SMBPATH${NUM}" >> $SMBCONF
echo " browseable = yes" >> $SMBCONF
echo " writeable = yes" >> $SMBCONF
echo " guest ok = yes" >> $SMBCONF
echo " create mask = 0644" >> $SMBCONF
# Closing /etc/samba/smb.conf.
else
echo "Could not mount /dev/sdc${NUM}." >> $USBTMP
echo "No further attempts will be done." >> $USBTMP
echo "-- Hint: wrong filesystem?" >> $USBTMP
rm -r $SMBPATH${NUM}
exit 1
fi
done
echo >> $USBTMP
# Printing USB flash partition.
fdisk -l /dev/sdc &>/dev/null
if [ $? -eq 0 ]; then
echo "Here's the USB flash key partition situation." >> $USBTMP
fdisk -l /dev/sdc >> $USBTMP
fi
# Now /mnt/flash should be mountable, if the script stopped here.
exit 0
Lo script crea un file di log in /tmp, chiamato usb-share.report. Se qualcosa non funziona puoi eventualmente vedere che cosa è andato storto là dentro. Se tutto è andato bene il file dovrebbe comprendere la tabella di partizione dell'unità USB esterna.
Così com'è non è un granchè, ma se hai un po' di dimestichezza con lo scripting bash ci puoi fare tutte le modifiche che ti pare. Ma il bambino si aspetta anche che esista un modulo kernel (usb-storage.ko) indispensabile per accedere all'unità USB esterna. I controlli che fa dovrebbero essere sufficienti e anche se manca il modulo nel percorso scritto te lo dice nel file di log. Comunque se usi fun_plug puoi modificare i path di tutto e fargli vedere i file giusti al posto giusto, così che all'avvio il DNS legga ed esegua fun_plug, che richiama questo script:
- carica il modulo usb-storage nel kernel,
- verifica che sdc sia partizionato e formattato,
- faccia la scansione delle partizioni e dei filesystem,
- crei le directory di montaggio delle partizioni nell'USB,
- le monti automaticamente,
- modifichi /etc/smb.conf in modo da condividere immediatamente le unità in rete.
Ovviamente il tutto condito con i controlli che decidi di fargli fare.
Poi dovrai riavviare smbd e nmbd per rendere effettive le condivisioni:
kill -15 $(pidof smbd)
kill -15 $(pidof nmbd)
smbd -D
nmbd -D
Ultim'ora. Ho brickato il DNS (riavvio infinito, senza dubbio ho pasticciato troppo con rc.sh) e ora mi tocca per forza aspettare che mi arrivi il materiale dall'America. Nel frattempo posso continuare a modificare gli script, ormai mi ricordo come funziona sh nel DNS. :biggrin: