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) -------------------------------------- The documentation is based on the Server World tutorial of configuring NFS Server and client. See refferences 1) and 2) However, it is not completely as there. 0) we need to have some packages installed, such as: nfs-kernel-server (on the server) nfs-common (on the client) ----- 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 si 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) to we start the demons, if they are not already started using the commands To do so we can use one (recomended b2 or b3) of the following: b1) start the servie using the scripts from the folder /etc/initd/ sudo /etc/init.d/nfs-kernel-server start b2) start the service using the service command sudo service nfs-kernel-service start b3) start the service using systemctl sudo systemctl start nfs-kernel-server Be aware that you only need one of the versions b1 - b3), but if several are used the service, already started will not be started again. So, no error if you start it twice Instead of "start" one can use: status - to determine if the service is running restart - to restart the service stop - to stop the service Notice that I have used "the service" and not "the server". This is because what we are starting or stopping are services, the commands similar to those from b2) and b3) will be used in the future for other services as well. So, "service" is a more general name for what we are managing now. The nfs-kernel-server will be running as a service. So, to make it start automatically after reboot we need to take some aditional steps (similar for all the services) Note about b1): the folder /etc/initd/ contains scripts for all the services installed. But because it is harder to write all the times the path we better use the versions from b2) or b3) I'd preffer b2) for compatibility with old versions of Linux, but in our days b3) is the one recommended, so we should use systemctl to manage the services. To make the service start automatically after reboot sudo systemctl enable nfs-kernel-server To check if a service is enabled (verify that the above command worked) sudo systemctl is-enabled nfs-kernel-server To check what is started now sudo service --status-all This last command will show all the services in the following manner: - with a "+" sign alongside with it in the case that the service is now running, - with a "-" sign if the service is NOT running now ----- 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) Where: directory - in the directory that we will share who-has-rights - can be: the IP OR IP/number OR IP/subnet_mask OR name_of_computer OR list of the above elements, separated by "," (comma) OR * - for everybody (the entire internet) 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 options are ro - for read-only access and rw - for read-write access no_subtree_check - to eliminate subtree check, it is said that some errors might appear if this is enabled root_squash or no_root_squash - the 1st one is default. The second one makes the root from the original computer (the server) also remain root on the mounted filesystem 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 /mnt/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! Stage 2.5 (on the server) Enable NFS through the firewall sudo ufw allow from 192.168.76.0/24 to any port nfs Note that the IP addresses allowed are the ones from my laptop, so, maybe 76 on your PC/laptop is another number. The above command allows for the entire subset of IPs between: 192.168.76.0 - 192.168.76.255 ---- 3) stage 3, (on the client) (that means the other computer!) ---- For the client we need to have there installed the package nfs-common We can, of course do that with sudo apt install -y nfs-common 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.76.7:/pub /mnt/linux2_home of course this will only work when: - the server is on 192.168.76.7 - 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. Don't do this until checked!!!!! 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 command 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? References: ------------ 1) Configuring the NFS Server (for Ubuntu 20.04) https://www.server-world.info/en/note?os=Ubuntu_20.04&p=nfs&f=1 2)Configuring the NFS Client (for Ubuntu 20.04) LTS) https://www.server-world.info/en/note?os=Ubuntu_20.04&p=nfs&f=2