0

I have got some issue with auto mount any external drives or partitions !! And every time I need to give sudo command from telnet to mount it such as

sudo mount /dev/sdc1 /media/raed

I have tried with this command (sudo ntfsfix /dev/sdc1) but nothing change

Mounting volume... OK
Processing of $MFT and $MFTMirr completed successfully.
Checking the alternate boot sector... OK
NTFS volume version is 3.1.
NTFS partition /dev/sdc1 was processed successfully.
RAED
  • 15
  • What does your fstab file look like? Are you able to share? I've found that mounting to /mnt rather than media works better. – who8mypnuts Nov 28 '23 at 17:59

1 Answers1

0

how to mount a disk without superuser (root)

Normally in Linux by default the action of mounting a disk, regardless of it is internal or external, requires root or elevated privileges. It is a basic security setting. But that setting can easily be modified to suit your needs... and allow specific users or all users to mount

First you will need to be root, or have enough of a superuser privilege to modify the specific security settings to open up the use of the mount command to users. To do this, there are various ways, see

How to allow non-superusers to mount any filesystem?

you mentioned how to mount an external disk

Whether the disk is external, or internal, is largely irrelevant. As long as Linux first recognizes the connected disk whether it is by USB connection or SATA or SAS or other, it will show up as some block device such as /dev/sdb for example. That needs to already be happening, if so then if all else is well you should be able *to mount the disk.

you mentioned a NTFS disk

Once the disk shows up as a block device, such as /dev/sdb for example, then Linux can begin to work with it. But the disk had to then have a valid partition table (GPT or MSDOS for example) as well as valid partitions and then a valid file system on a specific partition. For example the most common partition table today is GPT, and then you may see more than one partition on your disk that shows up as /dev/sdb and then you will see something like /dev/sdb1 and /dev/sdb2 and so on. On any of those 1,2,3..N partitions will need to be a file system Linux can work with. Since you mentioned NTFS you will require the ntfs-3gdriver, which is available from https://www.tuxera.com/company/open-source/. However if you are running a very new linux kernel, I have read it now includes support for NTFS file systems so you do not have to manually go get and install ntfs-3g

I have got some issue with auto mount any external drives or partitions

Realize that there are multiple ways to mount a disk in /etc/fstab

  • by name
  • by uuid
  • by disk label
  • by path

What can happen if you mount by name which will be a line something like this in /etc/fstab

/dev/sdb1   /data   ntfs-3g  defaults,nofail  0  0

That as you add remove disks in the system that sdb can refer to some other disk, and cause problems. So it is usually best to mount by uuid, or by label if you have set a partition label. Such a line in /etc/fstab would look like

# the uuid xxxx will be some long unique string
/dev/disk/by-uuid/xxxx   /data    defaults,nofail 0 0

LABEL=yourlabel /data defaults,nofail 0 0

To identify the uuid or label, you can do

lsblk -o size,fstype,model,name,serial,uuid,label

to see pertinent disk information to then understand what is what.

After all that, if you then get file system errors where NTFS is corrupted and you have to run ntfsfix then that's a different problem. My recommendation here would be to use Microsoft Windows 10 or later and use its ntfsrepair tool since NTFS is a proprietary microsoft file system; you take your chances with linux tools working on the ntfs file system.

You want to turn off Fast Startup in Microsoft windows so upon shutdown in windows it will fully close and unmount the NTFS file system so linux can later use it... if your disk gets mounted by linux and windows. Otherwise you will likely always encounter ntfs errors in linux where linux will prompt you to repair it.

ron
  • 6,575
  • Before I did not have any issue with external hard disk. Once ÷ connect the USB to the hard disk, ÷ will get the mount directly. Without edit fstb or any things else !! – RAED Nov 29 '23 at 11:59
  • you also said every time I need to give sudo command from telnet* to mount*. What you describe is sort of a red flag, and gives me the strong impression you have some other problem going on or are doing something incorrectly. What distribution and version of linux are you using? – ron Nov 29 '23 at 15:19
  • look into : https://unix.stackexchange.com/questions/134797/how-to-automatically-mount-an-usb-device-on-plugin-time-on-an-already-running-sy – ron Nov 29 '23 at 15:23
  • I using ubuntu 23.10 ... Yes as I wrote before every time if I want to open an external hard disk should be to give sudo mount /dev/sdc1 /media/raed but now I have fix just manually by adding this lines in fstab file '/dev/sdc1 /media/raed/NTFS_320B ntfs-3g defaults,nofail 0 01' – RAED Nov 29 '23 at 15:26
  • Before I did not have any issue ... funny how that always seems to be the case. Something changed. The scope of your question/problem is large- many things in play- the basic mounting of block devices (disks), the automount feature, the use of USB (assuming usb because you said external disk), and use of NTFS which is not a linux file system type. – ron Nov 29 '23 at 15:32
  • mounting by name /dev/sdc1 in /etc/fstab is bad, do by label or by uuid – ron Nov 29 '23 at 15:33
  • Ok.. I will mounting by uuid .. Thank you – RAED Nov 29 '23 at 17:48