rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Strange hard drive behavior

Fri Feb 27, 2015 1:20 am

My external hard drive is behaving oddly, I just completed a fresh install of Raspbian, setup Kodi, Pyload, and Bittorrent Sync. For some reason now when I turn it on, it says I do not have permissions to access the hard drive.

Code: Select all

pi@raspberrypi /media $ cd external/
-bash: cd: external/: Permission denied
Looking at the permissions, I see this.

Code: Select all

drwx------ 2 root root 4096 Feb 26 17:05 external
I have tired various versions of chmod -R 755 external (also 775 and 777), tried chown -R pi external. This changes the permissions and I am able to change into the external directory, but it lists as empty, nothing shows up.

The strange thing is, if I run kodi (via "kodi-standalone") it is able to see all the media on the hard drive, where the library had already been configured (on a previous installation).

After running kodi, using a separate terminal I can switch to the hard drive with no problem. It does not say anything about permissions, and when I list the home directory on the external drive everything is there.

The permissions after running kodi, when it works, look like this:

Code: Select all

drwxrwxr-x 12 pi   root 4.0K Feb 26 15:43 external
However, they continue to default back to drwx------ after each reboot. I have tried changing them manually using chmod and chown as described above, but like I said the directory just shows it is empty after that. (until I run kodi, then I can see and access the files that are really there on the hard drive).

I'm pretty confused, bc like I said this is a clean install I was simply trying to actually make a pristine copy without an problems to image before starting to tinker around some more, lol.

Any idea how I can fix this?

User avatar
DougieLawson
Posts: 40821
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Strange hard drive behavior

Fri Feb 27, 2015 1:29 am

What's the filesystem type on the HD?
What does a mount command (no operands) show?
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Strange hard drive behavior

Fri Feb 27, 2015 2:01 am

Filesystem is ext4, the mount command produces

Code: Select all

pi@raspberrypi /media $ mount
/dev/root on / type ext4 (rw,noatime,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=186144k,nr_inodes=46536,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=38084k,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=76160k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
/dev/mmcblk0p5 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)

User avatar
jojopi
Posts: 3424
Joined: Tue Oct 11, 2011 8:38 pm

Re: Strange hard drive behavior

Fri Feb 27, 2015 2:32 am

So the drive is not actually mounted, and you are just seeing the permissions on the empty directory that serves as the mount point. Which, by the way, you probably do not want non-root users to be able to write to, lest they accidentally put files on the SD card that they think are going to the external drive.

Have you told the Pi to mount the drive on /media/external, or is that just a place that Kodi or some other component chose?

Generally, if you want a drive to mount at boot time, and with system-level file permissions, you should have an entry in /etc/fstab. Something along the lines of:

Code: Select all

/dev/sda1  /media/external  ext4  noatime  0  2

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Strange hard drive behavior

Fri Feb 27, 2015 2:34 am

OK I can add that to my fstab. I just found it odd because previously it would automatically detect and mount the drive, but now that I have done a wipe and fresh install of Raspbian from noobs it no longer is auto-mounting the drive.

Edit - with regards to /media/external, that is just the name of the drive (external) and that is where my raspberry pi automatically mounted it when I first started using it a few months back (that was on raspbmc), but I have simply stuck with it because many of the programs I have tinkered with to get how I want I have configured to use that path.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Strange hard drive behavior

Fri Feb 27, 2015 2:39 am

So I edited my fstab by adding the line to look like this:

Code: Select all

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p5  /boot           vfat    defaults          0       2
/dev/mmcblk0p6  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use $

/dev/sda1  /media/WD500  ext4  noatime  0  2
saved, and rebooted

Now when I go to to media, it is still not there, this is what I see:

Code: Select all

pi@raspberrypi /media $ ls -l
total 16
drwx------ 2 root root 4096 Feb 26 17:05 boot0
drwx------ 2 root root 4096 Feb 26 17:05 RECOVERY
drwx------ 2 root root 4096 Feb 26 17:05 retropie
drwx------ 2 root root 4096 Feb 26 17:05 SETTINGS
This is what mount shows

Code: Select all

pi@raspberrypi /media $ mount
/dev/root on / type ext4 (rw,noatime,data=ordered)
devtmpfs on /dev type devtmpfs (rw,relatime,size=186144k,nr_inodes=46536,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=38084k,mode=755)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=76160k)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
/dev/mmcblk0p5 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
This is what fdisk shows:

Code: Select all

pi@raspberrypi /media $ sudo fdisk -l

Disk /dev/mmcblk0: 32.0 GB, 32010928128 bytes
4 heads, 16 sectors/track, 976896 cylinders, total 62521344 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ede64

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048     2390625     1194289    e  W95 FAT16 (LBA)
/dev/mmcblk0p2         2392064    62455807    30031872   85  Linux extended
/dev/mmcblk0p3        62455808    62521343       32768   83  Linux
/dev/mmcblk0p5         2400256     2523135       61440    c  W95 FAT32 (LBA)
/dev/mmcblk0p6         2531328    33243135    15355904   83  Linux
/dev/mmcblk0p7        33251328    33374207       61440    c  W95 FAT32 (LBA)
/dev/mmcblk0p8        33382400    62455807    14536704   83  Linux

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8d399bc0

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   976773119   488385536   83  Linux

Any idea why it still is not mounting at boot despite adding that line to fstab?

Edit - just wondered, do I have to change permissions of fstab? This is what they are without any tinkering from me:

Code: Select all

-rw-r--r--   1 root root    368 Feb 26 18:35 fstab
-rw-r--r--   1 root root    204 Feb 16 06:03 .fstab

User avatar
jojopi
Posts: 3424
Joined: Tue Oct 11, 2011 8:38 pm

Re: Strange hard drive behavior

Fri Feb 27, 2015 2:59 am

The operating system should detect disks but not automatically mount them.

Some GUI environments will automatically mount drives that they consider to be removable, but then for security reasons they have to distrust the permissions stored on the drive, and may restrict access to just the user who is logged in locally. This kind of "convenience" mounting is normally used with FAT-formatted USB flash drives, rather than native ext4 disks.

When using fstab, it is important that an empty root-owned directory exists at the point where the drive will be mounted. Something appears to have "cleaned up" /media/external. I think that /media/WD500 will be fine once you have created it with sudo mkdir, but if you find it does not survive a reboot you may need to mount somewhere outside of /media instead.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Strange hard drive behavior

Fri Feb 27, 2015 3:31 am

OK, that is interesting. I wonder if back when I was using raspbmc it automatically created the mount for me. Then when I switched to raspbian I used to have it automatically boot into the desktop, which may have entailed automatically mounting filesystems (it auto-logged in).

Anyways, adding the line to fstab worked great, thanks!

User avatar
DougieLawson
Posts: 40821
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Strange hard drive behavior

Fri Feb 27, 2015 7:46 am

Try this
blkid

Which should get something like

Code: Select all

/dev/sda1: UUID="f6xxxx22-fxx9-4xxe-a6dd-6d9xxxx0663f" TYPE="ext4"
You then add

Code: Select all

UUID="f6xxxx22-fxx9-4xxe-a6dd-6d9xxxx0663f" /media/WD500  ext4  noatime  0  2
to /etc/fstab.

That means you will ONLY get your WD drive mounted and it doesn't matter if it appears as /dev/sda1 or /dev/sdq1 it will mount it using the UUID value.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

rpi25
Posts: 23
Joined: Sat Feb 21, 2015 2:31 am

Re: Strange hard drive behavior

Sat Feb 28, 2015 6:52 am

Cool, that looks handy.

Is it common for the sda1 label to change over time? Like if for a while I stop using that hard drive and use a different one, then if I switch back to it will it no longer be sda1? What is the main advantage to using the UID over sda1?

User avatar
jojopi
Posts: 3424
Joined: Tue Oct 11, 2011 8:38 pm

Re: Strange hard drive behavior

Sat Feb 28, 2015 8:47 am

If you have exactly one storage device connected at boot, it will be sda. If you have two, it can become hard to predict which is sda and which is sdb.

If you unplug, unpower, or lose connection with a drive while it is mounted, when reconnected it will temporarily get a different name to distinguish new accesses from old ones that are still failing. Of course, it is best to avoid this.

Linux has no persistent recollection of devices, it just allocates whichever sdX device name is available at the time of detection. It is possible to use udev rules to force a particular device name, but it is better to access filesystems by UUID or LABEL instead.

User avatar
DougieLawson
Posts: 40821
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Strange hard drive behavior

Sat Feb 28, 2015 11:28 am

rpi25 wrote:Cool, that looks handy.

Is it common for the sda1 label to change over time? Like if for a while I stop using that hard drive and use a different one, then if I switch back to it will it no longer be sda1? What is the main advantage to using the UID over sda1?
The UUID is carried with the partition. You can change it with tune2fs -U random /dev/sda1 (or with some awful hacking using dd & hexedit & dd if the filesystem is FAT).

If you clone a device using dd or Win32DiskImager then the UUID on the input and output filesystems will be identical. Which is fun, because Linux will use the first one it finds. (I had a system with a SDCard, a HD (that I'd just copied from the SDCard) and a backup SDCard in a USB reader all with the same UUID, it was interesting to see which one got mounted.)
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Return to “Raspberry Pi OS”