First of all “bind-mounts” are just simple plain mounts. (that you might already know)

if not:

  1. creating a mount-point-folder
  2. than accessing a external data-source (SMB-Share, NFS-Share) and making it accessible via that mount-point-folder

“In general: a hard link is a filesystem object, a mount point – is kernel entity.”

That means:

  • mounts can use various protocols to access external data sources (FTP, SMB, NFS…)
  • hardlinks can NOT use protocolls
    • they only work with file system methods of accessing the same folder from two different locations in your filesystem

“hardlink will persistent during reboot, mount point will not.” (unless one lets system “auto-mount” external datasources via rc.local or fstab on startup)

creditz: http://stackoverflow.com/questions/30454191/difference-between-hardlink-and-bind-mount

but then again:

  • can the same partition be fstab mounted in two different locations?
  • at least in CentOS8 yes it can!

to get an filesystem & system overview

create new script:

vim /scripts/loop_df.sh

#!/bin/bash
# will give overview of filesystem
# updates every 1 sec
while true;
do
	clear;
	echo '=========== looped harddisk info ';
	datum;
	dmesg|tail -n20;
	echo '=========== where is what';
	lsblk -o 'NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID';
	echo '=========== harddisk usage';
	df -Th;
	sleep 1;
done

mark runnable and run

chmod +x /scripts/loop_df.sh
/scripts/loop_df.sh

mounting the same raid md0 at two different locations

hostnamectl; # tested on
  Operating System: CentOS Linux 8
       CPE OS Name: cpe:/o:centos:centos:8
            Kernel: Linux 4.18.0-240.10.1.el8_3.x86_64
      Architecture: x86-64

cat /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Tue Jan 19 11:07:30 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root    				/                       xfs     defaults,x-systemd.device-timeout=0	0 0
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx	/boot                   ext4    defaults				1 2
/dev/mapper/cl-home     			/home                   xfs     defaults,x-systemd.device-timeout=0	0 0
/dev/mapper/cl-swap     			swap                    swap    defaults,x-systemd.device-timeout=0	0 0

# example: mountint the same raid1 (md0) at two different mount points
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx	/alternative/mountpoint ext4	defaults,nodev				0 2
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx	/mnt/md0		ext4	defaults,nodev				0 2

… worked just fine.

how to mount a already mounted folder with as different user/with different priviliges:

# mounts PROJECTNAME into my workspace /var/www
# specify projectname
PROJECT="PROJECTNAME"

# create mountpoint
mkdir /var/www/$PROJECT

# mount project with userid: 1000 and groupid: 1000
bindfs -u 1000 -g 1000 /media/sf_PROJECTS/$PROJECT /var/www/$PROJECT/

this is how you “un-bind” “un-mount”:

# "unmount not found" can drive one crazy X-D
alias unmount="umount"

# unmount PROJECT
umount /var/www/$PROJECT

Another Usecase 🙂

“Have you ever dealt with a system that wasn’t partitioned properly when it was built and now it has gone into production? You’ll probably be hard pressed to find the time and patience to rebuild the system any time soon. Luckily there is a way to step around many of the limitations of a poorly partitioned system using bind mounts.

Bind mounts are quite simple. Instead of mounting a device (with a file system) on a particular path you are mounting one path into another path.

For example: Let’s say you have a small /var but a very large /opt partition and you need additional space for your growing log files.

First, shut down the services writing to log files, then…”

mv /var/log /opt/var_log
mkdir /var/log
mount -o bind /opt/var_log /var/log

You will now see this reflected when running the mount command:
example_image.jpg

# mount | grep var
/opt/var_log on /var/log type none (rw,bind)

example_image.jpg

At this point you are ready to restart the previously stopped services.

If you want this to persist across reboots, you’ll just need to update your /etc/fstab with the bind mount as well.
example_image.jpg

# /etc/fstab
/opt/var_log              /var/log                 none    bind    0 0

example_image.jpg
And there you have it! Its not beautiful, but it will help you keep the lights on until you can get a long-term fix in place.

creditz: http://backdrift.org/how-to-use-bind-mounts-in-linux

from:
mount.man

as far as i understand it: you can mount the same dir in two different places.

but where is the difference to hardlinks?

The bind mounts.
Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else. The call is:

mount --bind olddir newdir

or by using this fstab entry:

/olddir /newdir none bind

After this call the same contents are accessible in two places. One can also remount a single file (on a single file). It’s also possible to use the bind mount to create a mountpoint
from a regular directory, for example:

mount --bind foo foo

The bind mount call attaches only (part of) a single filesystem, not possible submounts. The entire file hierarchy including submounts is attached a second place by using:

mount --rbind olddir newdir

Note that the filesystem mount options will remain the same as those on the original mount point, and cannot be changed by passing the -o option along with –bind/–rbind. The mount
options can be changed by a separate remount command, for example:

mount --bind olddir newdir
mount -o remount,ro newdir

Note that the behavior of the remount operation depends on the /etc/mtab file. The first command stores the ‘bind’ flag in the /etc/mtab file and the second command reads the flag from
the file. If you have a system without the /etc/mtab file or if you explicitly define source and target for the remount command (then mount(8) does not read /etc/mtab), then you have to
use the bind flag (or option) for the remount command too. For example:

mount --bind olddir newdir
mount -o remount,ro,bind olddir newdir

Note that remount,ro,bind will create a read-only mountpoint (VFS entry), but the original filesystem superblock will still be writable, meaning that the olddir will be writable, but the
newdir will be read-only.

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin