Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
Quote:
Originally Posted by dowlq
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.
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.
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
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.
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
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?
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.
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.
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 \
--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:
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.