2

I am trying to manually install a USB hard drive from the command line on my Raspberry Pi. I am following the usual steps: Create a directory in /media, mount the drive,... However I can not access the drive as a regular user and since the root account is disabled...

pi@raspi:/media/pi $ ls -hal
total 113K
drwxr-x---+ 5 root root 4.0K Oct  1 22:57 .
drwxr-xr-x  4 root root 4.0K Oct  1 21:41 ..
drwxr-xr-x  6 pi   pi    32K Jan  1  1970 342F-8BF2
drwxr-xr-x  5 root root 1.0K Sep  1 11:29 SETTINGS
drwx------  1 root root  72K Sep 24 23:18 toshiba

342F-8BF2 is a pendrive automatically mounted when starting the desktop environmnent, meanwhile toshiba is the directory that I have created with mkdir and where the HD is mounted.

How can the desktop create a directory as user pi with all the permissions that allow me to access/modify the pen drive but I can't?

EDIT:

In order to mount the HD I am using the following command

sudo mount /dev/sdb1 /media/pi/toshiba

and these are the permissions for the /media/pi directory

pi@raspi:/media $ ls -hal
total 16K
drwxr-xr-x   4 root root 4.0K Oct  1 21:41 .
drwxr-xr-x  22 root root 4.0K Jun 27 03:09 ..
drwxr-x---+  2 root root 4.0K Sep 22 00:32 peter
drwxr-x---+  5 root root 4.0K Oct  1 22:57 pi
1
  • 1
    Please post the command you are using to mount that drive. If you have sudo access, you may be able to use that to fix the ownership/permissions of the mount. Commented Oct 1, 2018 at 22:30

2 Answers 2

4

What is the filesystem type on the disk you’re mounting manually?

Filesystems that have no real support for Unix-style file ownership will usually need mount options to determine who can access them. If you specify no options, the default is to allow root access only.

Use the id command to identify the UID and GID numbers of your user account. I believe the pi user on a RasPi is usually UID 1000, GID 1000, so this might work for you:

sudo mount -o uid=1000,gid=1000 /dev/sdb1 /media/pi/toshiba

The desktop will most likely use udisks2 or similar D-Bus service to actually handle the mounting; see man udisksctl to see how you can use the same service from the command line. It will automatically apply some mount options to assign the permissions for you if applicable.

If the disk/partition has a filesystem that can persistently store Unix-style file ownerships and permissions, then you can use the chown and chmod commands as an one-time action to set the permissions for the root directory of the filesystem:

<mount the filesystem>
sudo chown pi:pi /media/pi/toshiba

Note that changing the permissions of the /media/pi/toshiba directory while the filesystem is unmounted will have no effect on the permissions of the root directory of the filesystem on /dev/sdb1. They are two separate entities, although one covers the other when the filesystem is mounted.

1

root is not disabled, only the ability to login as root is. As you've discovered, executing sudo without specifying a user will run the command as root. One way to deal with the permission problem is to 'sudo chmod o+rx /media/pi' (and if you want to be able to write to the volume, replace the o+rx to o+rwx) This is not a secure way to do things, but is the quickest and will be fine if you are the only user of the system.

You must log in to answer this question.

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