In this video, Kevin Dankwardt describes and demonstrates automounting. Home directories for different users are shown being automatically mounted. The timeout for the automounter is set and demonstrated.
- [Instructor] Mounting on-demand, that is a directory isn't mounted to ask for it to be mounted. Lenox accomplishes this with autofs, just what's commonly used for NFS, you may have a system with say lots of home directories and at any given time, only a few of those are being used. If those are all being mounted via NFS, that means you could have lots of things mounted with NFS that aren't being used and that's wasteful, it's taking up time and space.
So with autofs, what happens is when somebody changes directory or opens up a file, in an autofs mounted directory, then it gets mounted from the server. And it stays mounted for a little while and if it's not used after a while it gets unmounted. So there's going to be a few files involved, the first file the default config file or the config file you'll specify is going to list files that will specify where things get mounted.
So for example, in the auto.master you could say we're going to have a mount point /home and that means stuff in the file specified for that will be mounted under /home. So you'd have /home and then you'd have the name of a file. So in that second file you would save the things that are going to get mounted underneath /home. So in auto.master you could have multiple directories for each directory you'd have a file and that would be specifying how stuff under that directory gets mounted.
So a map file for example, for the home could have something like kevin so the directory kevin would get mounted underneath home. And we have the file system type of NFS although you can probably leave that off. And then what directory from a server is supposed to be the directory that gets mounted is kevin. So we'd have some server like homeserver and the directory on that server in this case exports/kevin so that directory from that NF server would get mounted on /home/kevin on our system that's running autofs.
And /home/kevin will get created if it's not there the directory kind actually kind of come and go. So let's look at setting up NFS and doing auto mounting. Alright so we want to look at auto mounting and NFS so let's look at a few files. First of all let's look at etc/exports. That file is what files this machine will serve via NFS.
For this example we're going to have the same machine be both client and server. So right now etc/exports is a file for the NFS server, so tmp/c1 would be available, we won't use that in this demo and /exports will be available and everything underneath /exports. If we look at /exports, we see there's three directories. So those can be mounted, the whole /exports could be mounted or any of those directories underneath it could be mounted.
So to set up NFS we would edit the etc/exports file in this case if we look at the /exports line, we have the directory /exports space and then we'd have what machines are allowed to mount that, in this case asterisk which means any machines, if we put an IP address there then only that machine would be able to mount. Now with NFS mounting is done by servers, not by people.
So we give a server an IP address, access to it. And then we have features about how they can mount it and it's important in this exports file that there's no spaces after we do that asterisk. The ro means stuff can be mounted read only, no read write. For home directories you typically want the rw there. An the no_root_squash means if some machine mounts this as root, then they get to act like root, files they create are owned by root and so forth, without that, then the NFS server when it would create files would change the ownership to be a special non-privilege user, the nobody account.
And then we'd start up the NFS service with system control or service command like service nfs start. For example and this is so you can control what it tells you what that would be, that would be system control start nfs.service. So that's running. And that means that those directories can be mounted, so let's look at now setting this machine up as a client for autofs.
So we're going to look at /etc/auto.master. And we say we're going to mount stuff underneath home and the stuff that we're going to mount underneath home will be described it etc/auto.home. And we're going to set a time out of just ten seconds, that's good for the demo. That means after ten seconds of not using something that got mounted, it will get unmounted. And then if we looked at that etc/auto.home, we see we can mount either kevin or joe, we say read write but the NFS server's only making it read only.
And we're mounting from local host and we're going to make those directories and the exports kevin/home or joe/home be what gets mounted. So if we change directory into /home what will happen is from local host, exports kevin/home will get mounted there, so right now I'm in /home if I do an ls, there's nothing there. But if I change directory into kevin, it's there.
Kind of like magic. And if we, because we're the NFS server look at exports/kevin-home/ it's the same thing. If we change back out, we're in home, there it is. If we sleep for ten seconds, do another list, it's gone, it got unmounted after ten seconds. Okay there we go, we set up autofs and NFS.
- Partitioning storage
- Creating, mounting, and unmounting file systems
- Formatting file systems
- Making volumes with LVM
- Adding storage security
- Managing swap spaces
- Backing up and recovering Linux storage systems
- Working with networked file systems like NFS and SSHFS