Bind allows you to take a mounted partition and mount parts or all of it somewhere else in the file hierarchy. I'll show 4 different ways to accomplish this depending on how you want to use it. I will use as an example a data partition that I have set up in lieu of a dedicated /home partition at /Data. That partition is auto mounted in fstab as:
I have taken possession of the mounted partition: sudo chown altair /DataUUID=f7927995-b098-42be-ada0-987857f5177a /Data ext4 defaults,noatime 0 0
And I have populated /Data with all the directories in a normal home directory: Documents, Downloads, Pictures, Videos, etc ...
[1] A Manual Bind - Good for that session only. Does not survive a reboot
The general syntax of the command looks like this:
So in this example:sudo mount --bind /olddirectory /newdirectory
To unmount the bind:
sudo umount /newdirectory
Code: Select all
sudo mount --bind /Data/Documents /home/altair/Documents
Code: Select all
sudo mount --bind /windows/WinXP/"Documents and Settings/altair/My Documents" /home/altair/Documents
Code: Select all
sudo umount /home/altair/Documents
* Whatever you do in one happens to the other.
* The filesystem mount options will remain the same as those on the original mount point and you cannot change one without changing the other. Or in the case of a Windows fileystem ( i.e., NTFS ) not at all unless you change the mount options of the original mountpoint in fstab.
[2] Auto Mount at Boot using rc.local
You can use the same manual mount command ( without the sudo ) and add it to /etc/rc.local right above the "exit 0" line:
[3] Auto Mount at Boot by creating your own Upstart script - NO LONGER VALID IN MINT18 SINCE THERE IS NO UPSTART: NOTE: There seems to be an issue with upstart, bind, and Mint17-Cinnamon ( and so far only Cinnamon ) which makes this method not work. Please use method [2] - rc.local until I can find a resolution.#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
mount --bind /Data/Documents /home/altair/Documents
mount --bind /Data/Downloads /home/altair/Downloads
mount --bind /Data/Pictures /home/altair/Pictures
exit 0
This is the method I now use by default since I can make sure that the bind operation only happens after the original partition is mounted.
Create an upstart job named "bind-home.conf"
Code: Select all
gksu gedit /etc/init/bind-home.conf
Code: Select all
# Remount partitions with bind
#
description "Bind Data Partition Subdirectories to My Home Directory"
start on stopped mountall
script
mount --bind /Data/Documents /home/altair/Documents
mount --bind /Data/Downloads /home/altair/Downloads
mount --bind /Data/Pictures /home/altair/Pictures
end script
[4] Auto Mount at Boot in Fstab - Mint18
The bind syntax and how you handle spaces changes in fstab and it must appear someplace after the line that identifies the mount of the original partition. So for example:
Code: Select all
UUID=f7927995-b098-42be-ada0-987857f5177a /Data ext4 defaults,noatime 0 0
/Data/Documents /home/altair/Documents auto bind,x-systemd.requires=/Data 0 0
Code: Select all
UUID=DA9056C19056A3B3 /windows/WinXP ntfs defaults,uid=1000,gid=46,umask=007 0 0
/windows/WinXP/Documents\040and\040Settings/altair/My\040Documents /home/altair/Documents auto bind,x-systemd.requires=/windows/WinXP 0 0
I should note that another way to accomplish all this is simply to create a symbolic link from one location to the next.