Overriding automounted filesystem options


#1

Hi,

would it be possible to change the default mount options for ntfs-3g to make it compatible with windows (most people who use ntfs is for compatibility with windows)?
It would require to mount with “windows_names”. At the moment, after some weeks of using Manjaro with NTFS partitions, I had many files deleted by chkdisk and a lot of errors reported/unaccessible folders because of the mount option missing. Of course manually mounting solves the problem, but good defaults saves a lot of time and allow more user to step in.


Changing Manjaro's default NTFS mount options
Avoid ntfs corruption with bad file names
Avoid ntfs corruption with bad file names
#2

76 posts were split to a new topic: Changing Manjaro’s default NTFS mount options


#17

something like this could be sufficent

KERNEL=="sd[a-z][1-99]" SUBSYSTEM=="block" SUBSYSTEMS=="usb" ACTION=="add" ENV{ID_FS_TYPE}=="ntfs" SYMLINK+="winpart-'%E{ID_FS_UUID}'" RUN+="/home/mv/mount_via_udev.sh '%E{DEVNAME}'"

adjust script path , maybe better without symlink and as I dont have a usb ntfs stick not sure about the right ID_FS_TYPE name (tested with vfat, check with ntfs stick for correct id_fs_type)

mount script something like this:

#!/bin/sh

mount $1 -o windows_names,uid=1000,gid=users,noatime,errors=remount-ro,dmask=022,fmask=133,nls=iso8859-1 /mnt

adjust mountpoint and maybe add something that use unique one (to allow multiple devices mounted that way)
uid also need something better to allow better adjustment to actual user (instead of jsut 1000/username)


Avoid ntfs corruption with bad file names
#40

maybe the easiest way:
create pkgbuild
add udiskie as dependency
create udev rule like above just use udisksctl instead of script
then anybody who want ntfs automount with windows_names option can install the pkg


#41

if you can do it, please :slight_smile:


#42
─────────────────────────────────────────────────── NTFS write support ─────────────────────────────────────────────────────┐
  │ CONFIG_NTFS_RW:                                                                                                             │  
  │                                                                                                                             │  
  │ This enables the partial, but safe, write support in the NTFS driver.                                                       │  
  │                                                                                                                             │  
  │ The only supported operation is overwriting existing files, without                                                         │  
  │ changing the file length.  No file or directory creation, deletion or                                                       │  
  │ renaming is possible.  Note only non-resident files can be written to                                                       │  
  │ so you may find that some very small files (<500 bytes or so) cannot                                                        │  
  │ be written to.                                                                                                              │  
  │                                                                                                                             │  
  │ While we cannot guarantee that it will not damage any data, we have                                                         │  
  │ so far not received a single report where the driver would have                                                             │  
  │ damaged someones data so we assume it is perfectly safe to use.                                                             │  
  │                                                                                                                             │  
  │ Note:  While write support is safe in this version (a rewrite from                                                          │  
  │ scratch of the NTFS support), it should be noted that the old NTFS                                                          │  
  │ write support, included in Linux 2.5.10 and before (since 1997),                                                            │  
  │ is not safe.                                                                                                                │  
  │                                                                                                                             │  
  │ This is currently useful with TopologiLinux.  TopologiLinux is run                                                          │  
  │ on top of any DOS/Microsoft Windows system without partitioning your                                                        │  
  │ hard disk.  Unlike other Linux distributions TopologiLinux does not                                                         │  
  │ need its own partition.  For more information see                                                                           │  
  │ <http://topologi-linux.sourceforge.net/>

So built-in kernel NTFS writing is kinda meh.
Udev rule you proposed would work better.
There was a complaint about it calling a bash script, so I suggest the script is injected into the udev rule itself.

Found this for mounting NTFS as ro by default. Should be easy to modify to include windows_names.

Also, samba issues are off-topic here imho.


#47

pkgbuild e.g. something like this:

pkgname="ntfs_mount_udev_udisksctl"
pkgver=1
pkgrel=1
pkgdesc="simple udev rule which automounts ntfs with windows_names via udisksctl"
license=("none")
depends=('udisks2')
arch=('x86_64')

# install location package
prefixdir="/etc/udev/rules.d"

prepare() {
#mkdir -p ${srcdir}/${prefixdir}
# create udev rule
cat <<'EOF'> "${srcdir}/90-ntfs-automount-win_names.rules"
KERNEL=="sd[a-z][1-99]" SUBSYSTEM=="block" SUBSYSTEMS=="usb" ACTION=="add" ENV{ID_FS_TYPE}=="ntfs" SYMLINK+="winpart'%E{ID_FS_UUID}'" RUN+="/usr/bin/udisksctl mount --no-user-interaction -o windows_names -b /dev/%k"
EOF

}


package() {
cd "${srcdir}"
install -Dm644 90-ntfs-automount-win_names.rules "${pkgdir}/${prefixdir}/90-ntfs-automount-win_names.rules"

}

but not working yet, why dont know yet
command is executed, but fails (although works if I enter the same command in terminal ? maybe because su executes it?)

journalctl:
Process ‘/usr/bin/udisksctl mount --no-user-interaction -o windows_names -b /dev/sdc1’ failed with error code 1

mv@mv-pc:~/MyStuff/udiskie-pkg$ /usr/bin/udisksctl mount --no-user-interaction -o windows_names -b /dev/sdc1
Mounted /dev/sdc1 at /run/media/mv/251327DC0A47DCA2.

?


#54

now it mounts

mv@mv-pc:/media/251327DC0A47DCA2$ journalctl -r -b --no-pager | grep media
Feb 16 15:55:57 mv-pc udisksd[853]: Mounted /dev/sdc1 at /media/251327DC0A47DCA2 on behalf of uid 0
Feb 16 15:55:57 mv-pc systemd[1]: Started Clean the /media/251327DC0A47DCA2 mount point.
Feb 16 15:55:31 mv-pc systemd[1]: Mounted /media/Datengrab.
Feb 16 15:55:31 mv-pc systemd[1]: Mounting /media/Datengrab...
Feb 16 15:55:30 mv-pc kernel: media: Linux media interface: v0.10
mv@mv-pc:/media/251327DC0A47DCA2$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
dev              4004184         0   4004184   0% /dev
run              4010852      1144   4009708   1% /run
/dev/sda3       79342472  69364324   5924748  93% /
tmpfs            4010852         0   4010852   0% /dev/shm
tmpfs            4010852         0   4010852   0% /sys/fs/cgroup
tmpfs            4010852        12   4010840   1% /tmp
/dev/sda1         207251    121842     74709  62% /boot
/dev/sdb3      382537892 354476620   8606348  98% /media/Datengrab
tmpfs             802168        12    802156   1% /run/user/1000
/dev/sdc1        7688188     39172   7649016   1% /media/251327DC0A47DCA2
mv@mv-pc:/media/251327DC0A47DCA2$ mkdir Test
mv@mv-pc:/media/251327DC0A47DCA2$ mkdir 'Test\'
mkdir: cannot create directory 'Test\\': Invalid argument

but after unmount it wont mount again? (with udev. same command in terminal works)

Process '/usr/bin/udisksctl mount -o windows_names -b '/dev/sdc1'' failed with exit code 1.

PKGBUILD

kgname="ntfs_mount_udev_udisksctl"
pkgver=1
pkgrel=1
pkgdesc="simple udev rule which automounts ntfs with windows_names via udisksctl"
license=("none")
depends=('udisks2')
arch=('x86_64')

# install location package
prefixdir="/usr"

prepare() {
# create udev rule
cat <<'EOF'> "${srcdir}/90-ntfs-automount-win_names.rules"
KERNEL=="sd[a-z][1-99]" SUBSYSTEM=="block" SUBSYSTEMS=="usb" ACTION=="add" ENV{ID_FS_TYPE}=="ntfs" ENV{UDISKS_FILESYSTEM_SHARED}="1" RUN+="/usr/bin/udisksctl mount -o windows_names -b '%E{DEVNAME}'"
EOF

}


package() {
cd "${srcdir}"
install -Dm644 90-ntfs-automount-win_names.rules "${pkgdir}/${prefixdir}/lib/udev/rules.d/90-ntfs-automount-win_names.rules"
}

(without FILESYSTEM_SHARED it would be mounted in /run/media/root/… instead user and only accessible for root)


#57

it uses ntfs-3g

also note that mount.ntfs is a symlink to ntfs-3g

ls -l /usr/bin/mount.ntfs
lrwxrwxrwx 1 root root 16 29. Mär 2017 /usr/bin/mount.ntfs -> /usr/bin/ntfs-3g

I added env{Filesystem_Shared}, without the partition was mounted in /run/media/root/…

why it won’t work after unmount, removing and adding the device again, but in terminal, -> ?


#67

@dufloch

this way it seems to work:

  • use systemd and create unit for user (to ensure right mount path)
  • start udisike with custom config
  • in config specifiy mount option windows_names for ntfs

PKGBUILD:

pkgname="udiskie-mount-ntfs-windows_names"
pkgver=1
pkgrel=1
pkgdesc="simple systemctl unit which start udiskie and config.json for ntfs automount with windows_names option"
license=("none")
depends=('udiskie')
source=('udiskie.service' 'config.json')
sha256sums=('ef10e5b4350f35a18a5f522bb843b4692b1925c3697d9b035bc3dc8efb8b8bd2' 'fc37599544090e9ed99d10eeffcaa8faf9e7a5767dba0e8bfd92c1ed5f57b526')
arch=('x86_64')

# install location package
systemd_dir="/etc/systemd/user"
udskie_conf="/usr/local/share/udiskie"

prepare() {
echo -e "\e[31mStart with systemctl --user start udiskie.service"
echo "or for autostart enable with systemctl --user enable --now udiskie.service"
echo "Starting as user is important to ensure right mount dir"
echo -e "(Else add udev rule which changes mountpoint to shared)\e[39m"
}


package() {
cd "${srcdir}"
install -Dm644 udiskie.service "${pkgdir}/${systemd_dir}/udiskie.service"
install -Dm644 config.json "${pkgdir}/${udskie_conf}/config.json"
}

config.json:

{
  "program_options": {
    "tray": true,
    "automount": true,
    "menu": "nested",
    "file_manager": "xdg-open"
  },
  "device_config": [
    {
      "id_type": "ntfs",
      "options": ["windows_names"]
    }
  ]
}

(possible to add more stuff or ignore other filesystems)

udiskie.service

[Unit]
Description=udiskie starter (start with systemctl --user enable --now udiskie.service)

[Service]
ExecStart=/usr/bin/udiskie -c /usr/local/share/udiskie/config.json
Restart=on-failure

[Install]
WantedBy=default.target

important:
enable unit as user (with systemctl --user)
(else udev rules would be needed that change mountpoint to shared [/media/…] )

install:
create some_dir, cd some_dir
create PKGBUILD, paste text
also for config.json and udiskie.service
makepkg
makepkg -i

(Sorry cant upload tar.gz [or other archive] to this … forum. Only jpg,png,and other image formats. lol )

edit:

● udiskie.service - udiskie starter (start with systemctl --user enable --now udiskie.service)
   Loaded: loaded (/etc/systemd/user/udiskie.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-02-17 19:56:30 CET; 2min 53s ago
 Main PID: 660 (udiskie)
   CGroup: /user.slice/user-1000.slice/user@1000.service/udiskie.service
           └─660 /usr/bin/python /usr/bin/udiskie -c /usr/local/share/udiskie/config.json

Feb 17 19:56:30 mv-pc systemd[653]: Started udiskie starter (start with systemctl --user enable --now udiskie.service).
Feb 17 19:56:54 mv-pc udiskie[660]: mounted /org/freedesktop/UDisks2/block_devices/sdc1 on /run/media/mv/251327DC0A47DCA2
Feb 17 19:58:41 mv-pc udiskie[660]: mounted /org/freedesktop/UDisks2/block_devices/sdc1 on /run/media/mv/251327DC0A47DCA2
Feb 17 19:59:15 mv-pc udiskie[660]: mounted /org/freedesktop/UDisks2/block_devices/sdc1 on /run/media/mv/251327DC0A47DCA2
mv@mv-pc:~$ 

mv@mv-pc:/run/media/mv/251327DC0A47DCA2$ LANG=en mkdir 'test \'
mkdir: cannot create directory 'test \\': Invalid argument
mv@mv-pc:/run/media/mv/251327DC0A47DCA2$ LANG=en mkdir 'test :'
mkdir: cannot create directory 'test :': Invalid argument

edit:
updated config.json
https://raw.githubusercontent.com/coldfix/udiskie/master/doc/udiskie.8.txt


#72

in config.json better use “device_config” instead “mount_options”, because mount_options is deprecated (https://github.com/coldfix/udiskie/blob/master/doc/udiskie.8.txt)

please replace the mount_options block with

"device_config": [
    {
      "id_type": "ntfs",
      "options": ["windows_names"]
    }
  ]

and adjust sha256sum


#73

@vetzki after updating the file and the according sha256 (made with “openssl dgst -sha256 pathtofile”) it all intalled correctly and I started the service with systemctl --user enable --now udiskie.service. However, when I then click on the windows partition in thunar and add a file named “:” it creates the file. I tried to restart but it’s still the same.


#74

thats strange, can you show the config.json file?


edit:
without the option:

edit2:
also, can you show the output of

ps auxww| grep udisk
root      2238  0.0  0.1 583596 12316 ?        Ssl  09:19   0:02 /usr/lib/udisks2/udisksd
mv       17405  0.0  0.1 714808 11688 ?        Ssl  11:36   0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
mv       21655 13.5  0.5 489584 45868 ?        Ssl  12:26   0:00 /usr/bin/python /usr/bin/udiskie -c /usr/local/share/udiskie/config.json
root     21668  0.0  0.0  17772   480 ?        Ss   12:26   0:00 /sbin/mount.ntfs /dev/sdc1 /run/media/mv/251327DC0A47DCA2 -o rw,nodev,nosuid,uid=1000,gid=1000,windows_names,uhelper=udisks2
mv       21670  0.0  0.0  13328  2284 pts/1    S+   12:26   0:00 grep --color=auto udisk

if it shows windows_names in mount options?

edit3:

dont mount with thunar, because thunar uses its own stuff to mount the device, use udiskie and set automount true


#75

ok, indeed, it mount without the option through Thunar.

How can I change how Thunar mounts devices? Here, it says Thunar can use udiskie https://wiki.archlinux.org/index.php/thunar#Automounting_of_large_external_drives


#76

just disable automountig in thunar at all

the sytemctl --user enable command already autostarts udiskie, so nothing else required

you can check with systemctl --user status udiskie.service (you can use tab key for autocompletion)

the arch link also just say autostart udiskie (where doesnt really mathers as long as it is started as user).


#78

@vetzki I disabled all automount options. It now works for usb devices, but it still mounts without the option for local drives which are unmounted at start (which is good) but are mounted when clicking in Thunar. Is there a way to make this configuration work on all ntfs mounts made from UI?


#79

this way it would work (not with thunar, again thunar uses its own mounting utility if you mount something via thunar buttons, how you change it I dont know, especially as I dont have thunar installed and wont install), but there’s a caveat:

udiskie has a tray icon for mounting/unmounting
but systemd autostarts udiskie before X server is running
udiskie cant create a icon without x server (journalctl)

for non external drives device section can be replaced with this in the config file (device_file need correct location or use id_uuid) :

"device_config": [
    { "device_file": "/dev/sdb1",
      "ignore": false,
      "options": ["windows_names"],
      "automount": false
    },
    {
      "id_type": "ntfs",
      "options": ["windows_names"]
    }
  ]

then the local hard drive can be mounted via tray icon with windows_names option but isn’t automounted

but again you need a way to start udiskie after x server not before, could be either with:

  • autostart option of desktop environment (instead of systemd service)
  • find a way the systemd starts the service after x server is started

#83

@vetzki thanks, added to autostart of xfce, it now works. It’s a pleasure to speak with you :slight_smile:


#84

For those who find this thread useful, I changed “device_file” to “id_uuid” and added the corresponding UUID I got from the gnome disk utility, to ensure the right partition is mounted, even if the block device letter are changed automatically (like after adding another HDD).
I hope it helps


#85

@jonathon thanks for splitting