LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2019, 06:18 AM   #1
dowlq
LQ Newbie
 
Registered: Feb 2019
Distribution: Kubuntu 18.04
Posts: 5

Rep: Reputation: Disabled
Automounting external ext4 partition


Hi,
I have ext4 partition on my external USB HDD (there is one more NTFS partition on the drive, but I don't want it to be visible in Linux). What is the proper way in Linux to automount it (when I plug it in with USB cable) in /mnt/mydisk with permissions for every user for creating folders and files? I use Xubuntu 18.04.
 
Old 02-18-2019, 02:13 AM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,417

Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
Quote:
Originally Posted by dowlq View Post
Hi,
I have ext4 partition on my external USB HDD (there is one more NTFS partition on the drive, but I don't want it to be visible in Linux). What is the proper way in Linux to automount it (when I plug it in with USB cable) in /mnt/mydisk with permissions for every user for creating folders and files? I use Xubuntu 18.04.
It depends on what context you mean with regards to "automounting", for instance, if you are talking about through the graphical environment, then it would likely have an option somewhere for that - it depends on the graphical environment concerned as to where that option is, and what it's actually called. You would also need the autofs service running as well.

Linux doesn't honour NTFS permissions, so it depends on which user account it's mounted under, as to who has permission to access/modify files on it. I would mount it under your normal user account if you want that to have permissions to it.

You would have to make sure it's always plugged in if you always want it to be automounted.
 
Old 02-18-2019, 07:53 AM   #3
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 8,825

Rep: Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842Reputation: 1842
The methods vary so the first thing you should indicate is which of the hundreds of different Linux distributions you are using. Linux is not monolithic and also has available various Desktop Environments so that information would be useful. Many Linux systems will have a partition available to be accessed under the /media directory. Some will show a usb icon on the Desktop which you can use to access it.

If you want it mounted at a certain location (/mnt/mydisk), the proper place to put it would be the /etc/fstab file. The problem with this is that if the drive is not attached on boot, the system will look for it and not find it and will delay booting. You should see a message to that effect on-screen.

On a Linux filesystem, if you give users the ability to create directories/files that means write permission and if a user can write to s/he can also delete. You need to use additional parameters if that is not what you want.
 
Old 02-18-2019, 02:52 PM   #4
dowlq
LQ Newbie
 
Registered: Feb 2019
Distribution: Kubuntu 18.04
Posts: 5

Original Poster
Rep: Reputation: Disabled
I'm using Kubuntu 18.04. Let me describe what I need:
1. Disk will be used as additional storage space with access for every user.
2. Every user can create folders and manage permissions just like in his/her /home partition.
3. Disk should be mounted always in same folder, like /mnt/mydisk.
4. Disk should be mounted automatically when I plug the usb cable in.
Quote:
Originally Posted by yancek View Post
If you want it mounted at a certain location (/mnt/mydisk), the proper place to put it would be the /etc/fstab file. The problem with this is that if the drive is not attached on boot, the system will look for it and not find it and will delay booting. You should see a message to that effect on-screen.
Yes, during system installation I made /mnt/mydisk mountpoint for this partition. But I need to plug in the disk every system boot, otherwise it hangs during booting process.

Last edited by dowlq; 02-18-2019 at 02:57 PM.
 
Old 02-18-2019, 03:09 PM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 13,158
Blog Entries: 9

Rep: Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604Reputation: 3604
Quote:
Originally Posted by dowlq View Post
with permissions for every user for creating folders and files?
that is not really advisable.
you probably want the mounted drive to have the same ownership as you, the normal, unprivileged user.
what is its ownership now? maybe that's all you need to change.
show us
Code:
ls -al /path/to/mounted/partition
 
Old 02-19-2019, 11:00 AM   #6
dowlq
LQ Newbie
 
Registered: Feb 2019
Distribution: Kubuntu 18.04
Posts: 5

Original Poster
Rep: Reputation: Disabled
I know how to solve the permissions issue.
Currently I've added my usb hdd to /mnt/mydisk mountpoint during installation of Kubuntu 18.04 and the only issue is when I start system: the drive's usb cable must be plugged in, otherwise the system hangs at booting forever (or very long... I'm not so patient to wait till the end Is it possible to fix this issue so the system will ignore it when hdd isn't connected when booting and automount it to /mnt/mydisk when I'll plug the cable in?

Last edited by dowlq; 02-19-2019 at 11:01 AM.
 
Old 02-19-2019, 11:19 AM   #7
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,014

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by dowlq View Post
I know how to solve the permissions issue.
Currently I've added my usb hdd to /mnt/mydisk mountpoint during installation of Kubuntu 18.04 and the only issue is when I start system: the drive's usb cable must be plugged in, otherwise the system hangs at booting forever (or very long... I'm not so patient to wait till the end Is it possible to fix this issue so the system will ignore it when hdd isn't connected when booting and automount it to /mnt/mydisk when I'll plug the cable in?
You could add a udev rule that mounts the device.
Permissions only need to be adjusted while mounting if you are not using proper linux filesystems like ext4 or similar. If you do use fat or ntfs you can set the uid and gid with options in the mount command or in fstab.

If you don't want to mess with udev, you could also just add noauto to the options in fstab. That way you'd just have to double-click the desktop icon to mount and open the drive. If you do that, also set the user option in fstab so that regular users can mount the device.

Last not least: Use uuids to reliably identify the device in fstab / mount commands.
 
1 members found this post helpful.
Old 02-19-2019, 11:47 AM   #8
dowlq
LQ Newbie
 
Registered: Feb 2019
Distribution: Kubuntu 18.04
Posts: 5

Original Poster
Rep: Reputation: Disabled
My current fstab entry is:
UUID=123... /mnt/mydisk ext4 defaults 0 2

Should I change to:
UUID=123... /mnt/mydisk ext4 defaults,noauto,user 0 0

If I understand I have to change fsck from 2 to 0?
And can I use defaults and noauto at the same time?
 
Old 02-19-2019, 12:12 PM   #9
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,014

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by dowlq View Post
Should I change to:
UUID=123... /mnt/mydisk ext4 defaults,noauto,user 0 0
Yes, if you can live with the device not being automounted, that should do the trick.
Mounting it will require manual interaction then.

Quote:
Originally Posted by dowlq View Post
And can I use defaults and noauto at the same time?
I believe so.
 
Old 02-19-2019, 12:15 PM   #10
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,014

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by dowlq View Post
If I understand I have to change fsck from 2 to 0?
Overlooked this one in the first go. This change will disable the filesystem check at boot time. Which makes sense because the device might not be there at boot time.
 
Old 02-20-2019, 02:43 AM   #11
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 987

Rep: Reputation: 259Reputation: 259Reputation: 259
Quote:
Originally Posted by joe_2000 View Post
You could add a udev rule that mounts the device.
Below is a quote from ArchWiki:
Quote:
To mount removable drives, do not call mount from udev rules. In case of FUSE filesystems, you will get Transport endpoint not connected errors. Instead, you could use udisks that handles automount correctly or to make mount work inside udev rules, copy /usr/lib/systemd/system/systemd-udevd.service to /etc/systemd/system/systemd-udevd.service and replace MountFlags=slave to MountFlags=shared.[3] Keep in mind though that udev is not intended to invoke long-running processes.
I believe "MountFlags=shared" would allow the drive to be mounted to a second directory while still being mounted to /media/username/myremovabledrive.

Another option to look into is inotify-hookable, inotify is included with the kernel and using inotify-tools or inotify-hookable, you can monitor files or directories for specified events and process a command instantly when the event occurs. So with inotify-hookable, you should be able to monitor /media and sub-directories as depending on which user plugs the drive in, that username will appear in /media and below that the label of the external drive. Once the label name of that drive appears in /media sub-directories, your command can unmount it and then remount it in /mnt/mydisk with desired permissions.

This may need some head scratching, because you can mount a specific partition off a script based on it's UUID, but I don't think that option is available for umount command. Because the external drive for instance will not always be /dev/sdb, if you have something else plugged into a USB port, it might be /dev/sdc or /dev/sdd etc. depending on how many other pen drives or whatever are plugged in before it. If you could use the UUID for umount, then you wouldn't need to care what device it is, the UUID is unique, but if you put your mind to it, you can do it, you should be able to drum up a way of unmounting the proper device based on some unique identity, perhaps grepping it's serial number to determine it's device node and passing that to the umount command.

inotify-hookable
Code:
inotify-hookable \
        --watch-directories /media \
        --on-modify-path-command "^unmount mydisk && mount the ext4 partition at /mnt/mydisk with these permissions"
or      --on-modify-path-command "^run my script in this directory"
This way the NTFS partition in not mounted, only the ext4
To find unique attributes for your drive, use fdisk -l command to find it's device designation, if it's /dev/sdb, run the command below:
Code:
udevadm info --name=/dev/sdb --attribute-walk

Last edited by Brains; 02-20-2019 at 03:25 AM.
 
1 members found this post helpful.
Old 02-20-2019, 03:17 AM   #12
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,014

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by Brains View Post
Below is a quote from ArchWiki
good to know

Quote:
Originally Posted by Brains View Post
because you can mount a specific partition off a script based on it's UUID, but I don't think that option is available for umount command.
Not sure that that's true. You should be able to do
Code:
umount /dev/disk/by-uuid/<uuid>
no? (Can't test right now)

Alternatively, you can just call umount with the mount point as the argument to avoid the problem altogether.
 
Old 02-20-2019, 03:34 AM   #13
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 987

Rep: Reputation: 259Reputation: 259Reputation: 259
Quote:
Originally Posted by joe_2000 View Post
good to know


Not sure that that's true. You should be able to do
Code:
umount /dev/disk/by-uuid/<uuid>
no? (Can't test right now)

Alternatively, you can just call umount with the mount point as the argument to avoid the problem altogether.
Because the drive has two partitions, umount via UUID will only unmount that one partition, you need to determine the device designation which is not absolute depending on how many other removable media are plugged in. As such, it is better to find a unique attribute such as label or serial number to unmount both partitions, then mount only the ext4 at the desired location.
 
Old 02-20-2019, 04:15 AM   #14
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,014

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by Brains View Post
Because the drive has two partitions, umount via UUID will only unmount that one partition, you need to determine the device designation which is not absolute depending on how many other removable media are plugged in. As such, it is better to find a unique attribute such as label or serial number to unmount both partitions, then mount only the ext4 at the desired location.
The OP does not want the ntfs partition to be "visible in Linux" anyway, so you'd not mount it to begin with.
And even if it was mounted: Why not simply call umount on both partitions?

I am probably missing something...
 
Old 02-20-2019, 04:48 AM   #15
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 987

Rep: Reputation: 259Reputation: 259Reputation: 259
Quote:
Originally Posted by joe_2000 View Post
I am probably missing something...
Yes...you are.
If I'm not mistaken, the default action is that both partitions will be automatically mounted (depending on the DE). inotify is fast, by monitoring say /dev or appropriate sub-directory, when the serial number of the drive appears, your script would likely start with a sleep command to ensure the default mounting of both partitions is complete, then the next command shall unmount the drive which in turn unmounts both partitions before mounting only the ext4 partition in the desired directory with desired permissions and attributes.

Last edited by Brains; 02-20-2019 at 04:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about installing audio drivers, automounting ext4 partition, and general linux skills. louierev07 Linux - Newbie 6 07-27-2016 05:17 AM
I set up an ext4 partition on external HD to store media files. permission issues rbrtscornell Linux - Newbie 9 04-20-2015 12:15 PM
How to change file system from ext4 journeying to ext4 writeback ? 5883 Linux - Newbie 6 03-10-2014 09:04 AM
modprobe: Module ext4 not found. no dependencies for kernel module 'ext4' found TheIndependentAquarius Linux - Newbie 6 01-25-2012 06:07 AM
Is it safe to format USB flash to ext4 or ext4? joham34 Linux - Newbie 2 01-08-2011 12:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration