Outils pour utilisateurs

Outils du site


blog

SystemD Autofs Automount

Ou comment monter automatiquement un lecteur via SystemD

Voir :

Voir aussi

/etc/systemd/system/mnt-partage.mount

[Unit]
Description=Partage
 
[Mount]
What=//serveur/Partage
Where=/mnt/partage
Type=cifs
#Options=_netdev,rw,uid=1100,forceuid,gid=1100,forcegid,file_mode=0777,dir_mode=0777,noperm,credentials=/root/.cifs_partage
Options=noexec,nosuid,nodev,rw,uid=1100,forceuid,gid=1100,forcegid,file_mode=0777,dir_mode=0777,noperm,credentials=/root/.cifs_partage
 
[Install]
WantedBy=multi-user.target

/etc/systemd/system/mnt-partage.automount

[Unit]
Description=Automount Partage
#Requires=network-online.target
#After=network-online.service
 
[Automount]
Where=/mnt/partage
TimeoutIdleSec=10
 
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
 
systemctl disable mnt-partage.mount
systemctl enable mnt-partage.automount

Remarque : le nom du fichier à son importance. Pour un montage /mnt/plop le fichier doit s'appeler mnt-plop.mount

Vérif

systemctl status /mnt/partage
journalctl -u /mnt/partage

La partition est vu comme montée en autofs par la commande mount

# mount |grep /mnt/partage
systemd-1 on /mnt/partage type autofs (rw,relatime,fd=28,pgrp=1,timeout=10,minproto=5,maxproto=5,direct,pipe_ino=38828)

En cas de pb pour forcer le démontage. A utiliser si la commande df ne rien pas la main.

sudo umount -a -t cifs -l
sudo umount -a -t autofs -l

Diag

Pour retrouver le nom du service KO :

systemctl list-units --state failed --type mount --type automount --no-pager

Puis copier-coller le nom entre des quotes

systemctl status 'mnt-app-c888_yy\x2yyyy\x2yyy\x2dapp-data-mounts-Quayyyyyy-Envoi.mount' 
dmesg

Autres

Si caractères spéciaux

$ systemd-escape --suffix mount -p /mnt/foo-bar
mnt-foo\x2dbar.mount
 
$ systemd-escape -u 'mnt-foo\x2dbar.mount'
mnt/foo-bar.mount

NOTE : '\x' pour échapper ASCII en notation hexadécimale
'2d' corespond au code hexa du trait d'union.

https://github.com/systemd/systemd/blob/master/units/sys-fs-fuse-connections.mount

/etc/systemd/sys-fs-fuse-connections.mount

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
 
[Unit]
Description=FUSE Control File System
Documentation=https://www.kernel.org/doc/Documentation/filesystems/fuse.txt
Documentation=https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
ConditionPathExists=/sys/fs/fuse/connections
ConditionCapability=CAP_SYS_ADMIN
ConditionVirtualization=!private-users
After=systemd-modules-load.service
Before=sysinit.target
 
[Mount]
What=fusectl
Where=/sys/fs/fuse/connections
Type=fusectl
Options=nosuid,nodev,noexec
Si SNMP

Message d'erreur sur la console si partage injoignable

CIFS VFS: cifs_mount failed w/return code

Solution

/etc/snmp/snmpd.conf

skipNFSInHostResources 1

Autres solution

https://www.justegeek.fr/montage-automatique-partages-cifs-systemd/

Ajouter l'option suivant dans le fstab : x-systemd.automount,x-systemd.device-timeout=3

2025/03/24 15:06

Sécu - Scan de vulnérabilités

Voir :

  • suricata
  • openvas
  • nmap
  • Qualys
2025/03/24 15:06

SystemD - lingering

loginctl disable-linger jean
loginctl enable-linger jean
loginctl show-user $(id -u)

L'activation du lingering crée un fichier vide au nom de l'utilisateur dans le dossier /var/lib/systemd/linger/

mkdir -p ~/.config/systemd/user
restorecon -rv ~/.config/

~/.bashrc

export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
export XDG_RUNTIME_DIR=/run/user/$(id -u)

~/.config/systemd/user/plop.service

[Unit]
Description=Script plop
After=syslog.target network.target network-online.target
Wants=network.target network-online.target
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/opt/plop/bin/init.sh start
ExecStop=/opt/plop/bin/init.sh stop
RemainAfterExit=yes
 
[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable plop.service
2025/03/24 15:06

Syntax validator tool

Voir :

Langage Outil
Javascript esvalidate
Ansible ansible-lint
Bash shellcheck

Linter Multi langage :

2025/03/24 15:06

Swap sur ramdisk

Voir :

Source : https://wiki.archlinux.org/index.php/Maximizing_performance

modprobe zram
echo lz4 > /sys/block/zram0/comp_algorithm
echo 1G > /sys/block/zram0/disksize
mkswap --label zram0 /dev/zram0
swapon --priority 100 /dev/zram0

Erreur

echo 1G > /sys/block/zram0/disksize

-bash: echo: write error: Invalid argument

dmesg |grep zram
[29996.637522] zram: Cannot initialise lz4

Solution

echo "lzo" > /sys/block/zram0/comp_algorithm

Autres

modprobe zram
echo 3 > /sys/block/zram0/max_comp_streams
echo "lzo" > /sys/block/zram0/comp_algorithm
echo 100M > /sys/block/zram0/disksize
mkswap --label zram0 /dev/zram0
swapon --priority 100 /dev/zram0
2025/03/24 15:06
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki