1

When I try to run any executable from my second (NTFS) drive, I get a segmentation fault. If I run the exact same executable from, for example, my home folder, it works just fine.

For example: I compile the following C program using gcc a.c:

#include <stdio.h>

int main() {
    puts("Hello");
    return 0;
}

Now I run ./a.out from my second drive:

$ ./a.out
zsh: segmentation fault  ./a.out

(Also no core dump is generated, even though they are enabled and work for other things.)

If I copy the exact same file, without any modifications, to e.g. /home/username/ (which is on my main/OS drive):

$ ./a.out
Hello

Everything works perfectly fine there.

On the second drive however, GDB just fails during startup:

(gdb) starti
Starting program: /path/to/a.out 
During startup program terminated with signal SIGSEGV, Segmentation fault.

When I use strace, it says execve failed:

$ strace ./a.out
execve("./a.out", ["./a.out"], 0x7ffd0aa31070 /* 83 vars */) = -1 EOPNOTSUPP (Operation not supported)
+++ killed by SIGSEGV +++
zsh: segmentation fault (core dumped)  strace ./a.out

Also ldd just says not a dynamic executable on the second drive. readelf -d and objdump -p work just fine.

My drive and one of its subfolders is mounted like this in /etc/fstab:

UUID=drive-uuid-123        /path/to/drive   ntfs3   defaults      0 2
/path/to/drive/some/path   /my/new/path     none    defaults,bind 0 2

The same issue occurs when I run the binary from yet another different NTFS drive.

System information:

$ uname -a
Linux thomas-manjaro 6.6.25-1-MANJARO #1 SMP PREEMPT_DYNAMIC Thu Apr  4 20:32:38 UTC 2024 x86_64 GNU/Linux

This is a pretty fresh install of Manjaro and all packages are up-to-date.

Does anyone know what the problem could be? Do I need to mount my drive in a different way? Do I need to set some kind of system variable?

3
  • Your host-drive where everything is working, and your NTFS drive must be the same filesystem-type. You can't run binaries from Linux natively on a non-POSIX filesystem that's designed for a completely different OS. Please explain why you need to run Linux binaries on Windows.
    – eyoung100
    Commented Apr 10 at 20:25
  • I'm dual-booting Windows and Linux and the drive is shared between them. Windows doesn't support ext4, so I use ntfs. Also, I don't run Linux binaries on Windows, I run Linux binaries on Linux. I compile and run them on the same machine and OS, the binary is just stored on an ntfs drive/partition and not the main ext4 partition. Running binaries from an ntfs filesystem still works fine on my laptop where I have a similar setup and has worked fine on my desktop machine for years. I recently reinstalled Manjaro since I had some issues and that's when it stopped working.
    – Syntax
    Commented Apr 10 at 20:50
  • See Answer. Sorry, these take me a bit to write-up, being one handed and all.
    – eyoung100
    Commented Apr 10 at 22:40

2 Answers 2

0

Note: I've written the individual fstab lines with 2 spaces between each and then spaced it out as best I could in the completed fstab at the bottom. Feel free to alter the mountpoint to match whatever location you're actually using

Verification

  1. Install: sudo pacman -S ntfs-3g fuse
  2. Test Mount: sudo mkdir -p /mnt/ntfs && sudo mount -t ntfs /dev/sdX /mnt/ntfs - Use parted to determine what X is for the test only. We'll add the UUID shortly.
  3. Test that the mount in Step 2 mounted properly: mount | grep ntfs

Assemble fstab

  1. Take note of the UUID: sudo blkid /dev/sdX - See Step 2 Above.
  2. Add to fstab: UUID=XXXX-XXXX /mnt/ntfs ntfs user,ro,umask=0222,defaults 0 0 - This "master mount" is handled by the kernel's filesystem handlers

This should mount the entire drive read-only without needing root, and match the Linux access mask. We can now add/mount directories read/write like so in fstab (taking advantage of the FUSE filesystem): /mnt/ntfs/path/to/directory /some/new/path ntfs-3g rbind,user,umask=0222,defaults 0 0 - This "sub mount" is handled by the userspace tools.

Note 2: rbind is used here to keep the changes preserved recursively, because we are mounting part of the entire read-only filesystem as another mount that is read/write. Both mounts must be kept in sync to ensure changes are saved to disk correctly. See: Understanding Bind Mounts, which includes an explanation of Recursive Bindings.

The Completed fstab

# Device                   #Mount Point    #FS     #Mount Options              #Fsck                  
UUID=XXXX-XXXX            /mnt/ntfs        ntfs    user,ro,umask=0222,defaults     0 0
/mnt/ntfs/specific/dir   /some/new/path    ntfs-3g rbind,user,umask=0222,defaults  0 0
1
  • Thanks, working as before now!
    – Syntax
    Commented Apr 11 at 12:15
0

I keep a dual-boot system, but have not booted Windows for several years. I have many legacy files on both internal and external (USB) hard discs, both of which have Linux ext2/ext3 and NTFS partitions.

I choose not to mount NTFS permanently by default (as the USB is pluggable), so no fstab entries. I generally just use my Linux File Manager to mount partitions as I need them, which gives them these characteristics:

$ mount | grep Windows
/dev/sda2 on /media/paul/Windows type fuseblk \ 
    (rw,nosuid,nodev,relatime,user_id=0,group_id=0, \ 
    default_permissions,allow_other, \ 
    blksize=4096,uhelper=udisks2)

For things like backup scripts, I embed commands like:

mount -o uid=1000,gid=1000 "/dev/sda2" "/media/root/Windows"

The udisksctl command can also be useful.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .