Properly mounting network drives in Linux
After installing and configuring Kubuntu 15.10 from scratch, I have recognized a remarkable increase of my boot up time. Due to an existing Bluetooth bug, which was introduced in 15.10 and caused some delays, I have ignored the boot up delay for a while. After patching this bug, the delay still occurred. So what was the actual reason?
Boot up time analysis
Since 15.04 systemd is part of Ubuntu, which provides a built-in boot-charting. Systemd-analyze is used to inspect system start-up. Running
sudo systemd-analyze plot > bootchart.svg from terminal creates in a timely manner a graphical output of your last system boot-up.
Due to the large time line I had to shrink the above graphic. The horizontal red bar above remote-fs.target belongs to sys-devices-virtual-net-vmnet8.device. Looking at this output shows me that the delay is either caused by a virtual device of VMware Player or the mysterious remote-fs.target. I had a gut feeling, so I started looking at the last-named one. Running
systemctl list-unit-files | grep remote-fs.target shows that this is an enabled unit of systemd. Based on the used name, I proceeded on the assumption that it has something to do with remote file systems.
To get more details
systemctl list-dependencies remote-fs.target is necessary, which shows a bit more info about this unit.
Bingo! I remember that after installing my system, I have updated
/etc/fstab to automatically mount an NFS share. Uncommenting this line in /etc/fstab and repeating the bootchart analysis showed a significant difference. The new boot-up time took around 11s instead of 100s.
Mounting network shares on demand
An alternative to mounting devices during boot-up is to mount them only when you need them. A program called Autofs makes this possible. Install it with
sudo apt-get install autofs and edit
/etc/auto.master. Insert on top of this file the following line:
/mnt/nfs /etc/auto.network --ghost
This will mount the remote network drive into /mnt/nfs. Create the folder /mnt/nfs and the file /etc/auto.network, which is referenced above. Add each NFS drive you want to mount into a single line.
MyShare -rsize=32768,wsize=32768,intr,tcp,timeo=300,rw,user 192.168.1.2:/volume1/MyShare
Using the –ghost parameter inside /etc/auto.master will create ghost folders e.g. /mnt/nfs/MyShare. Entering these ghost folders by terminal or using a graphical file browser, will lead to an auto mount in the background. The mounted shares will be automatically unmounted if they are not in use and a specific time has passed.