Invalid cross-device link (18) when saving a file on arch linux

144 views (last 30 days)
I have installed matlab on arch linux. everything works fine, even simulink. I can also open files without a problem. But whenever i try to save a file, i get the error. I cant find anything about it online
Error writing file "[path]"Invalid cross-device link (18)".

Accepted Answer

Joshua Ortiga
Joshua Ortiga on 7 Sep 2022
Moved: Walter Roberson on 7 Sep 2022
I am also using Arch Linux and having the same problem as well. Unfortunately this is an issue that is currently only resolved by downgrading your kernel to <=Linux 5.18.9
  4 Comments

Sign in to comment.

More Answers (9)

simone rotondi
simone rotondi on 12 Oct 2022
I had the same behaviour.
Anyway i have figured out that a big problem are the temp files, if i set the matlab tempdir to a file system different wrt btrfs or tempfs and the file is also in a different file system it works with no problem.
If the filesystem of the temp files or the files you are working with is btrfs with a newer kernel it wont work. i have tried also to disable the COW on the folder i was working but no improvement at all.
For instance to change the temp dir of matlab
clear all
tempdir
setenv('TMPDIR','FOLDER FROM NTFS,EXT4..')
clear all
tempdir
and it should be fixed (for files not on btrfs)
  6 Comments
FEDERICO
FEDERICO on 30 Mar 2023
Since It is needed to do it any time you open matlab.
Open (or create) startup.m in your userpath folder, with the following command:
edit(fullfile(userpath,'startup.m'))
And then place inside this file the following line (with the correct folder path):
setenv('TMPDIR','/home/youruser/yourtempdir');

Sign in to comment.


Jacek Jagosz
Jacek Jagosz on 9 Nov 2022
To someone from Matlab, this is to help them fix this issue.
This seems to be the commit that introduced this issue, not only present in kernel 5.18 but even backported to 5.15 LTS https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-5.15.y&id=4d5055873e24bba9e01b3b5d16790714b0d38533
Some other applications broke with this change, not just Matlab. For example qBittorrent, they discussed the whole issue here: https://github.com/qbittorrent/qBittorrent/issues/17352
And they fixed it in this particular commit: https://github.com/arvidn/libtorrent/pull/6965
Hope Matlab can introduce the same fix, and hope it finds its way to the new release.
Can I ping someone so this gets to someone from Mathworks, this could probably help them fix this issue.
  3 Comments
Jacek Jagosz
Jacek Jagosz on 30 Jan 2023
@Walter Roberson Could you check if this bug got fixed in R2022b Update 3 or maybe in the R2023a prerelease? I want to install a matlab release that is fully working.

Sign in to comment.


Adrian Dummermuth
Adrian Dummermuth on 22 Sep 2022
I am getting this error while I try to save a .mlx file provided by the professor. I have write permissions in /tmp/ but I am not sure why saving the .mlx doesn't work but if I create a new file that works. Any suggestions?
Running on Pop!_OS 22.04 LTS
Linux pop-os 5.19.0-76051900-generic #202207312230~1660780566~22.04~9d60db1 SMP PREEMPT_DYNAMIC Thu A x86_64 x86_64 x86_64 GNU/Linux
Unable to save file ex_1_1_tmp.mlx.
java.lang.RuntimeException: Internal Exception in writing MLX file : Could not commit changes: copy failed: fl:filesystem:SystemError: /tmp/.ed28-df99-8888-aaaa.tmp Invalid cross-device link
  4 Comments
Maciej
Maciej on 29 Sep 2022
You can save the .mlx file to your /tmp directory, and then move the file to your prefferred location. It is a poor workaround, though.

Sign in to comment.


Carlos Planelles Otero
Carlos Planelles Otero on 28 Sep 2022
I have same issue on Pop!_OS 22.04, saving as a .m file works fine but not .mlx.

Lennart Guderian
Lennart Guderian on 30 Nov 2022
Hey guys,
this issue has been bugging me too (on Garuda (Arch) Linux) and I just wanted to share a solution I came up with that doesn't require you to downgrade your kernel since that was something I wasn't really excited about. Thank you @simone rotondi for the information about the filesystem being the issue in conjunction with the temp dir!
Since on my main hard drive I have a btrfs, I just formatted a small USB-Stick with FAT, named it matlab, created a tmp and set the TMPDIR var to point to it (`/run/media/uname/matlab/tmp`). Then I save all matlab files on this usb stick - works like a charm. Surely not optimal (looking forward to a soon fix from the MathWorks Team) but for me that was the more chill option than downgrading and version locking my kernel.
Hope it helps someone!
Cheers
  2 Comments
Rishab Kumar
Rishab Kumar on 3 Mar 2023
Could you send the CLI commands with which you set the TMPDIR var pointer
Lennart Guderian
Lennart Guderian on 3 Mar 2023
The command to use in Matlab is setenv('TMPDIR','FOLDER FROM NTFS,EXT4..')as you can see in Simone's answer above. In Matlab there is a startup script you can write that is run automatically when you open the program, if you add this line in there, it will be set automatically on every start and the problem is solved (if you also have your external storage device with FAT filesystem connected).

Sign in to comment.


Eugene Feinberg
Eugene Feinberg on 8 Dec 2022
After wasting (I hate to admit it) a few days trying to find a complete workaround to varients of this issue, I found that the root cause for me is the old version of the Java JRE that Mathworks packages with R2022b. Replacing the JRE with a newer version fixes every instance of the copy_file_range cross device problem (temporary directory, simulink saving issues, Xilinx blockset compile).
Process:
  • Download and untar or install java from https://www.java.com/en/download/manual.jsp
  • In the matlab install directory, rename R2022b/sys/java/jre/glnxa64 to R2022b/sys/java/glnxa64.orig
  • In the R2022b/sys/java/jre directory create a symlink to the download jre named glnxa64. There should now be a glnxa64/bin/java pointing to the new java binary.
The shipping version with R2022b update 2 is from January 2019
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
After installing the newer version
java version "1.8.0_351"
Java(TM) SE Runtime Environment (build 1.8.0_351-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.351-b10, mixed mode)
  1 Comment
simone rotondi
simone rotondi on 9 Dec 2022
Hi, i thought this was a cool solution but i didnt manage to fix the problem.
I'm on fedora 37 and Matlab 2022b update1
I tried this trick with both the java oracle libraries and the openjdk libs .. but both of them didnt solved the error. (anyway i'll keep using it)
'Java 1.8.0_352-b08 with Red Hat, Inc. OpenJDK 64-Bit Server VM mixed mode'
'Java 1.8.0_351-b10 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode'
This could be totally my fault and i hope it is. I'll keep trying , thanks anyway!

Sign in to comment.


Eugene Feinberg
Eugene Feinberg on 27 Sep 2022
I have the same problem on 22.04.1 LTS. MATLAB is installed on a different volume than /tmp. An strace shows the pattern below. By creating a temporary directory on the same disk volume that matlab is installed on and running matlab with the TMP variable set to that directory the error is resolved but that seems like a bad solution.
[pid 38662] openat(AT_FDCWD, "/opt/MATLAB/R2022b/toolbox/simulink/blocks/obsolete/simulink_need_slupdate.mdl", O_RDONLY|O_CLOEXEC) = 948
[pid 38662] fstat(948, {st_mode=S_IFREG|0444, st_size=164480, ...}) = 0
[pid 38662] openat(AT_FDCWD, "/tmp/.d1ee-e4b5-3401-aa22.tmp_extracted_package_simulink_need_slupdate.mdl/_mwopc_packageCopy.txt", O_WRONLY|O_CREAT|O_EXCL|O_TRUNC|O_CLOEXEC, 0100644) = 950
[pid 38662] fstat(950, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[pid 38662] copy_file_range(948, NULL, 950, NULL, 164480, 0) = -1 EXDEV (Invalid cross-device link)

simone rotondi
simone rotondi on 30 Sep 2022
On fedora 36 with btrfs file system there is the same error both in R2022a and in R2022b.
Linux 5.18.9 is the last one working well but is now 4 months old and from 5.18.10 to 5.19.12 the problem persists.
Everytime i have to save a slx file it gives me
Error writing file "[path]/name.slx": Failed to close the package: "Collegamento tra dispositivi non valido (18)".
Where "Collegamento tra dispositivi non valido" means "Invalid cross link device"
  6 Comments
Walter Roberson
Walter Roberson on 10 Nov 2022
You would need to have a partition available on a hard disk or SSD or flash drive (such as USB stick). The command line command that would be used at the Linux console would be mkfs -- see https://www.howtogeek.com/443342/how-to-use-the-mkfs-command-on-linux/
If I recall correctly there is a GUI available that will invoke the command on your behalf, but it has been several years since I last booted Linux so unfortunately I do not know where the GUI would be located.
simone rotondi
simone rotondi on 11 Nov 2022
Edited: simone rotondi on 11 Nov 2022
If you are on Fedora36 i would just recommend to go back to kernel 5.18.9
You can download and install it with
mkdir KernDown
cd KernDown
koji download-build kernel-5.18.9-200.fc36
sudo dnf install ./kernel-*
and lock it with
sudo dnf versionlock add kernel-5.18.9-200.fc36
then unlock when the problem will be fixed whith
sudo dnf versionlock delete kernel-5.18.200.fc36
Otherwise you should follow @Walter Roberson advice

Sign in to comment.


FEDERICO
FEDERICO on 30 Mar 2023
SOLUTION, LATEST KERNEL, MATLAB R2022b
Make sure to chose a TMPDIR inside your /home partition:
Since It is needed to do it any time you open matlab.
Open (or create) startup.m in your userpath folder, with the following command:
edit(fullfile(userpath,'startup.m'))
And then place inside this file the following line (with the correct folder path):
setenv('TMPDIR','/home/youruser/yourtempdir');

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!