Examples for mounting file systems: ---------------------------------- These examples cannot be just copy-pasted into the command prompt in Linux and then expect they will work. For exemple one can only mount the CD/DVD unit only if there is some CD/DVD inside the physical unit, also if it is described in the /etc/fstab file, otherwise it will not work a) mount /mnt/cdrom mounts the CD/DVD file system into the folder described in the /etc/fstab configuration file. If there is no description in the fstab file it will not work, instead maybe a longer version of the command might work, e.g. mount /dev/cdrom /mnt/mycd -t iso9660 b) mount -t nfs 194.102.62.42:/root/share /root/empty mounts the directory /root/share from the computer with the IP 194.102.62.42, called "the NFS server" in the local directory /root/empty from the local (client) computer. The file system type is NFS (this will work only if the NFS is configured on the NFS server computer, and if the firewall is configured to allow us the connection) c) mount -t cifs -o username=developer //blue/Staff /root/Staff mounts, using the Samba file-sharing the shared directory called Staff from the computer called blue into the local directory /root/Staff. The file system type is cifs, extra options: username=developer, which indicate which user will access the share. The computer blue existed in the past and had Windows 2000 running on it. Also developer was a valid user, Staff - a valid shared folder there, the developer user needed acces right there. We cannot try something like that now, but after a few labs we will know to configure Samba and then we can try something similar. cd /root/Staff ls -l After mounting the File System we will see in the local folder (/root/Staff) the contents of the Staff folder from the blue computer d) mount -t iso9660 -o loop yarrow-i386-disc1.iso /mnt/myiso would mount the ISO image named yarrow-i386-disc1.iso in the local directory /mnt/myiso the FS type is iso9660 extra options loop Note: the yarrow* file was downloaded from the Internet. We can do that again or create our own ISO image by transforming a folder into an ISO image mkisofs is the command for that. For the syntax search on the Internet or into the man pages (man mkisofs). Note than you will most likely need to install the package that contains the command, too. e) display the content of the file /etc/fstab which contains: - what file systems are mounted automatically, at system startup - what file systems would be mounted in the case of apparition of that respective physical media (e.g. CD/DVD unit, which will be automatically mounted when somebody inserts an CD in it) - what file systems could be mounted using simplified mount commands Read also the man page of the fstab file what can one find here NFS configuration (Network File System) -------------------------------------- 0) we need to have some packages installed, such as: rpcbind, nfs-utils Most likely you already have them installed on the 2 virtual machines ----- 1) stage 1, (on the server) ----- a) we need that on the server (the computer that exports the file system) should run some demons (resident programs) namely portmap, nfs and statd You can see if portmap is running with rpcinfo -p The other 2 function as services and will be started by using the scripts nfs and nfslock (see below) b) we start the demons, if they are not already started using the commands /etc/init.d/nfs start /etc/init.d/nfslock start Instead of "start" one can use: status - to determine if they are running restart - to restart them stop - to stop them Also the scripts are located in the /etc/init.d/ folder so one can launch them using the complete path to them, e.g. /etc/init.d/nfs or by just saying service nfs start If some shared folder needs to be provided (exported) all the time, then we should make sure the deamons start automatically next time the system starts. We can establish that by using the chkconfig command as below. Important! No need to restart the VM to complete this task! This is indeed intended for the next system start, but what can one benefit from that now? We can see with chkconfig (with no parameters) if it is ON on the 3rd runlevel, which is the one we are using on the VMs now. chkconfig nfs on chkconfig nfslock on So, to see what we have done chkconfig ----- 2) stage 2-a, (on the server) ----- We will export (share) the file systems from the source machine (that we call here the server) by declaring them in the file /etc/exports IN here we will state: - what folder(s) is exported - who can access them (those can mount the folders on their own computers) - what access rights do they have Each line in the /etc/exports file corresponds to an exported directory (folder) an looks as below. Notice, only one space charecter on the line, after the directory: directory who-has-rights(options) Options can be one or many from the list below , separated with the , (comma) character ro,rw,root_squash,no_root_squash,all_squash,anouid,anogid Most popular are ro - for read-only access and rw - for read-write access Ex: / 194.102.62.221(rw,no_root_squash) /mnt/myshare 194.102.62.0/24(rw) linux2(rw) In the first case the entire file system is exported (the / folder) and only on the pc with the IP 104.102.62.111 that can be mounted with read-write access. Search on the net for the other option In the second case the /mbt/myshare folder is shared and everybody which was an IP in the intervel 194.102.62.0 - 194.102.62.255 can import it (can mount the file system in one of his folders). Also some computer called linux2 can also import it. Linux2 computer needs to be defined in the /etc/hosts file if we want this to make sense. Most common mistake here: the student makes copy-paste of the lines in the example into the commapnd prompt and gets an error message back from the system. The lines are intended to be written in the /etc/exports with a text editor, of course! Let's say with nano. nano /etc/exports will open it in the nano text editor. Ctrl+X will save it when done editing Second most common mistake here: the student uses just the file name "exports" not the complete path "/etc/exports". Of course in teh 1st case he/she will indeed edit the exports fiel, just not the correct one, but rather one located in the current folder (usually that is /root or /home/root) So that the NFS server knows the new version of the exports fiel we just edited, we can use the exportfs command with the options -a when we wand to append some new share to the old list -r when we want to reread the file and forget the old shared files So, exportfs -r To verify if we succeeded to export correctly, we use exportfs -v There is also another file /var/lib/nfs/etab which contains the exports that are in place at a certain moment in time. The command exportfs sysnchronizes the 2 files. Look also for other options of the command in the manual! ---- 3) stage 3, (on the client) (that means the other computer!) ---- We mount temporarily (using the mount command) or permanently (by modifying the file /etc/fstab) the file system imported from the server. a) temporary mount the FS mount -t nfs 192.168.56.101:/pub /mnt/linux2_home of course this will only work when: - the server is on 192.168.56.101 - we have a share there exactly in the folder /pub, and we also have access there! - we have a local folder /mnt/linux2_home on our machine - the firewall on the server lets us access the folder. We will not configure the firewall now, rather we will disable it with the nest 2 commands: iptables -F setenforce 0 b) permanently mount the FS in the file /etc/fstab the line 192.168.56.101:/pub /mnt/linux2_home nfs defaults 0 0 will automatically determine the /pub folder exported from the server to be mounted automatically into the directory /mnt/linux2_home from the local computer Instead of the defaults option , one can use other options, like: ro, rw, suid, nosuid, and others (see the help offered by the man command) ---- 4) Stage 4 (on the server) ---- There is a problem: we cannot give on a share more rights that we have locally. So, since the default set of rights is 755 on a folder, the last 5 says everybody else has read-only access. So to grant read-write access we first need to grant it locally (on the server's shared folder). 777 is the set of rights we need on the server if we want read-write on the client! chmod 777 /pub will do that on the folder /pub from the server machine. ---- 5) Useful commands ---- a) the umount command which is the opposite of the mount command. e.g. umount /mnt/linux2_home b) the rpcinfo commadn to see what processes are running on the server rpcinfo -p c) update on-the-spot the list of exported files, without modifying the exoprts file: exportfs -a masina:share d) unexport a certain folder, without modifying the exports file exportfs -u masina:share e) exportfs -r f) umount mount-point g) the files /var/lib/nfs/etab /etc/fstab /etc/exports ----- Excercises: ----- 1) Asume we share the folder /mnt/myshare from the server and mount it then in the folder /mnt/myshare from the client What happens if we already have files in the folder from the client machine and still mount the remote FS from the server there? What happens after we unmount the foreign FS? Do the files come back? 2) Assume we want to share /home/user1/share from the server computer. What else do we need so that sharing works?