Mount Different Folders On Disk And Locations

Is it possible to mount different folders on disk to different locations? 

I have a disk with two folders, folder1 and folder2. I'd like to mount these folders separately in my home folder, that is, to the locations:

Code:
/home/<username>/folder1
/home/<username>/folder2Is that possible? If so, how?

Solution:

Suppose you had a user on a ntfs partition, say /dev/sda1 and you wanted to map each user's document folders to a folder, say Documents/Windows in each of those same user's /home directories on your (dual-booting) Linux system. Then the following commands (in bold below) would do the trick. (Lines starting with a hash mark - # - are comments)

Code:

$ # First, create a mount point for the partition
$ sudo mkdir /Vista
$ # Then add a line to /etc/fstab so the partition will be automatically mounted every time you boot your system.
$
$ # CAUTION: The two redirection symbols (vis: >>) in the
$ # following command are essential. If you use a single redirection, then
$ # your whole fstab will be replaced by the single line, and your system
$ # will be unbootable. A simple sudo cp /etc/fstab /etc/fstab.backup
$ # would be prudent before changing the contents of this critical file.
$ #
$ sudo echo UUID=342D7D7923AC4107 /Vista ntfs-3g rw,defaults 0 0 >> /etc/fstab
$ # To get the UUID, do a ls -l /dev/disk/by-uuid. Instead of UUID=
$ # you could use LABEL= (look in /dev/disk/by-label) or just
$ # use the physical address /dev/sda1. The use of the UUID or LABEL
$ # option is preferred because it lets you move your drives without breaking
$ # your system. (Look at man fstab for more information.)
$
$ # Verify that you've got the fstab entry correct.
$ sudo mount /Vista
$ # (If the mount fails, edit the fstab by hand (sudo gedit /etc/fstab) until it works.
$
$ # Verify that the data is correct and locate the Documents folder you want to map:
$ ls /Vista/

autoexec.bat  Commands                hiberfil.sys  pagefile.sys  Program Files  System.sav                 Windows
Books         config.sys              HP            PerfLogs      Recovery       System Volume Information
boot          CVS                     IPH.PH        Pictures      $RECYCLE.BIN   Users
bootmgr       Documents and Settings  MSOCache      ProgramData   SWSetup        Wallpapers
$ ls /Vista/Users/
All Users  Default  Default User  desktop.ini  Judy  Peter  Public
$ ls /Vista/Users/Peter/
AppData           Music                                                                                         Pictures
Application Data  My Documents                                                                                  PrintHood
Contacts          NetHood                                                                                       Recent
Cookies           NTUSER.DAT                                                                                    Saved Games
Desktop           NTUSER.DAT{3a539871-6a70-11db-887c-d362bd253390}.TM.blf                                       Searches
Documents         NTUSER.DAT{3a539871-6a70-11db-887c-d362bd253390}.TMContainer00000000000000000001.regtrans-ms  SendTo
Downloads         NTUSER.DAT{3a539871-6a70-11db-887c-d362bd253390}.TMContainer00000000000000000002.regtrans-ms  Start Menu
Favorites         ntuser.dat.LOG1                                                                               Templates
Links             ntuser.dat.LOG2                                                                               Videos
Local Settings    ntuser.ini
$ ls /Vista/Users/Peter/Documents/
desktop.ini  Downloads  My Music  My Pictures  My Videos
$
$ # Create the folder in the user's directory to which Windows folder is to be mapped:
$ mkdir -p /home/Peter/Documents/Vista
$ # Create the link to the Windows folder
$ ln -s /Vista/Users/Peter/Documents/ /home/Peter/Documents/Vista/
$ # Verify that the link works
$ ls /home/Peter/Documents/Vista/
Documents
$ ls /home/Peter/Documents/Vista/Documents/
desktop.ini  Downloads  My Music  My Pictures  My Videos
It's really that simple. (The above an actual terminal session I just ran on my Fedora system.)

Oh, I was logged in a Peter when I ran that. If I had been logged in as someone else (e.g., root), the last makdir command would either need to be run as Peter (i.e., su Peter -c 'mkdir -p /home/Peter/Documents/Vista') or followed by a sudo chown Peter:Peter /home/Peter/Documents/Vista so Peter could use the directory.

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.