# on the fly mounting when accessed via samba

## shaumux

Hi 

I don't know if its even possible but i want to mount a partition on the fly automatically when accessed by samba.

I was thinking that i might need to share the block device itself via samba somehow to make this happen.

Anybody got any idea on implementing this?

----------

## hdcg

Hi,

take a look at the preexec and postexec option of smb.conf (http://www.samba.org/samba/docs/man/manpages-3/smb.conf.5.html#idp61460000).

Best Regards,

Holger

----------

## shaumux

Maybe i can use postexec to unmount but i don't understand how to use preexec in this scenario.

Let me explain the scenario in more detail.

Suppose there are 4 partitions /dev/sdb{1,2,3,4}

What i want is when i try to access /dev/sdb1 it should only mount /dev/sdb1 and not the others and that too only when i try to access it instead of when i connect to samba server.

Is that possible to achieve?

Thanks for the reply.

----------

## Hu

You might be able to use the automounter to do this.  It is normally used for network filesystems.

----------

## shaumux

 *Hu wrote:*   

> You might be able to use the automounter to do this.  It is normally used for network filesystems.

 I don't want to automount the samba filesystems, i want to mount the local filesystems on the machine with samba when they are accessed via samba from another system

----------

## hdcg

Hi,

for the preexec/postexec szenario you need to define a share for the mount point as well as the proper fstab entry. The preexec option makes sure that the mount command is invoked and the preexec makes sure that the umount command is invoked.

A usual example for this is a cdrom share like:

```
[cdrom]

   comment = CD-ROM

   writable = no

   locking = no

   path = /cdrom

   public = yes

   preexec = /bin/mount /cdrom

   postexec = /bin/umount /cdrom

```

This simple setup works well in a single user szenario. With multiple users accessing the same share for the same time I am not so sure.

Best Regards,

Holger

----------

