Thursday, March 18, 2010

access files below a mountpoint

Today I needed to be able to access a directory that is normally used as a mountpoint. I needed to do this because we wanted to transition some automounts to hardmounts without interruption.

So an example is we have auto mount table /test specfied in /etc/auto.master which automounts /test/1 and /test/2 automatically.

Say someone was on a system using /test/1 actively. I would want to 'fix' the system by setting up new entries in /etc/fstab for /test/1 and /test/2 and remove /test from /etc/auto.master. Then I would want to restart automount.

/test/1 would still be mounted since its in use which is good as then there is no interruption to the user. I would create /test/2 and mount a 'hard' mount on that. Since automount was restarted and no longer has an entry for /test in /etc/auto.master then /test/1 will never timeout from automount anymore.

However, the base mountpoint that automount was using is /test ... so on a reboot /test will still exist but directories /test/1 and /test/2 will no longer exist and the system will fail to mount on those /etc/fstab entries ...

What I ended up doing was:
  • mount --bind / /mnt
  • cd /mnt/test
This allows me to be 'underneath' the /test mountpoint which currently has /test/1 mounted from automount earlier.
  • mkdir 1 2
  • cd /
  • umount /mnt
Now if the system reboots /test/1 and /test/2 will exist and the mounts specified in /etc/fstab will mount correctly.

No comments: