SliTaz SliTaz Forum

You are not logged in.

#1 2016-01-01 20:23:15

gibor
Moderator
Registered: 2011-04-30
Posts: 1,067

Udev rules to automount usb drive

Hi at all, I tried this Udev rules, but create the folder basic sda or sdb...

I want to make only util partition sda1, sda2 ecc, if and it possible to skip partition swap.

This is file to have tested

11-media-by-label-auto-mount.rules

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"

ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"

# Non effettua il mount di file system già montati in altri percorsi per evitare che in /media si creino voci per tutte le partizioni locali

ACTION=="add", PROGRAM=="/bin/grep -q ' /dev/%k ' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end"

# Apre la partizione LUKS se necessario

PROGRAM=="/sbin/blkid -o value -s TYPE %N",  RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"

ENV{crypto}=="", ENV{device}="%N"

ACTION=="add", ENV{crypto}!="", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /sbin/cryptsetup luksOpen %N %k'"

ACTION=="add", ENV{crypto}!="", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"

# Opzioni globali per il comando mount

ACTION=="add", ENV{mount_options}="noatime"

# opzioni di mount specifiche per i filesystem

ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"

# Individua l'etichetta se esiste, altrimenti ne crea una

PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c"

# Utilizza basename per to gestire etichette come ../mnt/foo

PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"

ENV{dir_name}=="", ENV{dir_name}="%k"

# Effettua il mount della periferica

ACTION=="add", ENV{dir_name}!="", RUN+="/bin/mkdir -p '/media/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '/media/%E{dir_name}'"

# Effettua la pulizia delle directory alla rimozione della periferica

ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'"

ACTION=="remove", ENV{crypto}!="", RUN+="/sbin/cryptsetup luksClose %k"

ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/rmdir '/media/%E{dir_name}'"

# Uscita

LABEL="media_by_label_auto_mount_end"

any ideas?

Thank in advance.

Offline

#2 2016-01-02 21:32:23

llev
Member
Registered: 2011-12-09
Posts: 568

Re: Udev rules to automount usb drive

Hi gibor,

I don't understand why you would need to write a rules file: your file manager, pcmanfm or spacefm, should have a setting to enable automounting of removable/hotpluggable device. Doesn't it?

Offline

#3 2016-01-02 22:17:45

gibor
Moderator
Registered: 2011-04-30
Posts: 1,067

Re: Udev rules to automount usb drive

Hi llev,

why I want system less Gnome or polkit dependencies.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.018 seconds, 7 queries executed - Memory usage: 1.53 MiB (Peak: 1.77 MiB) ]