Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Mounting extrnal hard drive
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Mon Aug 13, 2018 12:28 am    Post subject: Mounting extrnal hard drive Reply with quote

Hi,
I am trying to mount an external harddrive.

Here is what I got:

Code:

IgorReinCloud igor # lsblk -o +fstype,label,uuid,partuuid
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT FSTYPE LABEL           UUID                                 PARTUUID
sda      8:0    0 465.8G  0 disk                                                                       
├─sda1   8:1    0    15G  0 part            ntfs   PQSERVICE       88362BC9362BB75A                     35b8bd9b-01
├─sda2   8:2    0   100M  0 part            ntfs   SYSTEM RESERVED A4B82C84B82C56D8                     35b8bd9b-02
├─sda3   8:3    0 206.5G  0 part            ntfs   Acer            243613FA3613CC24                     35b8bd9b-03
├─sda4   8:4    0     1K  0 part                                                                        35b8bd9b-04
├─sda5   8:5    0    30M  0 part /boot      ext2                   127fb462-930a-437a-90e9-568ce46b9596 35b8bd9b-05
├─sda6   8:6    0 976.3M  0 part [SWAP]     swap                   cdd43044-a75b-45f9-a538-229dd59dfe9b 35b8bd9b-06
└─sda7   8:7    0 243.2G  0 part /          ext3                   9b379094-003d-477e-a559-fbe871337e5b 35b8bd9b-07
sdc      8:32   0 931.5G  0 disk                                                                       
└─sdc1   8:33   0 931.5G  0 part            ntfs   My Passport     76B4261DB425DFFB                     95f88007-27ff-4424-929d-ce8331a6c665
sr0     11:0    1  1024M  0 rom                                                                         

IgorReinCloud igor # cat /etc/fstab
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed); notail increases performance of ReiserFS (at the expense of storage
# efficiency).  It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>         <mountpoint>   <type>      <opts>      <dump/pass>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
UUID=76B4261DB425DFFB   /mnt/extern   ntfs      noauto,rw,user         0 0
/dev/sda5      /boot      ext2      defaults,noatime,user_xattr   1 2
/dev/sda7      /      ext3      noatime,user_xattr      0 1
/dev/sda6      none      swap      sw      0 0
/dev/cdrom      /mnt/cdrom   auto      noauto,user   0 0
#/dev/fd0      /mnt/floppy   auto      noauto      0 0
/dev/sr0      /mnt/cdrom   auto      noauto,rw,user      0 0
proc         /proc      proc      defaults   0 0
shm         /dev/shm   tmpfs      nodev,nosuid,noexec   0 0
#none         /dev/shm   devtmpfs   defaults   0 0


However, I am getting following:

Code:

IgorReinCloud igor # chmod 777 /mnt/extern/
chmod: changing permissions of '/mnt/extern/': Read-only file system


As far as I understand I can create a writeable mountpoint for ntfs drives. So what is happenning? Or it can be done only after the reboot?

Thank you.
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1555
Location: Montréal

PostPosted: Mon Aug 13, 2018 12:41 am    Post subject: Reply with quote

To have read and write access to an Ntfs filesystem you need to use ntfs-3g. The ntfs module in the Linux kernel only give read access, write access is partial. You need to use the uid=value, gid=value and umask=value parameters to set the permissons in fstab.

Changing permissions with chmod and chown in the mount point directory does nothing. Have a look to the ntfs and ntfs-3g manual pages.
_________________
Paul
Back to top
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Mon Aug 13, 2018 1:22 am    Post subject: Reply with quote

Logicien,
I installed ntfs-3g and tried again.

Code:

igor@IgorReinCloud ~/dbhandler $ mount /mnt/extern
Error opening '/dev/sdc1': Permission denied
Failed to mount '/dev/sdc1': Permission denied
Please check '/dev/sdc1' and the ntfs-3g binary permissions,
and the mounting user ID. More explanation is provided at
http://tuxera.com/community/ntfs-3g-faq/#unprivileged


I didn't change anything in the fstab. And here is the /mnt directory:

Code:

igor@IgorReinCloud ~/dbhandler $ ls -la /mnt
total 36
drwxr-xr-x  9 root root 4096 May 12 21:55 .
drwxr-xr-x 29 root root 4096 Mar 16 01:48 ..
drwxr-xr-x  2 root root 4096 Feb 16  2017 cdrom
drwxrwxrwx  2 root root 4096 Jul  9  2011 extern
-rw-r--r--  1 root root    0 May 25  2011 .keep
drwxr-xr-x  2 root root 4096 May 12 21:55 mac
drwxrwxrwx  2 root root 4096 Jun 22  2011 phone
drwxrwxrwx  2 root root 4096 May 27  2014 samba
drwxrwxrwx  2 root root 4096 Dec  4  2011 usb
drwxr-xr-x  2 root root 4096 Jun 20  2011 win7


And I did turn off external-fuse, as it is required for an unprivileged user mounting.

What am I doing wrong?

[EDIT]
I just trried what's suggested on the this page, section "Why can’t unprivileged users mount block devices?"

Code:

  chown root $(which ntfs-3g)
  chmod 4755 $(which ntfs-3g)


but still got the same errors.
[/EDIT]
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Mon Aug 13, 2018 7:00 am    Post subject: Reply with quote

ONEEYEMAN wrote:
I didn't change anything in the fstab. And here is the /mnt directory:

ntfs type is the kernel handling, ntfs-3g is the type for ntfs-3g, so if you don't swap ntfs fs type to ntfs-3g, kernel driver will still be use.

here's howto do what you want:
Code:
mount -t ntfs-3g -o uid=1000,gid=1000 /dev/diskpath /pathofyourmount

which is translate into fstab as
Code:
/dev/diskpath             /pathofyourmount   ntfs-3g            uid=1000,gid=100   0 0
Back to top
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Mon Aug 13, 2018 12:45 pm    Post subject: Reply with quote

krinn,
I am trying to mount it as a regular user. I think I can still do it and get a write access to the drive.
After swapping the FS in the /etc/fstab, I still receive the same errors.

Thank you.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Mon Aug 13, 2018 1:50 pm    Post subject: Reply with quote

ONEEYEMAN wrote:
I am trying to mount it as a regular user. I think I can still do it and get a write access to the drive. After swapping the FS in the /etc/fstab, I still receive the same errors.

ONEEYEMAN ... to mount as user then ntfs-3g has to be setuid-root, so set USE="suid" on sys-fs/ntfs3g and re-merge. Then you want 'users' in 'opts' ...

/etc/fstab:
/dev/sdc1 /mnt/dir ntfs-3g noauto,users,uid=1000,gid=100   0 0

HTH & best ... khay
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Mon Aug 13, 2018 4:47 pm    Post subject: Reply with quote

ONEEYEMAN wrote:
I am trying to mount it as a regular user. I think I can still do it and get a write access to the drive.

you get write rights on it because all actions will be as per the options set for uid/gid ; on gentoo normally uid=1000 is the first user, and gid=100 the first group (users group)
you can get the needed uid/gid for your user with id youruser if they are not "classic"

if you want a user to have ability to mount/unmount the drive, then you need to set user in the options user,uid=1000,gid=100
but you seems to assume user ability to mount a drive would grant him writes on it ; which is false.
Back to top
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Mon Aug 13, 2018 11:05 pm    Post subject: Reply with quote

khayyam wrote:

ONEEYEMAN wrote:

I am trying to mount it as a regular user. I think I can still do it and get a write access to the drive. After swapping the FS in the /etc/fstab, I still receive the same errors.

ONEEYEMAN ... to mount as user then ntfs-3g has to be setuid-root, so set USE="suid" on sys-fs/ntfs3g and re-merge. Then you want 'users' in 'opts' ...

/etc/fstab:
/dev/sdc1 /mnt/dir ntfs-3g noauto,users,uid=1000,gid=100   0 0

HTH & best ... khay

Added the USE flag and re-emerged.
Then fixed the line in the /etc/fstab:

Code:

igor@IgorReinCloud ~ $ cat /etc/fstab
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed); notail increases performance of ReiserFS (at the expense of storage
# efficiency).  It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>         <mountpoint>   <type>      <opts>      <dump/pass>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
UUID=76B4261DB425DFFB   /mnt/extern   ntfs-3g      noauto,rw,users,uid=1000,gid=100   0 0


Still:

Code:

igor@IgorReinCloud ~ $ mount /mnt/extern
Error opening '/dev/sdb1': Permission denied
Failed to mount '/dev/sdb1': Permission denied
Please check '/dev/sdb1' and the ntfs-3g binary permissions,
and the mounting user ID. More explanation is provided at
http://tuxera.com/community/ntfs-3g-faq/#unprivileged


Code:

[37477.710264] usb 1-1: USB disconnect, device number 2
[37484.410870] usb 1-1: new high-speed USB device number 3 using ehci-pci
[37484.607984] usb 1-1: New USB device found, idVendor=1058, idProduct=25e1
[37484.607995] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[37484.608000] usb 1-1: Product: My Passport 25E1
[37484.608004] usb 1-1: Manufacturer: Western Digital
[37484.608008] usb 1-1: SerialNumber: 575847314139363754344559
[37484.608581] usb-storage 1-1:1.0: USB Mass Storage device detected
[37484.610639] scsi host4: usb-storage 1-1:1.0
[37485.611486] scsi 4:0:0:0: Direct-Access     WD       My Passport 25E1 1015 PQ: 0 ANSI: 6
[37485.613463] sd 4:0:0:0: Attached scsi generic sg2 type 0
[37485.617897] scsi 4:0:0:1: Enclosure         WD       SES Device       1015 PQ: 0 ANSI: 6
[37485.621391] sd 4:0:0:0: [sdb] Spinning up disk...
[37485.626393] scsi 4:0:0:1: Attached scsi generic sg3 type 13

igor@IgorReinCloud ~ $ mount /mnt/extern
Error opening '/dev/sdb1': Permission denied
Failed to mount '/dev/sdb1': Permission denied
Please check '/dev/sdb1' and the ntfs-3g binary permissions,
and the mounting user ID. More explanation is provided at
http://tuxera.com/community/ntfs-3g-faq/#unprivileged


The drive should be /dev/sdc1 and not /dev/sdb1.
Back to top
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Mon Aug 13, 2018 11:11 pm    Post subject: Reply with quote

krinn wrote:

ONEEYEMAN wrote:

I am trying to mount it as a regular user. I think I can still do it and get a write access to the drive.

you get write rights on it because all actions will be as per the options set for uid/gid ; on gentoo normally uid=1000 is the first user, and gid=100 the first group (users group)
you can get the needed uid/gid for your user with id youruser if they are not "classic"

if you want a user to have ability to mount/unmount the drive, then you need to set user in the options user,uid=1000,gid=100
but you seems to assume user ability to mount a drive would grant him writes on it ; which is false.


I understand that mounting and writing are 2 different operations. But I should be able to mount the drive as a regular user, correct?
I can mount as "root", but just trying to save on typing. Because I will need to mount the drive as root and then exit the root terminal.

Thank you.
Back to top
View user's profile Send private message
apiaio
Guru
Guru


Joined: 04 Dec 2008
Posts: 426

PostPosted: Tue Aug 14, 2018 7:33 am    Post subject: Reply with quote

Code:
$ cat /etc/udev/rules.d/40-usbkey.rules
ACTION=="add", KERNEL=="sdc*", SUBSYSTEM=="block", RUN+="/bin/mount /dev/%k"
ACTION=="remove", KERNEL=="sdc*", SUBSYSTEM=="block", RUN+="/bin/umount /dev/%k"

and
in fstab
Code:
/dev/sdc1               /media          ntfs-3g   defaults,noauto,sync,users,gid=15,umask=0002 0 0

That is the way how to outomount external hard disk.
Back to top
View user's profile Send private message
P.Kosunen
Guru
Guru


Joined: 21 Nov 2005
Posts: 309
Location: Finland

PostPosted: Tue Aug 14, 2018 10:48 am    Post subject: Reply with quote

Edit: https://wiki.gentoo.org/wiki/Mount
/etc/fstab options can allow user(s) to mount.


Last edited by P.Kosunen on Tue Aug 14, 2018 1:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Tue Aug 14, 2018 12:50 pm    Post subject: Reply with quote

Hi,
apiaio wrote:

Code:

$ cat /etc/udev/rules.d/40-usbkey.rules
ACTION=="add", KERNEL=="sdc*", SUBSYSTEM=="block", RUN+="/bin/mount /dev/%k"
ACTION=="remove", KERNEL=="sdc*", SUBSYSTEM=="block", RUN+="/bin/umount /dev/%k"


Can I do that by label or UUID?

apiaio wrote:

and
in fstab
Code:

/dev/sdc1               /media          ntfs-3g   defaults,noauto,sync,users,gid=15,umask=0002 0 0

That is the way how to outomount external hard disk.


Thank you,
Back to top
View user's profile Send private message
apiaio
Guru
Guru


Joined: 04 Dec 2008
Posts: 426

PostPosted: Tue Aug 14, 2018 3:00 pm    Post subject: Reply with quote

ONEEYEMAN wrote:
Hi,
Can I do that by label or UUID?

You can use UUID in fstab.
Code:
UUID=76B4261DB425DFFB /mnt/extern   ntfs-3g   defaults,noauto,users,gid=15,umask=0002 0 0
Back to top
View user's profile Send private message
ONEEYEMAN
Advocate
Advocate


Joined: 01 Mar 2005
Posts: 3674

PostPosted: Tue Aug 14, 2018 3:18 pm    Post subject: Reply with quote

Hi,
So udev rules has to be written with the exact device?
But then - what would be the way for this scenario:

2 disks are connected to the machine with the usb, but only one is preferred to be mounted by the user.
Lets say they are a hard drive and a thumb drive.

The hard drive can be mounted by the user and then can be worked on from the OS/GUI. (I'm planning to put a VMs on this drive and already hae VirtualBox installed).
A thumb drive can be mounted by the root only and is used to transfer some files - just copying to/from (this can be done from the Terminal).

How do I manage this? Connect one and then the other always?

I'm just trying to understand and learn the best option to manage it?

Thank you.
Back to top
View user's profile Send private message
apiaio
Guru
Guru


Joined: 04 Dec 2008
Posts: 426

PostPosted: Tue Aug 14, 2018 3:36 pm    Post subject: Reply with quote

Udev rules has to be written with the device, which is populated during plugin in /dev.
You have to modify KERNEL=="sdc*" option.

Disk which will be mounted by user has to be enabled in /etc/fstab with the options listed above.
You can modify options. I think, that if you omit "users", hard drive wont be mounted.

This I have in my /etc/fstab
Code:
UUID=F474B7AA74B76DCC   /media/ext-hd   ntfs-3g   defaults,noauto,users,gid=15,umask=0002 0 0
UUID=F012-DC91          /media/ext-flash  vfat   defaults,noauto,users,gid=15,umask=0002 0 0
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum