Romanian PC Forum Sabitech Media - web design, gazduire web, promovare, seo, logo design si branding


Go Back   Romanian PC Forum > Hardware > Silent PC & Cooling

Silent PC & Cooling Air cooling, water cooling, phase/change, vibratii, temperaturi... pentru maniaci!


Reply
 
Thread Tools
Old 03.02.2016, 00:18   #1
bogdan
RPC Super Moderator
 
bogdan's Avatar
 
Join Date: 26.06.2010
Posts: 5,333
Thanks: 5,829
Thanked 7,829 Times in 3,982 Posts
Default Interfata relee pornire hard disk-uri

Dragilor, am cam "chiulit" de pe forum in ultima vreme, insa am fost tare prins (pe langa activitatea cotidiana) cu un proiect hard & soft, si anume constructia unei interfete care sa-mi permita comutarea ON/OFF a unor HDD-uri din PC. Toata treaba e realizata pe port paralel - stiu ca e cam "obsolete", dar se interfateaza foarte usor, pe baza celor 8 iesiri digitale.

Ideea e de a comanda cate un releu care sa alimenteze un HDD, atat cu tensiunea de 5 V (necesara partii electronice a HDD-ului) cat si de 12 V (necesara motorului ce invarteste platanele). E necesara o placa de baza cu porturi SATA hotplug sau convertoare USB3->SATA.

Avantaje:
_PC silentios; OS-ul il am instalat pe un SSD, plus inca un SSD ("de frecatura") in sistem, asadar la pornire PC-ul nu va activa niciun HDD mecanic. In miscare vor fi doar ventilatoarele de la sursa, CPU, GPU si case exhaust. In afara celui de la placa video, toate celelalte sunt de 120 mm la turatie joasa; per ansamblu iese foarte silentios.
_Reduce mult uzura HDD-urilor, mai ales daca-i vorba de discuri cu nenorocirea aia de IntelliPower de la WD (sau echivalentul de la Seagate), in care se efectueaza parcarea capetelor la cateva secunde in situatia in care HDD-ul nu efectueaza operatii I/O. Un anumit HDD poate fi astfel pornit numai cand e nevoie de salvat/accesat informatie, asadar nu se va invarti "in gol" tot timpul in care PC-ul e pornit
_Reduce destul de mult consumul de curent al PC-ului (socotind undeva la 7-8W per HDD, daca sunt multe HDD-uri in sistem, incepe sa se simta bine de tot...)
_Atata vreme cat pornirea/oprirea unui anumit HDD se face "din soft", se poate porni/opri un HDD prin conexiune remote

Dezavantaje:
_inca n-am gasit... In afara timpului necesar constructiei...

Bun, sa incepem "teoria": de ce port paralel:
1) o placa adaptoare PCI la LPT+serial se cumpara ieftin sh (~35 lei am dat eu)
2) interfatarea e foarte simpla; din pacate nu stiu sa programez microcontrollere (asta ar fi fost calea moderna care sa foloseasca bus-ul USB); pe langa hex-ul ca atare mai e nevoie si de device-ul fizic ce permite flash-uirea hex-ului pe microcontroller (in fine, programatorul de microcontroller, oricum, ar fi iesit mult prea scump sa mai cumpar si asa ceva pentru un singur montaj).

Portul paralel are 8 iesiri digitale ( D0-D7 )
lpt.png
care sunt la 0V in stare logica 0 si +5V (in practica 4.7-4.8V) in stare logica 1. Acest semnal permite deschiderea unui tranzistor ce va alimenta bobina unui releu. Mult mai practic decat folosirea unor tranzistoare discrete e utilizarea unui circuit integrat ULN 2803, care e o matrice de 8 montaje Darlington (factor de amplificare zdravan !) cu intrare protejata bine (max. 30V input) si de asemenea echipat pe iesire cu diode de protectie pentru sarcini inductive (necesar in cazul nostru datorita faptului ca alimentam bobina unui releu). Mai mult, se pot pune in paralel mai multe "module" Darlington dintr-un integrat ULN 2803 pentru a putea comuta un curent mai mare pe iesire.

In esenta asta ar fi suficient, cele 8 iesiri digitale D0-D7 ale portului paralel conectate la intrarile de semnal ale unui ULN 2803 si putem comanda 8 relee prin manipularea bitilor D0-D7 ale portului paralel. Pentru siguranta, am preferat sa folosesc 2 integrate ULN2803 punand in paralel cate 2 module pentru a comanda fiecare releu. Ca relee am ales ceva mai de soi (OMRON), 12V, set dublu de contacte (avem nevoie pentru a putea comanda tensiunile de 5V si 12V). De ce relee ? Da, e "obsolete", dar rezistenta pe elementul de comutatie e extrem de mica, asadar cadere de tensiune neglijabila pe el. HDD-urile vor fi alimentate exact la tensiunea sursei PC-ului; o comutatie cu tranzistori obisnuiti ar fi insemnat cadere de tensiune pe tranzistor, plus incalzire destul de zdravana datorita puterii disipate. Da, ar fi fost si varianta MOSFET-urilor, dar nu-s foarte usor de gasit, plus ca n-am experienta necesara in proiectarea unei scheme ce-ar folosi asa ceva. Ca dezavantaj al folosirii releelor ar fi socul de tensiune la cuplarea brusca a unei sarcini inductive (motorul HDD), dar asta e compensata pe de-o parte de o sursa buna (am un Seasonic), plus diodele TVS (nu stiu care-i termenul corect in romaneste pentru "transient voltage suppressor") cu care e echipat "din fabrica" fiecare HDD.

Pana aici toate bune si frumoase, avem 8 relee comandate prin doua ULN2803-uri din iesirile D0-D7 ale portului paralel. Problema mare a portului paralel e insa faptul ca la boot-are, starea logica a pinilor D0-D7 e nedefinita; mai precis "oscileaza" de cateva ori intre 0V si +5V, ceea ce ar insemna aclansare aleatoare (de cateva ori in timp scurt) a releelor ce comuta HDD-urile. Cat se poate de nasol; pe de-o parte socuri de tensiune datorate cuplarii/decuplarii repetate in timp scurt a motoarelor HDD-urilor, plus ca nu cred ca un HDD va suporta prea bine un asemenea tratament la fiecare boot. Rezolvarea este asa: pin-ul de STROBE al portului paralel este HIGH (+5V) imediat ce e apasat butonul de power al PC-ului, si starea lui nu se modifica. Asta permite folosirea unui buffer octal ( 74HCT244 ) interpus intre iesirile D0-D7 ale portului paralel si intrarile circuitelor de comanda ale releelor (ULN 2803):
schema.png
Iesirea pin-ului de STROBE a portului paralel se conecteaza la intrarile inversoare ale buffer-ului octal, astfel incat atata vreme cat STROBE e pe HIGH, iesirile logice din 74HCT244 vor fi pe Z (high impedance OFF state):
74hct244-tab-logic.png
asadar la intrarea ULN2803 nu vom avea tensiune de comanda care sa induca alimentarea bobinelor releelor (chiar daca D0-D7 din portul paralel "oscileaza" la boot-are, releele nu vor fi alimentate atata vreme cat avem tensiune pe STROBE). Dupa ce a boot-at PC-ul, trecem D0-D7 pe LOW ( 0V ), apoi inversam starea STROBE, ceea ce va "debloca" comanda releelor in functie de starea logica a pinilor D0-D7. In fine, nu stiu cat de bine am explicat, dar ideea e ca HDD-urile de stocare sa nu fie alimentate la boot-are.

Am ales ca relee varianta de 12V, deoarece putem alimenta comod tot montajul din sursa PC-ului (12V pt. relee si 5V pt. buffer-ul octal).
Realizarea practica nu e ceva foarte aratos (n-am stat sa "bibilesc" un PCB, ci am folosit o placa de test gata gaurita pe care conexiunile le-am facut mai "ciobaneste" cu fire:
1.jpg
Stiu, daca proiectam "ca la carte" un PCB ieseam mai bine si ca spatiu, dar ar fi fost un efort mult prea mare pentru realizarea unui singur montaj. Pentru rigidizare am fixat PCB-ul pe o bucata de plexiglas gros. A, da, in schema am mai pus cate o dioda 1N4148 in contrasens cu bobina fiecarui releu (stiu, e relativ inutil, socotind ca fiecare iesire de ULN2803 are dioda supresoare, plus faptul ca folosesc 2 module in paralel... ajung astfel la 3 diode de protectie pe fiecare releu. In fine, costa putin o asemenea dioda, asadar ... "nu ca trăbă, da' să hie !").

Se observa conectorii (2 perechi) pt. fiecare releu, plus conectorul cu molex pt. alimentare. Am mai adaugat ulterior niste conectori pt. ventilatoare ce vor fi alimentati prin diode 1N4007 pt. a porni ventilatoarele de racire a HDD-urilor, in functie de care HDD e pornit (iac-asa se face si mai silentios PC-ul ! Pornim ventilatorul ce raceste un anumit HDD doar atunci cand pornim si HDD-ul).

Ultima etapa e confectionarea cablurilor de alimentare pt. HDD-uri; am folosit niste "splittere" (nu stiu cum sa le zic altfel...) de la SATA la 2*SATA:
SATA-power.jpeg
la care am lasat masa conectata (firele negre) si circuitele de 5V (fir rosu) si 12V (fir galben) sunt trecute prin fiecare releu de pe placa. Am folosit fir cam gros (1.5 mm^2) deoarece asta a fost cel mai subtire cablul pe care l-am gasit intr-un magazin de bricolaj (4*1.5). E util sa folosim un asemenea cablu deoarece dupa ce dam jos mansonul, avem 4 fire de culori diferite (in cazul asta e mai mult decat necesar, socotind ca avem deja 4*8=32 de fire de conectat in placa cu relee; orice confuzie a liniilor de 5 cu 12V va avea consecinte dezastruoase asupra HDD-ului ce urmeaza a fi alimentat):
2.jpg
Si o poza cu partea de jos (plexiglasul folosit e cam zgariat):
3.jpg

Iese ditamai paienjenisul de fire, dar cu grija la "cable management" intra OK intr-o carcasa; placa cu relee fiind asezata jos, pe "fundul" carcasei.
__________________
CHIAR Imi place Romanian PC Forum - www.rpc-forum.ro!

Last edited by bogdan; 03.02.2016 at 00:36.
bogdan is offline   Reply With Quote
The Following 7 Users Say Thank You to bogdan For This Useful Post:
Alin99 (05.02.2016), AnbuBlack (03.02.2016), COMAN DINU-VICE (05.02.2016), konstantine (03.02.2016), ono (03.02.2016), XVanish (03.02.2016), yo9fah (03.02.2016)
Old 03.02.2016, 00:42   #2
XVanish
RPC Administrator
 
XVanish's Avatar
 
Join Date: 03.06.2008
Location: Baia Mare
Age: 37
Posts: 5,958
Thanks: 3,635
Thanked 3,356 Times in 1,978 Posts
Send a message via Yahoo to XVanish Send a message via Skype™ to XVanish
Default Re: Interfata relee pornire hard disk-uri

Super tare, bravo! Am citit pe sarite acum ca am de lucru dar o sa citesc atent tot ce ai mesterit si vin cu pareri. Te invidiez sa stii... eu nu mai am timp de "mesterit" mai nimic in ultima perioada.
__________________
Internetul e distractie, nu pierde controlul!


Foloseste Google si YouTube inainte de a pune intrebari stupide!
XVanish is offline   Reply With Quote
The Following User Says Thank You to XVanish For This Useful Post:
bogdan (03.02.2016)
Old 03.02.2016, 01:27   #3
bogdan
RPC Super Moderator
 
bogdan's Avatar
 
Join Date: 26.06.2010
Posts: 5,333
Thanks: 5,829
Thanked 7,829 Times in 3,982 Posts
Default Re: Interfata relee pornire hard disk-uri

Partea de control acum; linux only ca nu ma impac deloc cu windoaza...
Trebuie aflata adresa I/O pentru portul paralel:
Code:
lspci -v
In cazul meu:
Code:
06:05.0 Communication controller: MosChip Semiconductor Technology Ltd. PCI 9835 Multi-I/O Controller (rev 01)
        Subsystem: LSI Logic / Symbios Logic 1P2S
        Flags: medium devsel, IRQ 20
        I/O ports at b1d0 [size=8]
        I/O ports at b1c0 [size=8]
        I/O ports at b1b0 [size=8]
        I/O ports at b1a0 [size=8]
        I/O ports at b190 [size=8]
        I/O ports at b180 [size=16]
        Kernel driver in use: parport_serial
Cel rosu e portul paralel, placa PCI are 2 porturi seriale (primele 2 adrese) si unul paralel. Asadar adresa este 0xb1b0

Urmatorul program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>

#define lp0_ioaddr 0xb1b0 //parport0 ioaddr
#define lp0_strobe_ioaddr 0xb1b2 //parport0 STROBE ioaddr

int main()
{
         if (ioperm(lp0_ioaddr,1,1))
            fprintf(stderr, "Couldn't get the port at %x\n", lp0_ioaddr), exit(1);
         outb(0, lp0_ioaddr);
         sleep(1);
         if (ioperm(lp0_ioaddr+2,1,1))//STROBE e la lp0_ioaddr + 2
            fprintf(stderr, "Couldn't get the port at %x\n", lp0_ioaddr+2), exit(1);
         outb(1, lp0_ioaddr+2);
return 0;
}
compilat cu
Code:
gcc -O parport_init.c -o parport_init
ce trece pe 0V (LOW) bitii D0-D7 ai portului paralel, apoi STROBE (adresa lp0+2) tot pe LOW (STROBE e iesire inversata; valoarea 1 "scrisa" pe strobe va determina setarea pe LOW a pin-ului).
Programelul asta trebuie executat dupa boot-ul sistemului (l-am pus "ciobaneste" in /etc/rc.d/rc.local, bine ca se mai poate treaba asta in CentOS 7, ca nu ma prea impac cu systemd ).

Controlul bitilor pe lp0 il facem cu programelul:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <unistd.h>

#define lp0_ioaddr 0xb1b0 //parport0 ioaddr

void print_lp0_status(void); //Afisam frumos fiecare HDD cu ON/OFF
void read_lp0(unsigned short int *lp0_bit); //citim starea bitilor de pe lp0 si returnam matricea lp0_bit[0..7]
void int2bin(int parport_value, unsigned short int *lp_bit); //conversie valoare citita de pe port paralel in 8 biti separati

int main (int argc, char *argv[])
{
   unsigned short int lp0_bit[8]={0, 0, 0, 0, 0, 0, 0, 0};
   int argv1, argv2;

   if (argc != 3) //linie de comanda fara argumente, sau gresita; afisam doar statusul
   {
      print_lp0_status(); //Afisam frumos fiecare HDD cu ON/OFF
      exit (1);
   }
//incercam sa deschidem & citim portul paralel, daca da gres, exit(1) din program
   if (ioperm(lp0_ioaddr,1,1))
   {
      fprintf(stderr, "Couldn't get the port at %x\n", lp0_ioaddr);
      exit(1);
   }
   print_lp0_status(); //Afisam frumos fiecare HDD cu ON/OFF
//asta-i bug, daca argv[1 sau 2] e char/string, va fi convertit la 0 de strtol!
   argv1 = (int)strtol ( argv[1], NULL, 10 );
   argv2 = (int)strtol ( argv[2], NULL, 10 );
//HDD 1..8, power status 0..1
   if((argv1 < 1) || (argv1 > 8))
   {
      printf("HDD from 1 to 8 !\n");
      exit(1);
   }
   if((argv2 < 0) || (argv2 > 1))
   {
      printf("Power status: 0 (OFF) or 1 (ON) !\n");
      exit(1);
   }
   read_lp0(lp0_bit);
   if ( lp0_bit[argv1-1] == argv2)
   {
      printf("\nHDD %i already on or off !\n\n", argv1);
      print_lp0_status(); //Afisam frumos fiecare HDD cu ON/OFF
      exit(1);
   }
   else
   {
      printf("\nToggling HDD %i status...\n\n", argv1);
      lp0_bit[argv1-1] = argv2;
      outb( lp0_bit[0]*1 + lp0_bit[1]*2 + lp0_bit[2]*4 + lp0_bit[3]*8 + lp0_bit[4]*16 + lp0_bit[5]*32 + lp0_bit[6]*64 + lp0_bit[7]*128 , lp0_ioaddr);
      print_lp0_status(); //Afisam frumos fiecare HDD cu ON/OFF
   }
return 0;
}

/*   Read the current status of the lp0 parallell port bits  */

void print_lp0_status(void) //Afisam frumos fiecare HDD cu ON/OFF
{
   unsigned short int i, lp0_bit[8]={0, 0, 0, 0, 0, 0, 0, 0};
   read_lp0(lp0_bit);
   printf("HDD Nr:  1    2    3    4    5    6    7    8\nStatus:");
   for (i=0; i<=7; i++)
   {
      if(lp0_bit[i]==1)
         printf(" ON  ");
      else
         printf(" OFF ");
   }
  printf("\n");
}

/*   Read the current status of the lp0 parallell port bits  */

void read_lp0(unsigned short int *lp0_bit) //citim starea bitilor de pe lp0 si returnam matricea lp0_bit[0..7]
{
   unsigned short int parport_status;
   if (ioperm(lp0_ioaddr,1,1))
   {
      fprintf(stderr, "Couldn't get the port at %x\n", lp0_ioaddr);
      exit(1);
   }
   else
   {
      parport_status=inb(lp0_ioaddr); //reading the status of the other bits of the parallel port
      int2bin(parport_status, lp0_bit); //conversie valoare citita de pe port paralel in 8 biti separati
   }
}

/*   Break parallel port status value to single bits  */

void int2bin(int parport_value, unsigned short int *lp_bit)
{
   unsigned short int i;
   for (i=0; i<=7; i++)
   {
      lp_bit[i]=((parport_value>>i)&1); //shift tb. cu i biti (BIN), asa obtinem bit[0] pt. n*2^0, bit[1] pt n*2^1...
   }
}
compilare, la fel ca mai sus:
Code:
gcc -O lp0ctrl.c -o lp0ctrl
Pentru a putea fi rulat ca user simplu, il "dam" in proprietatea root-ului si ii setam sticky bit:
Code:
chown root.root lp0ctrl
chmod a+s lp0ctrl
Abilitatile mele de programator sunt destul de limitate, asadar nu-i deloc ceva "profi"; are si un bug (la faza cu strtol din argv ), dar oricum, il folosesc doar eu din cadrul unui bash script, asadar nu prea am cum sa gresesc la linia de comanda
La rulare fara argumente afiseaza doar statusul:

Code:
HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  OFF  OFF  OFF  OFF  OFF  OFF  OFF
apoi, pentru a modifica starea unui HDD se dau 2 argumente: numarul HDD-ului urmat de status (0-OFF, 1-ON), ex:
Code:
lp0ctrl 2 1
rezultat:
HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  OFF  OFF  OFF  OFF  OFF  OFF  OFF 

Toggling HDD 2 status...

HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  ON   OFF  OFF  OFF  OFF  OFF  OFF
OK, dupa un mic test, "asezam" executabilul in /usr/local/bin

---------- Post added at 02:27 ---------- Previous post was at 01:58 ----------

E, acu' ca putem porni/opri un HDD din linia de comanda e OK, dar trebuie tinut cont de:
1) kernel-ul va atribui HDD-urilor indicator sdX in functie de ordinea in care au fost pornite, asadar suita sdb, sdc, sdd, etc... nu mai prea are sens in identificarea precisa a unui HDD. Cea mai buna varianta e folosirea disk-id-ului, obtinut astfel:
Code:
ls -l /dev/disk/by-id/
care contine symlink-uri spre sdb, sdc, etc... Pentru a usura gestionarea montarii/demontarii, eu am facut o singura partitie (avand toata capacitatea HDD-ului). In modul asta, identificam usor un HDD din listing-ul de mai sus; apoi partitia apare sub forma id_hdd-part1, care e un symlink spre sdX1. Iac-asa, ca sa montam un anumit HDD, dam:
Code:
mount /dev/disk/by-id/id_hdd-blablabla-part1 /mnt/storage1
2) oprirea unui HDD nu se face (evident !) cu el montat, ci trebuie facute o serie de operatii (cu comenzile aferente)
_sync system buffer&caches si sync disk cache:
Code:
sync && sdparm -C sync /dev/disk/by-id/id_hdd-blablabla
_unmount
Code:
umount /mnt/storage1
inc-o data (just for safety...):
Code:
sync && sdparm -C sync /dev/disk/by-id/id_hdd-blablabla
_daca e disk SATA: pus discul in idle
Code:
hdparm -Y /dev/disk/by-id/id_hdd-blablabla
_daca e disk USB: dat disconnect
Code:
udisks --detach /dev/disk/by-id/id_hdd-blablabla
_"sters" din "evidenta" kernel-ului:
Code:
echo 1 > /sys/block/sdX/device/delete
dupa care poate fi oprit din releu.

