7

I have a problem with binding two directories. The problem comes that storage on hard disk is almost run out and I install another disk moving files in ~/Documents/ into one folder of the new disk. I still want mount --bind folder_on_new_disk ~/Documents, thus I will not change my favor.

The problem is that could I add an item in /etc/fstab to achieve this automatically when system startup?

amin
  • 125
  • 6
Summer_More_More_Tea
  • 983
  • 6
  • 14
  • 28

2 Answers2

17

You can add this to fstab as follows:

/mnt/new_disk/folder /home/[username]/Documents    none    bind    0 0

Replace the correct folder name, and the username where the documents folder is. It also presumes the /home directory is where your user folders are, so adjust accordingly if not.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
Paul
  • 59,223
  • 18
  • 147
  • 168
6

@Paul's fstab example is, basically, the way to go if you want an answer to the question as asked. However, I would suggest that unless you have specific reasons for only moving your documents, it might not be a bad idea to move the whole /home directory to the new disk, and use the same technique to bind /home to its new location (or even just move /home/* to the root of a partition on the new drive and mount that partition at /home). This will provide two major benefits:

  1. You are likely to get more space for your home directory.
  2. You completely separate the operating system, system-wide configuration files and application binaries from your own files.

The point on separation to me is the bigger issue: it means that if you need to reinstall the OS for some reason, you won't have to worry anywhere near as much about your personal files (e-mails, documents, music, etc etc).

Unix mount points are a very flexible construct - do take advantage of that.

user
  • 29,449
  • 11
  • 99
  • 144