Discussion:
udev rule to mount ext4 with data=journal
(too old to reply)
Pascal K
2017-06-14 07:30:09 UTC
Permalink
Raw Message
Hello everyone,

I am new to this list and to udev (used mdev before).

My goal: Mount a CFast card partioned with 2 partitions one FAT32 and one
EXT4, the EXT4 I would like to mount with option "data=journal"

The Problem: from the console using mount the partition can be mounted with
mount -o "data=journal" ... but not from my udev rule. My rule results in
only the FAT32 partition being mounted.

My Rule:

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Global mount options
ACTION=="add", ENV{mount_options}="relatime"

# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs",
ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
ACTION=="add", ENV{ID_FS_TYPE}=="ext4",
ENV{mount_options}="$env{mount_options},data=journal"

#Mount the Filesystems
ACTION=="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}",
RUN+="/bin/mount -o %E{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"

# Exit
LABEL="media_by_label_auto_mount_end"

Any help is highly appreciated, so far I can only mount with "data=ordered"
since this seems to be the default option (for that the two lines matching
"ENV{ID_FS_TYPE} are removed).

Best regards
Pascal
Michał Zegan
2017-06-14 07:31:55 UTC
Permalink
Raw Message
Hmm, why not to place such things in /etc/fstab?
Post by Pascal K
Hello everyone,
I am new to this list and to udev (used mdev before).
My goal: Mount a CFast card partioned with 2 partitions one FAT32 and
one EXT4, the EXT4 I would like to mount with option "data=journal"
The Problem: from the console using mount the partition can be mounted
with mount -o "data=journal" ... but not from my udev rule. My rule
results in only the FAT32 partition being mounted.
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs",
ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
ACTION=="add", ENV{ID_FS_TYPE}=="ext4",
ENV{mount_options}="$env{mount_options},data=journal"
#Mount the Filesystems
ACTION=="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}",
RUN+="/bin/mount -o %E{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"
# Exit
LABEL="media_by_label_auto_mount_end"
Any help is highly appreciated, so far I can only mount with
"data=ordered" since this seems to be the default option (for that the
two lines matching "ENV{ID_FS_TYPE} are removed).
Best regards
Pascal
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Lennart Poettering
2017-06-14 08:05:31 UTC
Permalink
Raw Message
Post by Pascal K
Hello everyone,
I am new to this list and to udev (used mdev before).
My goal: Mount a CFast card partioned with 2 partitions one FAT32 and one
EXT4, the EXT4 I would like to mount with option "data=journal"
The Problem: from the console using mount the partition can be mounted with
mount -o "data=journal" ... but not from my udev rule. My rule results in
only the FAT32 partition being mounted.
Note that we run udevd in its own mount namespace through MountFlags=,
and this means no mounts will ever appear on the host anyway.

Note that it is sufficient to mark mounts as "auto,nofail" in
/etc/fstab to make sure they are mounted automatically as they appear
without making the boot wait for it.

Lennart
--
Lennart Poettering, Red Hat
Pascal K
2017-06-14 08:11:00 UTC
Permalink
Raw Message
I try to achieve that regardless the device plugged to my embedded system
the mount will be in folder /media/"name_of_volume".

If I understand correctly for the usage of fstab I have to give a static
name for the mount point.

Thanks for pointing out the "nofail" option.

Best regards,
Pascal
Post by Lennart Poettering
Post by Pascal K
Hello everyone,
I am new to this list and to udev (used mdev before).
My goal: Mount a CFast card partioned with 2 partitions one FAT32 and one
EXT4, the EXT4 I would like to mount with option "data=journal"
The Problem: from the console using mount the partition can be mounted
with
Post by Pascal K
mount -o "data=journal" ... but not from my udev rule. My rule results in
only the FAT32 partition being mounted.
Note that we run udevd in its own mount namespace through MountFlags=,
and this means no mounts will ever appear on the host anyway.
Note that it is sufficient to mark mounts as "auto,nofail" in
/etc/fstab to make sure they are mounted automatically as they appear
without making the boot wait for it.
Lennart
--
Lennart Poettering, Red Hat
Lennart Poettering
2017-06-14 08:30:28 UTC
Permalink
Raw Message
Post by Pascal K
I try to achieve that regardless the device plugged to my embedded system
the mount will be in folder /media/"name_of_volume".
If I understand correctly for the usage of fstab I have to give a static
name for the mount point.
It appears to me "systemd-mount" is the functionality you want to use
for this. It will automatically derive a usable name from the device
metadata and install an automount instance for it, so that there's the
best chance for the device's file system to always stay in a clean state.

You can invoke systemd-mount directly from the udev rule.

Lennart
--
Lennart Poettering, Red Hat
Pascal K
2017-06-14 08:44:48 UTC
Permalink
Raw Message
As I am on a embedded device I am trying to avoid the usage of systemd due
to serveral reasons.

@Lennart
Post by Lennart Poettering
Note that we run udevd in its own mount namespace through MountFlags=,
and this means no mounts will ever appear on the host anyway.
Am I right that this means that with setting ENV{mount_options} I am
setting a variable from udevd namespace, therefore "...mount -o
%E{mount_options}..." should try to run /sbin/mount with the options I
selected before?

Best regards,
Pascal
Post by Lennart Poettering
Post by Pascal K
I try to achieve that regardless the device plugged to my embedded system
the mount will be in folder /media/"name_of_volume".
If I understand correctly for the usage of fstab I have to give a static
name for the mount point.
It appears to me "systemd-mount" is the functionality you want to use
for this. It will automatically derive a usable name from the device
metadata and install an automount instance for it, so that there's the
best chance for the device's file system to always stay in a clean state.
You can invoke systemd-mount directly from the udev rule.
Lennart
--
Lennart Poettering, Red Hat
Michael Biebl
2017-06-14 09:13:09 UTC
Permalink
Raw Message
Post by Pascal K
As I am on a embedded device I am trying to avoid the usage of systemd due
to serveral reasons.
Does that mean you are not using systemd as PID 1?
--
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
Lennart Poettering
2017-06-14 09:23:33 UTC
Permalink
Raw Message
Post by Pascal K
As I am on a embedded device I am trying to avoid the usage of systemd due
to serveral reasons.
Not sure I follow the logic in the above, but if you don't want to use
systemd, then you should probably run something else that can do most
basic disk management for you.

udev isn't really the right tool for the job.

Sorry,

Lennart
--
Lennart Poettering, Red Hat
Pascal K
2017-06-14 09:43:30 UTC
Permalink
Raw Message
To clear things up a bit:

I build a Image using Buildroot running Busybox on top. I have SystemVinit.

Is there something else commonly used out there? Otherwise I just create my
own daemon.

Best regards,
Pascal
Post by Lennart Poettering
Post by Pascal K
As I am on a embedded device I am trying to avoid the usage of systemd
due
Post by Pascal K
to serveral reasons.
Not sure I follow the logic in the above, but if you don't want to use
systemd, then you should probably run something else that can do most
basic disk management for you.
udev isn't really the right tool for the job.
Sorry,
Lennart
--
Lennart Poettering, Red Hat
Loading...