HowTo: Using Bind to Remount Part of a Partition

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

HowTo: Using Bind to Remount Part of a Partition

Postby altair4 on Sun Jun 05, 2011 12:53 pm

HowTo: Using Bind to Remount Part of a Partition.

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:
UUID=f7927995-b098-42be-ada0-987857f5177a /Data ext4 defaults,noatime 0 0

I have taken possession of the mounted partition: sudo chown altair /Data
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:
sudo mount --bind /olddirectory /newdirectory
To unmount the bind:
sudo umount /newdirectory

So in this example:
Code: Select all
sudo mount --bind /Data/Documents /home/altair/Documents

If you have spaces in the path it has to have quotes around it like this:
Code: Select all
sudo mount --bind /windows/WinXP/"Documents and Settings/altair/My Documents" /home/altair/Documents

To "unbind" the directory:
Code: Select all
sudo umount /home/altair/Documents

* The same content is now accessible in two different places: In /Data and in /home/altair.
* 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:
#!/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


[3] Auto Mount at Boot by creating your own Upstart script: 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.

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

The content of that file would look like this:
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

The "start on stopped mountall" insures that the bind commands will not be executed until all system mounts ( i.e., fstab ) are completed.

[4] Auto Mount at Boot in Fstab

NOTE: This is the traditional method and I have used it myself without issue until recently. Something has happened with mountall / upstart and who knows what else to make this a very unreliable method. I post it here in case the cause of the problem gets resolved. I have seen posts lately where this method is still being used with success so it may just be something unique with my setup but I urge caution.

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 0 0

Or in the case of an NTFS partition with spaces in the path:
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 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. However, I live in a very networked environment with a combination of Windows, Macs, and Linux machines so I use Samba and the Samba client cannot follow symbolic links without modifying config files which Samba does not recommend.
Last edited by altair4 on Sun Jul 27, 2014 3:25 pm, edited 5 times in total.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 16
Level 16
 
Posts: 6152
Joined: Tue Feb 03, 2009 10:27 am

Linux Mint is funded by ads and donations.
 

Re: HowTo: Using Bind to Remount Part of a Partition

Postby Habitual on Sun Jun 05, 2011 2:33 pm

good stuff. Thanks!
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2219
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: HowTo: Using Bind to Remount Part of a Partition

Postby altair4 on Mon Jun 06, 2011 5:52 pm

Thanks. I always wonder if anybody reads my obscure little HowTo's :)
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
altair4
Level 16
Level 16
 
Posts: 6152
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: Using Bind to Remount Part of a Partition

Postby DaLiMan on Fri Nov 15, 2013 5:19 pm

After years, it is still very helpfull..... :D
Thanx!
DaLiMan
Level 1
Level 1
 
Posts: 8
Joined: Fri Nov 15, 2013 5:16 pm

Re: HowTo: Using Bind to Remount Part of a Partition

Postby Cammo on Tue Apr 15, 2014 1:24 am

Thanks Altair, still very helpful. Keep up the good how-tos :)
Cammo
Level 2
Level 2
 
Posts: 60
Joined: Tue Apr 08, 2014 8:19 pm

Re: HowTo: Using Bind to Remount Part of a Partition

Postby Spearmint2 on Wed Jul 16, 2014 11:40 pm

Complaint filed, lol.

viewtopic.php?f=90&t=173334
All things go better with Mint. Mint julep, mint jelly, mint gum, candy mints, pillow mints, peppermint, chocolate mints, spearmint,....
User avatar
Spearmint2
Level 10
Level 10
 
Posts: 3312
Joined: Sat May 04, 2013 1:41 pm
Location: Maryland, USA


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests