1

I have installed Ubuntu system at an SS disk and I wish users to access partitions of the second (mechanical) disk as common depositories with full read/write/delete permissions for each file. And I wish that each user see such a partition (say /dev/sdb7) as a directory with a fixed name (say /home/the_user/F). I was advised (Is it possible to mount a partition as a common depository for users with the same relative path?) to mount the partition during boot and to symlink that mountpoint to somewhere in the user's home. However, in the manual for

link
I see an option
‘-d’
‘-F’
‘--directory’
     Allow users with appropriate privileges to attempt to make hard
     links to directories.  However, note that this will probably fail
     due to system restrictions, even for the super-user.
I am afraid of it. Please advise me an example of a proper link; and the corresponding group or bindfs commands to be used at user login or once forever by the root. Thanks!

3 Answers 3

1

You don't need to use hard links, actually we can not create a hard link to a directory because it makes loop in file system hierarchy.

You have to use -s option to create a symlink (symbolic link):

Let's say I have mounted /dev/sda7 on /media/some/mount/point. To create a link to this path I have to run:

ln -s [target] [symlink]

Like:

ln -s /media/some/mount/point  /home/username/F

The permission of link would be 777 but however a symlink is a different file from you actual directory, it only grant access to symlink itself and the user must have correct permissions to be able to work with the files in /media/some/mount/point.

1
1

Regarding your concern about linking to the mounted directory, it sounds like you may have simply stumbled onto the wrong program. According to your post, you were advised to create symbolic links (i.e. symlinks). However the link command only creates hard links. To create symbolic links you can use the ln command instead, e.g.:

ln -s /path/to/mount/point  /home/the_user/F

Regarding shared access, you can set this up using ACLs (access control lists), e.g.:

sudo setfacl -Rm g:mount-group:rwx /path/to/mount/point
sudo setfacl -Rdm g:mount-group:rwx /path/to/mount/point

To demonstrate what this might look like and give you a starting-point to experiment with, here's a longer example which bind-mounts a directory (you would replace this with the actual mount that you want), sets its ownership and permissions (using access control lists), and then creates a symbolic link to it inside another directory:

# Create a group to own the shared mount
sudo groupadd mount-group

# Create a user that belongs to this group
sudo adduser mount-user
sudo usermod -a -G mount-group mount-user

# Create a directory to mount
mkdir /tmp/mount-source

# Create the mount-point
mkdir /tmp/mount-target

# Bind-mount the directory onto the mount point
sudo mount --bind /tmp/mount-source /tmp/mount-target

# Set the group owner for the mounted volume
sudo chown :mount-group /tmp/mount-target

# Set the group permissions to match the user permissions
sudo chmod -R g=u /tmp/mount-target

# Set the setgid bit on the mounted volume
sudo chmod g=u,g+s /tmp/mount-source

# Set the ownership and permissions for the mounted volume using an ACL
sudo setfacl -Rm g:mount-group:rwx /tmp/mount-target

# Set the default ownership and permissions for files created inside the mount-point
sudo setfacl -Rdm g:mount-group:rwx /tmp/mount-target

# Login as the test user
su -l mount-user

# Link a subdirectory inside the user's home folder to the mounted volume
ln -s /tmp/mount-target ~/link-to-mount-target

# Create a new file inside the mounted volume
echo 'Hello world!' > ~/link-to-mount-target/hello.txt

# Check the permissions on the new file
getfacl ~/link-to-mount-target/hello.txt
0

I think that your question needs two a two-fold answer: firstly on mounting of the device in the filesystem, and secondly on linking a destination location.

Before you start

The following explanations require a terminal program (keyboard shortcut: Ctrl+Alt+t) for typing the commands in.

You will also need a superuser privileges. Typically (as the first user after the fresh installation) you get the privileges by typing sudo ahead of the command. After that (typically, if you are the first user after the fresh installation) you have to provide your own password before the command runs.

Your hard drive (the "mechanical" disk) needs to be connected to your computer already, and formatted properly with a file system (like ntfs or ext4).

Beware! By changing your fstab file, you work on internals which can stop your computer from booting. This is not a permanent damage, but it will need skill and time to repair. Work with it carefully.

If in doubts about any of the above prerequisite, please ask in the comment.

Mounting the disk at boot-time

Mounting disks in boot-time is made in /etc/fstab file. For this you need to know either the UUID of your "mechanical" disk or at least it's name in the /dev directory.

Find the UUID and the name (similar to /dev/sdb5) of your disk:

ls -l /dev/disk/by-uuid

It will be listed here. Now determine the filesystem. It will be listed in the last column of the appropriate line of

sudo fdisk -l | less

Next, decide on the mount path, and create it:

sudo mkdir -p /media/shareddrv

Knowing the disk's UUID, name, and the file-system type, your configuration line for /etc/fstab looks like this:

UUID=481aba75-c8a7-4b70-bdc4-fab4de7c1410  /media/shareddrv  ext4  errors=remount-ro  0  2

where UUID=481aba75-c8a7-4b70-bdc4-fab4de7c1410 can be something like /dev/sdb5 if you had problems establishing what the UUID is. The part /media/shareddrv is the location that you have decided on, and ext4 is the partition type, and be different depending on your disk. The rest remains preferably as it is here.

You have to add this entire line to your /etc/fstab. Since there are many ways to do it, one quite convenient is to use sudo nano /etc/fstab and to type/paste the line at the end of the file.

Now make your changes work for you: the simpliest way is to RESTART your computer (e.g. sudo init 6 or sudo shutdown -h now). If all works, you will see your "mechanical" disk and its mount-point after you type: df -h in the terminal.

Linking the disk in user directories

This part can be done user-after-user, semi-manually. For a user "alice", run:

TMPUNAME=alice;  sudo -u $TMPUNAME ln -s /media/shareddrv /home/$TMPUNAME/F

And repeat this for each user. At the end you could unset TMPUNAME but not necessarily.

I hope all works for you. If you find this mini-tutorial helpful, please upvote my answer and mark it as useful. Thank you! Also ask more questions if something isn't clear or does not work!

1
  • Wow! The answers pop up so quickly! Hard to compete! Thanks guys! Aug 27, 2017 at 23:30

You must log in to answer this question.

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