Score:3

Ubuntu 22.04 mounting NAS SMB shares

bb flag

I’m relatively new to Ubuntu as I always used Linux Mint.

I wanted to change to Ubuntu because I have bought a larger monitor and wanted to use Gsnap on Gnome as a tiling assistant.

I installed Ubuntu alongside LinuxMint and Windows 11. I configured Ubuntu a bit like Linux Mint where I put my SMB shares (14x) in /etc/fstab and mounted them automatically to the mountpoints in /mnt/ It works. But it is awfully slow.

When I boot Ubuntu without the networkshares it takes 14 seconds to show the desktop. With the 14 SMB shares in /etc/fstab it takes 65 seconds before the desktop shows. When I reduce the shares to 5, the boot time is 58 seconds.

I have already looked at “systemd-analyze critical-chain” and “systemd-analyze blame” and mounting the shares takes about 200ms each. That would be three seconds for 14 shares.

What am I doing wrong? Would it not be much faster to mount the shares after Ubuntu has started? (sudo mount -a takes only a second to mount all shares) Is there a better alternative to mount NAS drives under Ubuntu?

David avatar
cn flag
Never heard of doing what you did. Here is a link you can learn how to create SMB shares. https://phoenixnap.com/kb/ubuntu-samba
tommiedepommie avatar
bb flag
Hello, maybe I didn't express myself correctly, I use the format in /etc/fstab "//<NAS>/<SHARE> /mnt/<MNT-point> cifs user=<NAME>,password=<PASSWD>,vers=2.0,iocharset=utf8,sec=ntlmsspi 0 0' I use a file smbcredentials which contains my NAS username and password.
ckhan avatar
ph flag
To clarify: your problem is that the _exact same shares_ mount correctly in both cases, but takes 5-10s to mount per share when listed in `/etc/fstab`, but are almost instantaneous when listed as `noauto` and mounted after system boot?
David avatar
cn flag
Guess I never made myself clear. That is not usually how it is done. See the link I gave you.
ckhan avatar
ph flag
@david, my understanding is that OP is looking to solve a performance issue mounting SMB shares in Linux; that is, the Ubuntu box is an SMB client, and the relevant software in Linux is cifs-utils. Your link is about setting up Samba the SMB server.
David avatar
cn flag
And it covers how to configure and set up the shares.
ckhan avatar
ph flag
Certainly does, for the server. Nothing about smbclient or cifs or performance. I was reacting your note "that's not usually how it's done". Quoting from Samba.org : https://wiki.samba.org/index.php/LinuxCIFS_utils `The in-kernel CIFS filesystem is generally the preferred method for mounting SMB/CIFS shares on Linux.`. OP's mount command looks very much like how I've seen it on other systems.
tommiedepommie avatar
bb flag
I'm talking about my QNAP Nas server and Ubuntu 22.04 client which automatically wants to connect to the shares on the server. Indeed, it's a performance issue. Without shares my system boots in 14 seconds and with SMB shares, 65 seconds. I think that's not a normal behaviour.
tommiedepommie avatar
bb flag
@ckhan, I disabled (#) the shares in /etc/fstab and then my system boots in 14 seconds.
ckhan avatar
ph flag
Can you see if `dmesg` shows any relevant output ? The only other report of your symptoms is thits: https://bbs.archlinux.org/viewtopic.php?id=248818. Possible you have something similar, multiple services blocked against each other?
tommiedepommie avatar
bb flag
@ckhan the link you gave describes exactly my problem. He also has a boot in 15 seconds without shares. I executed "systemctl list-unit-files --state=enabled" but can't find the service systemd-networkd to disable. I tried to pastebin the service list but it's under maintenance. Pfff
ckhan avatar
ph flag
It’s unlikely that your problem is exactly theirs — the poster in that thread has inadvertently enabled two competing services. But it might be something like that . We’ll need dmesg or other logs to diagnose
tommiedepommie avatar
bb flag
Hello, here are my pastebin's from services and dmesg: https://pastebin.com/trWQAr3Z : https://pastebin.com/Yh2awZZv thank you for taking a look at them. Greetings tom
ckhan avatar
ph flag
Two thoughts: 1) the log line at 36.700468 noting that time went backward might suggest that the HW clock for this system isn't UTC, and your local timezone is east of the meridian. That might also explain why it's not an issue after boot. Check out https://unix.stackexchange.com/a/600490/17683. 2) If that doesn't help, maybe the best approach is leave mounts in fstab, but mark them with mount options : `noauto,x-systemd.automount` (from https://www.reddit.com/r/archlinux/comments/p7kb7y/comment/h9kyxgo/?utm_source=share&utm_medium=web3x) so that they're automounted on first use after boot.
tommiedepommie avatar
bb flag
Hello @ckhan, YOU'RE THE BEST !!!! I read somewhere to change the timezone setting to timedatectl set-local-rtc 1 when the system is using double-boot with windows. I changed this to "timedatectl set-local-rtc 1 --adjust-system-clock" and the message 'clock jumps backwards' was resolved. But the option "noauto,x-systemd.automount" resolved my long boot time. Thank you for your help. Greetings, A very happy Ubuntu user. Tom
Organic Marble avatar
us flag
Hi, please don't put "solved" in the title. Post a proper answer and accept it.
ckhan avatar
ph flag
Thanks @OrganicMarble. tommiedpommie -- I've submitted my solution as an answer, you can accept that.
tommiedepommie avatar
bb flag
Ahh, ok. Now I understand how it works here. Thank you very much.
ckhan avatar
ph flag
@tommiedepommie: remember, as the asker, you have _two_ affordances: you can upvote the answer, but also important to _accept_ it if you believe it is the best solution to your problem. See https://stackoverflow.com/help/someone-answers#:~:text=To%20accept%20an%20answer%3A&text=To%20mark%20an%20answer%20as,the%20answer%2C%20at%20any%20time.
Score:4
ph flag

Two thoughts:

  1. The log line at 36.700468 noting that time went backward might suggest that the HW clock for this system isn't UTC, and your local timezone is east of the meridian. That might also explain why it's not an issue after boot. Check out this post for more info.

  2. Even if that doesn't help, a better approach may be to leave the mounts in fstab, but mark them with mount options : noauto,x-systemd.automount (from this Reddit comment) so that they're automounted on first use after boot. This will eliminate the boot time penalty entirely.

Score:0
ua flag

Here I'm, 2023... linux kernel 6,

and I'm still using the good old networked CIFIS disk boot.so... Let's do it.

Linux 22 kernel 6

//192.168.0.11/fotos /DATA/fotos cifs username=USER,password=CHANGEME,iocharset=utf8,file_mode=0777,dir_mode=0777,x-systemd.automount,x-systemd.idle-timeout=60
//192.168.0.11/arquivos /DATA/arquivos cifs username=USER,password=CHANGEME,iocharset=utf8,file_mode=0777,dir_mode=0777,x-systemd.automount,x-systemd.idle-timeout=60

Linux 20 kernel 5

x-systemd.automount,x-systemd.idle-timeout=1min
//192.168.0.11/fotos /DATA/fotos cifs username=USER,password=CHANGEME,iocharset=utf8,file_mode=0777,dir_mode=0777
//192.168.0.11/arquivos /DATA/arquivos cifs username=USER,password=CHANGEME,iocharset=utf8,file_mode=0777,dir_mode=0777
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.