Previously, I wrote an article about how macOS achieves mounting shared SMB folders on boot (see:Tips and Tricks Series: macOS Automatically Mounts SMB Shared Network Disks on Boot ), and this article will briefly explain how the Debian 12 system achieves mounting SMB folders on boot.
First, install the required components:
apt-get install cifs-utils
apt install samba-client
After installation, you can use the following command to verify whether you can log in to the corresponding shared device, such as a NAS:
smbclient -L your-ip -U 用户名
Then create the mount directory:
mkdir /mnt/share
Mount the shared directory to the /mnt/share directory created earlier:
mount -o username=账号,password=密码 //your-ip/共享目录 /mnt/share
Note: If the Debian 12 here is an LXC (Linux container), the following error may be reported:
mount error(1): Operation not permitted lxc
This indicates that the LXC is an unprivileged container. Therefore, if you want to use the method in this article, it needs to be a privileged LXC. If it is not a privileged container, there are other ways to achieve this, which I will cover in another article in the future.
You can use thedf -hcommand to check if the mount was successful.
To set it to automatically mount on boot, you need to edit theetc/fstabfile:
vim /etc/fstab
Then add the following configuration to the last line of the file, save, and exit:
//your-ip/共享目录 /mnt/share cifs defaults,username=账号,password=密码
Finally,rebootand then usedf -hto check if the mount has taken effect.