Thursday, December 13, 2007

Mount a folder inside another folder (Binding)

I'll show you how to mount a folder residing somewhere in a filesystem to another folder.

Its a line command,
sudo mount -o bind /sourcefolderurl /destinationfolderurl

Done! Now where is it useful?
I ran into this problem during my ftp server setup,
ftp://myserver mapped to file system /media/sda7/ftpshared, ie ftp://myserver/a.mp3 mapped to /media/sda7/ftpshared/a.mp3.

But i also had to share /opt/cache/apt/archives (all the .deb files) within the ftp server, creating symbolic links wasn't working since proftpd worked in a chrooted environment, thus this was a good solution.

sudo mount -o bind /opt/cache/apt/archives/ /media/sda7/ftpshared/archives

To automatically mount the folder, make an entry in /etc/fstab file at the very end,
/var/cache/apt/archives /media/sda7/ftpshared/archives auto bind,gid=46,defaults 0 0

And on every boot, the folder is automatically mounted.

Cheers!!

2 comments:

Laurie said...

Ahh fstab. I had used sessions to run some bash at login to no avail. Glad this page is still up lol

Sikku said...

This was helpful to mount my home folder from other partition to my existing home folder....

Thanx...