Pentru utilitarele de mai sus, in CentOS 7:
Code:
yum install hdparm sdparm oldudisks
ultimul, e din nux-dextop repo.
__________________
CHIAR Imi place Romanian PC Forum - www.rpc-forum.ro!

Last edited by bogdan; 03.02.2016 at 01:02.
bogdan is offline   Reply With Quote
The Following 6 Users Say Thank You to bogdan For This Useful Post:
Alin99 (05.02.2016), AnbuBlack (03.02.2016), COMAN DINU-VICE (05.02.2016), ono (03.02.2016), XVanish (03.02.2016), yo9fah (03.02.2016)
Old 03.02.2016, 02:45   #4
bogdan
RPC Super Moderator
 
bogdan's Avatar
 
Join Date: 26.06.2010
Posts: 5,333
Thanks: 5,829
Thanked 7,829 Times in 3,982 Posts
Default Re: Interfata relee pornire hard disk-uri

In final si un bash script ce face toata treaba asta cat de cat automatizat (din nou, imi cer scuze pentru abilitatile mele mai amatoricesti de programare) :
Code:
#!/bin/bash
echo "----------------------------------------------------------------------------"
echo -e "Nr    Status\tPartition 1 mountpoint\t\tHDD ID "
echo "----------------------------------------------------------------------------"

allHDDstatus=$(/usr/local/bin/lp0ctrl | grep Status)
IFS=' ' read -r -a HDDstatus <<< "$allHDDstatus"

#ls /dev/disk/by-id
#adauga aici HDD ID-ul corect, destinatia de montare si capacitatea!
HDD[1]=ata-Hitachi_BLABLABLA123456789_HDDSERIAL1234
mntPart1HDD[1]=/mnt/stor1
echo -e " 1:\t${HDDstatus[1]}\t${mntPart1HDD[1]} (xTB)\t${HDD[1]}"

HDD[2]=ata-Hitachi_BLABLABLA123456789_HDDSERIAL1235
mntPart1HDD[2]=/mnt/stor2
echo -e " 2:\t${HDDstatus[2]}\t${mntPart1HDD[2]} (yTB)\t${HDD[2]}"

HDD[3]=ata-WDC_WDBLABLABLA_WD-SERIAL-TRALALA1
mntPart1HDD[3]=/mnt/stor3
echo -e " 3:\t${HDDstatus[3]}\t${mntPart1HDD[3]} (zTB)\t${HDD[3]}"

HDD[4]=ata-WDC_WDBLABLABLA_WD-SERIAL-TRALALA2
mntPart1HDD[4]=/mnt/stor4
echo -e " 4:\t${HDDstatus[4]}\t${mntPart1HDD[4]} (xTB)\t${HDD[4]}"

HDD[5]=usb-WDC_WDCUCURIGUBLABLABLA_POLOLOGHIE_LUNGA-0:0
mntPart1HDD[5]=/mnt/stor5
echo -e " 5:\t${HDDstatus[5]}\t${mntPart1HDD[5]} (xyz GB)\t${HDD[5]}"

HDD[6]=ata-ST000000111112222BLABLABLA_SERIAL1
mntPart1HDD[6]=/mnt/stor6
echo -e " 6:\t${HDDstatus[6]}\t${mntPart1HDD[6]} (xyz GB)\t${HDD[6]}"

HDD[7]=ata-ST000000111112222BLABLABLA_SERIAL2
mntPart1HDD[7]=/mnt/stor7
echo -e " 7:\t${HDDstatus[7]}\t${mntPart1HDD[7]} (xyz GB)\t${HDD[7]}"

HDD[8]=usb-WDC_BURUBURU_SERIALn
mntPart1HDD[8]=/mnt/stor8
echo -e " 8:\t${HDDstatus[8]}\t${mntPart1HDD[8]} (xyz GB)\t${HDD[8]}"

echo " ";
while true; do
   read -p "Select HDD Nr (0 to exit) : " nrHDD
   case $nrHDD in
      0 ) exit;;
      1 ) break;;
      2 ) break;;
      3 ) break;;
      4 ) break;;
      5 ) break;;
      6 ) break;;
      7 ) break;;
      8 ) break;;
      * ) echo "Hey... Type carefully ! Number between 0 and 8: ";;
   esac
done

#if HDD is powered ON, we try to unmount & then stop it
if [ ${HDDstatus[nrHDD]} = "ON" ]; then
   echo "HDD $nrHDD is powered ${HDDstatus[nrHDD]}"
   if readlink -e /dev/disk/by-id/${HDD[nrHDD]} | grep dev > /dev/null; then
      echo "detected as $(readlink -e /dev/disk/by-id/${HDD[nrHDD]} | grep dev) ; check if mounted:"
      if mount | grep $(readlink -e /dev/disk/by-id/${HDD[nrHDD]} ); then
         while true; do
            read -p "Mounted ! Unmount ${mntPart1HDD[nrHDD]} & power off HDD $nrHDD ? (y/n) " yn
            case $yn in
               y ) break;;
               n ) break;;
               * ) echo "Hey... Type carefully ! y or n : ";;
            esac
         done
         if [ $yn = "y"  ]; then
            sync && sdparm -C sync /dev/disk/by-id/${HDD[nrHDD]} > /dev/null #sync system buffers & HDD cache
            echo " "
            if umount ${mntPart1HDD[nrHDD]} 2>/dev/null ; then
              echo "${mntPart1HDD[nrHDD]} unmounted OK !"
            else
               echo "${mntPart1HDD[nrHDD]} is still accessed and can not be unmounted; lsof output:"
               echo " "
               lsof -w ${mntPart1HDD[nrHDD]}
               exit;
            fi
            echo "Sync system & HDD $nrHDD cache..."
            sync && sdparm -C sync /dev/disk/by-id/${HDD[nrHDD]} > /dev/null #sync system buffers & HDD cache
            sleep 5 #wait for final HDD cache sync
            if ls /dev/disk/by-id/${HDD[nrHDD]} | grep usb ; then  #for USB disks:
               echo "Disconnect (USB) HDD $nrHDD ..."
               udisks --detach /dev/disk/by-id/${HDD[nrHDD]}
            else                                                   #for SATA disks:
               echo "Set HDD $nrHDD in idle mode ..."
               hdparm -Y /dev/disk/by-id/${HDD[nrHDD]}
               sleep 10 #wait for HDD to enter idle mode
               echo "Disconnect HDD $nrHDD from SATA bus..."
               disk="readlink -e /dev/disk/by-id/${HDD[nrHDD]} | cut -c 6-8"
               echo 1 > /sys/block/$(eval $disk)/device/delete
            fi
            sleep 10
            echo "Power off HDD $nrHDD ..."
            /usr/local/bin/lp0ctrl $nrHDD 0
            sleep 5
            echo "HDD $nrHDD OFF"
            dmesg | tail -n 10
         else
            exit;
         fi
      else
         while true; do
            read -p "Not mounted. Power off ? (y/n) " yn
            case $yn in
               y ) break;;
               n ) break;;
               * ) echo "Hey... Type carefully ! y or n : ";;
            esac
         done
         if [ $yn = "y"  ]; then
            echo "Sync system & HDD $nrHDD cache..."
            sync && sdparm -C sync /dev/disk/by-id/${HDD[nrHDD]} > /dev/null #sync system buffers & HDD cache
            sleep 5 #wait for final HDD cache sync
            if ls /dev/disk/by-id/${HDD[nrHDD]} | grep usb ; then #for USB disks:
               echo "Disconnect (USB) HDD $nrHDD ..."
               udisks --detach /dev/disk/by-id/${HDD[nrHDD]}
            else                                                  #for SATA disks:
               echo "Set HDD $nrHDD in idle mode ..."
               hdparm -Y /dev/disk/by-id/${HDD[nrHDD]}
               sleep 10 #wait for HDD to enter idle mode
               echo "Disconnect HDD $nrHDD from SATA bus..."
               disk="readlink -e /dev/disk/by-id/${HDD[nrHDD]} | cut -c 6-8"
               echo 1 > /sys/block/$(eval $disk)/device/delete
            fi
            sleep 10
            echo "Power off HDD $nrHDD ..."
            /usr/local/bin/lp0ctrl $nrHDD 0
            sleep 5
            echo "HDD $nrHDD OFF"
            dmesg | tail -n 10
         else
            exit;
         fi
      fi
   else
      echo "but not detected by the kernel. Check your hardware !!!"
      exit;
   fi
fi

#if HDD is powered OFF, we try to start & mount it
if [ ${HDDstatus[nrHDD]} = "OFF" ]; then
   echo "HDD $nrHDD is powered ${HDDstatus[nrHDD]}"
   while true; do
      read -p "Start HDD & mount ${mntPart1HDD[nrHDD]} ? (y/n) " yn
      case $yn in
         y ) break;;
         n ) break;;
         * ) echo "Hey... Type carefully ! y or n : ";;
      esac
   done
   if [ $yn = "y"  ]; then
      if [ ! -d "${mntPart1HDD[nrHDD]}" ]; then
         echo "Mountpoint ${mntPart1HDD[nrHDD]} doesn't exist. Create it first, then rerun." 
         exit;
      fi
      echo " "
      /usr/local/bin/lp0ctrl $nrHDD 1
      echo " "
      echo "Wait for the system to detect HDD $nrHDD ..."
      iterations=1
      while [ $iterations -lt 7 ]; do
         if readlink -e /dev/disk/by-id/${HDD[nrHDD]} >> /dev/null ; then
            break;
         else
            sleep 5
            iterations=$[$iterations+1]
         fi
      done
      if [ $iterations = 6 ]; then
         echo "HDD $nrHDD powered ON, but not detected by the system. Check hardware !"
         exit;
      fi
      echo "detected as $(readlink -e /dev/disk/by-id/${HDD[nrHDD]}) ; now mounting..."
      if mount /dev/disk/by-id/${HDD[nrHDD]}-part1 ${mntPart1HDD[nrHDD]} ; then
         echo "mounted OK !"
         echo " "
         chmod a+rw ${mntPart1HDD[nrHDD]}
         dmesg | tail -n 10
         echo " "
         df | grep $(readlink -e /dev/disk/by-id/${HDD[nrHDD]})
      else
         echo "HDD $nrHDD powered ON, detected by the system, but partition 1 cand not be mounted. Damaged or wrong partition ?"
         exit;
      fi
   else
      exit;
   fi
fi
Scriptul trebuie adaptat de fiecare: adaugate id-urile corecte ale HDD-urilor (obtinute cu ls -l /dev/disk/by-id), destinatia pt. montare, si ceva info (capacitatea). De asemenea, va monat DOAR PRIMA PARTITIE a HDD-ului (eu asa le am pe toate, n-am stat sa complic scriptul cu detectie a numarului de partitii, etc...).

Scriptul asta contine comanda mount/umount, asadar trebuie rulat ca root. O varianta e sa-l salvam intr-un fisier /usr/local/bin/controlHDDuri si sa-l invocam dintr-un alt script (sa zicem, /usr/local/disks , ca-i usr de dat "disks" in linia de comanda...):
Code:
#!/bin/bash
sudo /usr/local/bin/controlHDDuri
adaugand bineinteles pentru userul curent /usr/local/bin/controlHDDuri in sudoers (cu comanda "visudo" executata ca root).
Cam asta ar fi, sper sa n-am bugs prea nasoale in script (inca n-am apucat sa-l testez prea mult; l-am scris cam in graba, ca m-am intins cam mult cu tot proiectul asta). De asemenea, sper ca n-am sarit vreo linie cand l-am copiat aici pe forum...

No, cam asta ar fi; iac-asa se poate face foarte silentios un PC care are o gasca de HDD-uri in el !

---------- Post added at 03:10 ---------- Previous post was at 02:48 ----------

Preview al scriptului de mai sus:
_la oprire HDD:
Code:
----------------------------------------------------------------------------
Nr    Status    Partition 1 mountpoint          HDD ID 
----------------------------------------------------------------------------
 1:     OFF     /mnt/stor1 (xTB)        ata-Producator_Model_Serial
 2:     ON      /mnt/stor2 (yTB)         ata-Producator_Model_Serial
 3:     OFF     /mnt/stor3 (zTB)       ata-Producator_Model_Serial
 4:     OFF     /mnt/stor4 (xTB)        ata-Producator_Model_Serial
 5:     OFF     /mnt/usb1 (xxx GB)      usb-Producator_Model_Serial-0:0
 6:     OFF     /mnt/stor6 (yyy GB)     ata-Producator_Model_Serial
 7:     OFF     /mnt/stor7 (zzz GB)     ata-Producator_Model_Serial
 8:     OFF     /mnt/usb2 (xxx GB)      usb-Producator_Model_Serial-0:0
Select HDD Nr (0 to exit) : 2
HDD 2 is powered ON
detected as /dev/sdh ; check if mounted:
/dev/sdh1 on /mnt/stor2 type ext4 (rw,relatime,data=ordered)
Mounted ! Unmount /mnt/date & power off HDD 2 ? (y/n) y
 
/mnt/date unmounted OK !
Sync system & HDD 2 cache...
Set HDD 2 in idle mode ...

/dev/disk/by-id/ata-Producator_Model_Serial:
 issuing sleep command
Disconnect HDD 2 from the SATA bus...
Power off HDD 2 ...
HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  ON   OFF  OFF  OFF  OFF  OFF  OFF 

Toggling HDD 2 status...

HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  OFF  OFF  OFF  OFF  OFF  OFF  OFF 
HDD 2 OFF
[ 4669.675513] ata5: EH complete
[ 4669.675628] sd 4:0:0:0: [sdh] Stopping disk
[ 4669.675774] sdh: detected capacity change from 0 to 2.....
[ 4669.675845] ata5.00: disabled
[ 4679.201623] ata5: exception Emask 0x10 SAct 0x0 SErr 0x90202 action 0xe frozen
[ 4679.201639] ata5: irq_stat 0x00400000, PHY RDY changed
si la pornire:
Code:
----------------------------------------------------------------------------
Nr    Status    Partition 1 mountpoint          HDD ID 
----------------------------------------------------------------------------
 1:     OFF     /mnt/stor1 (xTB)        ata-Producator_Model_Serial
 2:     OFF     /mnt/stor2 (yTB)         ata-Producator_Model_Serial
 3:     OFF     /mnt/stor3 (zTB)       ata-Producator_Model_Serial
 4:     OFF     /mnt/stor4 (xTB)        ata-Producator_Model_Serial
 5:     OFF     /mnt/usb1 (xxx GB)      usb-Producator_Model_Serial-0:0
 6:     OFF     /mnt/stor6 (yyy GB)     ata-Producator_Model_Serial
 7:     OFF     /mnt/stor7 (zzz GB)     ata-Producator_Model_Serial
 8:     OFF     /mnt/usb2 (xxx GB)      usb-Producator_Model_Serial-0:0
 
Select HDD Nr (0 to exit) : 6
HDD 6 is powered OFF
Start HDD & mount /mnt/stor6 ? (y/n) y
 
HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  OFF  OFF  OFF  OFF  OFF  OFF  OFF 

Toggling HDD 6 status...

HDD Nr:  1    2    3    4    5    6    7    8
Status: OFF  OFF  OFF  OFF  OFF  ON   OFF  OFF 
 
Wait for the system to detect HDD 6 ...
detected as /dev/sdh ; now mounting...
mounted OK !
 
[ 5266.299595] ata8.00: configured for UDMA/133
[ 5266.299607] ata8: EH complete
[ 5266.299756] scsi 7:0:0:0: Direct-Access     ATA      ModelHDD      PQ: 0 ANSI: 5
[ 5266.300191] sd 7:0:0:0: [sdh]........512-byte logical blocks: (xyz GB/zyxGiB)
[ 5266.300242] sd 7:0:0:0: Attached scsi generic sg7 type 0
[ 5266.300365] sd 7:0:0:0: [sdh] Write Protect is off
[ 5266.300377] sd 7:0:0:0: [sdh] Mode Sense: 00 3a 00 00
[ 5266.300439] sd 7:0:0:0: [sdh] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 5266.335866]  sdh: sdh1
[ 5266.336712] sd 7:0:0:0: [sdh] Attached SCSI disk
 
/dev/sdh1       12345678 87654321 12312312  60% /mnt/stor6


---------- Post added at 03:45 ---------- Previous post was at 03:10 ----------

Quote:
Originally Posted by XVanish View Post
Super tare, bravo! Am citit pe sarite acum ca am de lucru dar o sa citesc atent tot ce ai mesterit si vin cu pareri. Te invidiez sa stii... eu nu mai am timp de "mesterit" mai nimic in ultima perioada.
Multam mult XVanish; adevarul e ca nici eu nu mai prea am timp de mesterit; am inceput toata treaba asta cam de prin decembrie, mesterind cate putin seara, "printre picaturi"... Iac-asa s-a intins pana acuma.
__________________
CHIAR Imi place Romanian PC Forum - www.rpc-forum.ro!

Last edited by bogdan; 03.02.2016 at 01:54.
bogdan is offline   Reply With Quote
The Following 7 Users Say Thank You to bogdan For This Useful Post:
Alin99 (05.02.2016), AnbuBlack (03.02.2016), COMAN DINU-VICE (05.02.2016), konstantine (03.02.2016), ono (03.02.2016), XVanish (03.02.2016), yo9fah (03.02.2016)
Old 03.02.2016, 15:01   #5
sdw
RPC Gold Member
 
Join Date: 02.03.2011
Age: 42
Posts: 975
Thanks: 20
Thanked 1,079 Times in 575 Posts
Default Re: Interfata relee pornire hard disk-uri

O imbunatatire posibila a softului de control ar fi prin folosirea xinetd-ului pentru comanda (in felul asta nu mai ai nevoie de sudo). Iar ca efect secundar, vei putea controla sistemul remote fara SSH. Eu fac frecvent chestia asta cand am nevoie sa execut comenzi ce au nevoie de drepturi elevate din aplicatii web, si nu vrea sa las apache sa execute ce vrea el. Si atunci doar transmit un mic "semnal" pe un socket tcp prin xinetd, care la randul lui executa ca root ce script am eu chef.

---------- Post added at 16:01 ---------- Previous post was at 15:56 ----------

Uite un exemplu de serviciu xinetd customizat:

Code:
service lanctrl
{
                disable = no
                wait = no
                type = UNLISTED
                socket_type = stream
                bind = 127.0.0.1
                port = 6666
                user = root
                group = root
                server = /var/www/vhosts/lanctrl.wifimag.ro/bin/xinetd.php
}
Cand te conectezi pe tcp la portul 6666, se executa scriptul /var/www/vhosts/lanctrl.wifimag.ro/bin/xinetd.php, cu privilegii de root.
__________________
E bine să ai mintea deschisă, dar nu aşa deschisă încât să-ţi cadă creierul.
sdw is offline   Reply With Quote
The Following 5 Users Say Thank You to sdw For This Useful Post:
Alin99 (05.02.2016), bogdan (03.02.2016), konstantine (04.02.2016), ono (05.02.2016), XVanish (03.02.2016)
Old 03.02.2016, 20:11   #6
bogdan
RPC Super Moderator
 
bogdan's Avatar
 
Join Date: 26.06.2010
Posts: 5,333
Thanks: 5,829
Thanked 7,829 Times in 3,982 Posts
Default Re: Interfata relee pornire hard disk-uri

Multam mult sdw, foarte utila treaba asta !
__________________
CHIAR Imi place Romanian PC Forum - www.rpc-forum.ro!
bogdan is offline   Reply With Quote
The Following 3 Users Say Thank You to bogdan For This Useful Post:
Alin99 (05.02.2016), ono (05.02.2016), XVanish (03.02.2016)
Old 05.02.2016, 07:39   #7
Emanuelul
RPC Gold Member
 
Join Date: 30.08.2010
Location: Bucuresti
Age: 50
Posts: 885
Thanks: 129
Thanked 661 Times in 379 Posts
Default Re: Interfata relee pornire hard disk-uri

Bravo Bogdane!! Felicitari pt realizare!!!!
__________________
Imi place Romanian PC Forum - www.rpc-forum.ro!
Emanuelul is offline   Reply With Quote
Old 05.02.2016, 12:46   #8
bogdan
RPC Super Moderator
 
bogdan's Avatar
 
Join Date: 26.06.2010
Posts: 5,333
Thanks: 5,829
Thanked 7,829 Times in 3,982 Posts
Default Re: Interfata relee pornire hard disk-uri

Quote:
Originally Posted by Emanuelul View Post
Bravo Bogdane!! Felicitari pt realizare!!!!
Multam mult Emanuelule !
__________________
CHIAR Imi place Romanian PC Forum - www.rpc-forum.ro!
bogdan is offline   Reply With Quote
Old 05.02.2016, 13:40   #9
Alin99
RPC Gold Member
 
Alin99's Avatar
 
Join Date: 12.11.2010
Location: somewhere in world
Posts: 4,495
Thanks: 5,586
Thanked 3,494 Times in 2,043 Posts
Default Re: Interfata relee pornire hard disk-uri

Super, felicitari pentru proiect, patenteaza-l pana nu iti fura careva ideea!
__________________
TOSHIBA LED TV 43" 4K
VU+SOLO2 , VU+SOLO4K , Prime focus 1.80m,offset 1.30m,offset 1.00m
Multifeed 42E,28.2E,19.2E,16E,13E,9E,1W,5W DiSEqC Multimode Switch 8in+1 EMP - Centauri
Alin99 is offline   Reply With Quote
The Following 2 Users Say Thank You to Alin99 For This Useful Post:
bogdan (07.02.2016), COMAN DINU-VICE (05.02.2016)
Old 05.02.2016, 20:08   #10
COMAN DINU-VICE
RPC Gold Member
 
COMAN DINU-VICE's Avatar
 
Join Date: 19.09.2010
Location: Castellon de la Plana -ESPAŃA
Age: 54
Posts: 675
Thanks: 1,250
Thanked 1,233 Times in 491 Posts
Send a message via Yahoo to COMAN DINU-VICE
Default Re: Interfata relee pornire hard disk-uri

Buna treaba ! Clar ca este un project "copt" de mai mult timp ! Felicitari !
Attached Images
File Type: jpg 12046730_10207213476431368_1182247902388877152_n.jpg (42.7 KB, 4 views)
__________________
Nimeni nu conduce daca nimeni nu se supune. Tao Do
COMAN DINU-VICE is offline   Reply With Quote
The Following 3 Users Say Thank You to COMAN DINU-VICE For This Useful Post:
Alin99 (05.02.2016), bogdan (07.02.2016), konstantine (05.02.2016)
Old 05.02.2016, 22:21   #11
konstantine
RPC Gold Member
 
konstantine's Avatar
 
Join Date: 27.09.2012
Posts: 426
Thanks: 716
Thanked 413 Times in 223 Posts
Send a message via Skype™ to konstantine
Default Re: Interfata relee pornire hard disk-uri

Quote:
Originally Posted by Alin99 View Post
patenteaza-l pana nu iti fura careva ideea!
Nu zi de doua ori...Ca apare si lpf3.ro ( stiti la ce "bule" fac refrerire)
__________________
Citat din Ram Daas:“The quieter you become, the more you can hear.”
konstantine is offline   Reply With Quote
Old 07.02.2016, 18:15   #12
bogdan
RPC Super Moderator
 
bogdan's Avatar
 
Join Date: 26.06.2010
Posts: 5,333
Thanks: 5,829
Thanked 7,829 Times in 3,982 Posts
Default Re: Interfata relee pornire hard disk-uri

Va multumesc tuturor pentru aprecieri si comentarii. De patentat... l-am "patentat" deja publicandu-l aici ! Cine doreste sa isi mestereasca asa ceva, are toata informatia disponibila. Plus, bineinteles, raspund cu placere intrebarilor legate de detalii.
__________________
CHIAR Imi place Romanian PC Forum - www.rpc-forum.ro!
bogdan is offline   Reply With Quote
The Following 4 Users Say Thank You to bogdan For This Useful Post:
Alin99 (08.02.2016), COMAN DINU-VICE (09.02.2016), konstantine (07.02.2016), ono (07.02.2016)
Reply

Bookmarks

Tags
hard drive , parallel port , relay , switck


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seagate livrează hard disk-uri de 8TB Alin99 IT&C News 1 30.08.2014 17:58
Hard Disk Extern Curierul Windows 25 24.03.2014 15:27
Hard disk notebook AnbuBlack Unitati de stocare 7 23.03.2014 11:52
how to clone hard disk to ssd Alin99 Windows 0 10.12.2012 00:04
probleme hard disk petricaiancu Suport Tehnic 5 13.12.2011 18:37

 
Advertisement




camere foto digitale

aparate foto digitale


Partner Links
Sabitech Media - dezvoltare web, servicii media

RSP Forum - sateliti.info
Comunitate Satelitara






All times are GMT +2. The time now is 18:34.


Powered by vBulletin® - © Jelsoft Enterprises Ltd.
~ Copyright © 2007-2015 Romanian PC Forum ~
Toate drepturile rezervate

Romanian Sattelites Provider Wi-Fi Magazin