Bonjour,

J'essaie de configurer un script systemd qui coupe automatiquement un disque dur au démarrage de fedora. Ce disque dur ntfs est uniquement utile pour moi quand je suis sur le dual boot windows mais jamais sous fedora. Donc économie en energie et silence 🙂.

Sauf que mon script actuel dès fois marche... mais dès fois ne marche pas sans erreur pour autant dans status où le sleep se lance bien mais en réalité un hdparm -C me dit qu'il est en idle, pas standby. Donc je suis obligé de relancer manuellement un systemctl start hdparm.service et là il se couche...
system]$ cat hdparm.service
[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/sbin/hdparm -Y /dev/sda1

[Install]
WantedBy=multi-user.target
Merci
Je n'y connait pas grand chose en hdparm, mais ta commande "ExecStart=/usr/sbin/hdparm -Y /dev/sda1" me semble affecter qu'une partie de ton disque sda,
Essaye en enlevant le 1 de sda1
chepioq wrote:Je n'y connait pas grand chose en hdparm, mais ta commande "ExecStart=/usr/sbin/hdparm -Y /dev/sda1" me semble affecter qu'une partie de ton disque sda,
Essaye en enlevant le 1 de sda1
Ben oui ! 😉 😉 😉
[Résolu] donc !!!
sympa ce truc
Eh nan , pas résolu :p. Ce serait trop simple ! 😉
J'ai bien édité en virant le 1, même si en exécutant le script avec le 1 dedans il arrêtait bien le moteur du disque dur mais que après boot (voir la suite).
cat hdparm.service
[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/sbin/hdparm -Y /dev/sda

[Install]
WantedBy=multi-user.target
Au démarrage le script se lance ....
hdparm.service - hdparm sleep
   Loaded: loaded (/etc/systemd/system/hdparm.service; enabled; vendor preset: d
   Active: inactive (dead) since Tue 2017-06-20 19:13:45 CEST; 1min 56s ago
  Process: 689 ExecStart=/usr/sbin/hdparm -Y /dev/sda (code=exited, status=0/SUC
 Main PID: 689 (code=exited, status=0/SUCCESS)

juin 20 19:13:45 john systemd[1]: Starting hdparm sleep...
juin 20 19:13:45 john hdparm[689]: /dev/sda:
juin 20 19:13:45 john hdparm[689]:  issuing sleep command
juin 20 19:13:45 john systemd[1]: Started hdparm sleep.
Mais rien ne change. Disque en idle, et il ne s'est pas arrêté entre temps...
sudo hdparm -C /dev/sda

/dev/sda:
 drive state is:  active/idle
Seule solution : sudo systemctl start hdparm.service
Ce qu'il relance ...
 hdparm.service - hdparm sleep
   Loaded: loaded (/etc/systemd/system/hdparm.service; enabled; vendor preset: d
   Active: inactive (dead) since Tue 2017-06-20 19:18:11 CEST; 25s ago
  Process: 2223 ExecStart=/usr/sbin/hdparm -Y /dev/sda (code=exited, status=0/SU
 Main PID: 2223 (code=exited, status=0/SUCCESS)

juin 20 19:18:11 john systemd[1]: Starting hdparm sleep...
juin 20 19:18:11 john hdparm[2223]: /dev/sda:
juin 20 19:18:11 john hdparm[2223]:  issuing sleep command
juin 20 19:18:11 john systemd[1]: Started hdparm sleep.
Et là magie :
sudo hdparm -C /dev/sda

/dev/sda:
 drive state is:  standby
J'ai l'impression, enfin théorie théorie... Que au moment du démarrage où il lance le hdparm, il ne veut rien comprendre alors que quand ça a booté ça marche...
Je pense que lorsque ton service hdparm se lance, ton disque n'est pas encore monté, donc il ne fait rien.
Il faudrait peut-être mettre une option dans ton hdparm.service, du genre after=....., mais je ne sais pas vraiment "after quoi"
J'ai tenté avec un délai dans la commande hdparm
hdparm.service - hdparm sleep
   Loaded: loaded (/etc/systemd/system/hdparm.service; enabled; vendor preset: d
   Active: inactive (dead) since Tue 2017-06-20 22:16:56 CEST; 44s ago
  Process: 677 ExecStart=/usr/sbin/hdparm -Y -S12 /dev/sda (code=exited, status
 Main PID: 677 (code=exited, status=0/SUCCESS)

juin 20 22:16:56 john systemd[1]: Starting hdparm sleep...
juin 20 22:16:56 john hdparm[677]: /dev/sda:
juin 20 22:16:56 john hdparm[677]:  setting standby to 12 (1 minutes)
juin 20 22:16:56 john hdparm[677]:  issuing sleep command
juin 20 22:16:56 john systemd[1]: Started hdparm sleep.
Sans succès...
sudo hdparm -C /dev/sda

/dev/sda:
drive state is: active/idle

Malgré le timing, comme dit chepioq , ça doit s'exécuter quand le disque n'est pas monté, donc il en a rien a foutre 🙁.
Il faudrait peut-être lancer ce service après le lancement de ton gestionnaire de connexion (gdm, sddm ou un autre).Chez moi c'est sddm, je mettrai donc:
[Unit]
Description=hdparm sleep
After=sddm.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/hdparm -Y /dev/sda

[Install]
WantedBy=multi-user.target
A toi de savoir quel est ton gestionnaire de connexion
Ca à l'air de marcher. Merci 🙂.
J'ai mis "After=sddm.service" car je sais qu'après le lancement de sddm toutes les partitions sont montées.
Il serait intéressant de savoir quelle est le service qui "monte" les partition, de manière à lancer ton service hdparm.service le plus tôt possible.
Pour moi c'était gdm.service. Aucune idée pour le service qui monte les partitions...
trouver le service qui lit fstab c'est possible ?
nouvo09 wrote:trouver le service qui lit fstab c'est possible ?
J'ai cherché mais je ne trouve pas.
chepioq wrote:
nouvo09 wrote:trouver le service qui lit fstab c'est possible ?
J'ai cherché mais je ne trouve pas.
Peut-être ça ?
https://www.freedesktop.org/software/systemd/man/systemd-fstab-generator.html#
https://www.freedesktop.org/software/systemd/man/systemd.generator.html#
After editing /etc/fstab, the user should invoke systemctl daemon-reload. This will re-run all generators and cause systemd to reload units from disk. To actually mount new directories added to fstab, systemctl start /path/to/mountpoint or systemctl start local-fs.target may be used.
Il y a aussi ces services, mais je suis loin de connaitre vraiment le fonctionnement de systemd:
/usr/lib/systemd/system/local-fs.target
/usr/lib/systemd/system/local-fs.target.wants
/usr/lib/systemd/system/local-fs.target.wants/fedora-import-state.service
/usr/lib/systemd/system/local-fs.target.wants/fedora-readonly.service
/usr/lib/systemd/system/local-fs.target.wants/systemd-remount-fs.service
/usr/lib/systemd/system/local-fs.target.wants/tmp.mount
/usr/lib/systemd/system/local-fs.target.wants/var-lib-machines.mount
EDIT::
Donc je dirais: local-fs.target (et le mettre en: WantedBy ?)
Je ne sais pas si c'est une bonne idée par contre, de le mettre aussi tôt, et si ça peut perturber le démarrage