LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to mount a subdirectory at boot time (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-mount-a-subdirectory-at-boot-time-4175468745/)

linux.penguin67 07-07-2013 12:14 AM

How to mount a subdirectory at boot time
 
I have a partition, sda8, that gets mounted as /share1 at boot time by it's entry in /etc/fstab. What I NEED is to actually have:

/share1/this_dir mounted as /this_dir
and
/share1/that_dir mounted as /that_dir

I tried using fstab, couldn't make it work - I guess it just mounts partitions, not subdirs.

After booting, I can issue the command:
mount --bind /share1/this_dir this_dir

This works great, but I don't want to do this EVERY time I reboot.

I tried putting this in /etc/skel/.profile doesn't work?

Any ideas?
Thanks in advance,
Terry.

astrogeek 07-07-2013 12:23 AM

Yes, you can only mount partitions (devices) that way.

To access the subdirs I would mount it then create symlinks into the mounted subdirs. Then you would access this_dir and that_dir by the symlinks. When sda8 was not mounted the symlinks would remain but simply be dead ends, but would be valid again when the device is mounted.

linux.penguin67 07-07-2013 12:41 AM

After rebooting, via /etc/fstab, /dev/sda8 gets mounted as /share1.
If I issue the following command:
ln -s /share1/this_dir this_dir
then try ls -l, I get:
lrwxrwxrwx 1 root root 13 Jul 7 00:36 this_dir -> /share1/this_dir/

ok, hang on... I got to smart for myself.

When I do a normal ls, I get all my files!

Question for you astrogeek, when I issue the ln -s /share/this_dir this_dir command, the symlink exists over multiple boots, right? <-- of course it does. -->

Cheers,
Terry.

Madhu Desai 07-07-2013 02:42 AM

How about this in /etc/fstab

Code:

/dev/sda8                /share1                ext4        defaults        0 0
/share1/this_dir        /share1                none        bind                0 0

where 'this_dir' is one of directory in '/dev/sda8'. Also note that when you do this, other than 'this_dir', all other sibling directories of 'this_dir' in /dev/sda8 are not accessible.

cyberpatrol 07-07-2013 06:03 AM

Another possible way would be adding the command

mount --bind /share1/this_dir this_dir

to the local initscript like

/etc/rc.d/rc.local
/etc/init.d/local
/etc/local.d/local.start

or whichever file this is on your distribution.


All times are GMT -5. The time now is 11:53 PM.