Tuesday, November 24, 2020

Linux case sensitivity in mounted network path - ls v/s cp commands

This is about simple troubleshooting did in the Raspberry Pi (Raspberry Pi OS ) environment that related to path sensitivity. As most of us know when Windows guys start in Linux it happens. But here it's a little interesting as the issue occurred on a path that is mounted from a shared path using cifs driver.

If this is already known and feels obvious, please skip.

Problem

The below copy command failed.
pi@raspberrypi:~ $ sudo cp /media/router/media/2020/2020-08-26-Giant-stairs/DJI_0159.MP4  /media/usbadata64gb/share

cp: cannot open '/media/router/media/2020/2020-08-26-Giant-stairs/DJI_0159.MP4' for reading: No such file or directory

The /media/router was mounted using below command.

sudo mount -t cifs -o username=<user name>,password=<pass>,vers=1.0 //192.168.1.1/USB_Media  /media/router

The //192/168.1.1/USB_Media is the external hard disk connected to USB port in my router. That path is mounted into RasPi. The location is /mediate/router. 

The destination is another mount where it has mounted an external disk directly connected to RasPi.

Troubleshooting

As I am now following more of scientific debugging, the first hypothesis was as follows.

Hypothesis 1 - The file doesn't exist

The immediate thing is to check whether the file exists by using the below command.

pi@raspberrypi:~ $ ls /media/router/media/2020/2020-08-26-Giant-stairs/DJI_0159.MP4

File exists. Hypothesis rejected. Obviously, the next hypothesis is there are not enough permissions

Hypothesis 2 - Not enough permissions on the file

Command to check permissions.
pi@raspberrypi:~ $ ls -lp /media/router/media/2020/2020-08-26-Giant-stairs/DJI_0159.MP4
-rwxrwxrwx 1 pi root 556408823 Aug 26 14:35 /mnt/router/Media/2020/2020-08-26-Giant-stairs/DJI_0159.MP4

Shows permissions properly. Now what? 

yes, google. Went through a lot of links where cp fails on the different cases including NAS permissions etc...

Hypothesis 3 - ls command is not case sensitive but cp is

This is about questioning my Linux knowledge. Maybe the entire community where Linux file system is known for case sensitivity. I looked at each character in the path and figured one change. It is /Media, instead of /media when its coming second time in the path. The new command goes below

pi@raspberrypi:~ $ sudo cp /media/router/Media/2020/2020-08-26-Giant-stairs/DJI_0159.MP4  /media/usbadata64gb/share

It worked magically.

Findings

When I checked the ls command in the Linux file system, it is case sensitive. But in this particular mounted path, the ls command is not case sensitive but the cp command is. The cifs command options MAN page says there is a 'nocase' option if we want to avoid case sensitivity. By default, it's case sensitive.

This behavior seems known, below are some links.

https://superuser.com/questions/680492/mounts-arent-case-sensitive
https://bugzilla.redhat.com/show_bug.cgi?id=432837
https://unix.stackexchange.com/questions/521125/access-windows-shared-files-from-linux-case-insensitive


No comments: