Ubuntu添加网络映射路径

参考资料

linux挂在阿里云盘(webdav协议)给服务器扩容、备份数据等_davfs2-CSDN博客

Linux将WebDAV为本地磁盘 - 夏日冰菓 (lincloud.pro)

systemd系统开机运行rc.local_rc-local.service: failed to execute command: exec -CSDN博客

系统版本:

shell 复制代码
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-105-generic x86_64)

现有webdev地址:http://192.168.3.2:5005/185xxxx/very-mount/linuxServer,以及webdev账号密码

欲挂载在linux的\home\kono707da\nas-mount路径下

  1. 安装davfs2

    shell 复制代码
    apt-get install davfs2
  2. 挂载网络磁盘

    shell 复制代码
    sudo mount -t davfs http://192.168.3.2:5005/185xxxx/very-mount/linuxServer /home/kono707da/nas-mount
  3. 输入账密

  4. 配置开机自启

    1. 修改use_locks

      shell 复制代码
      sudo vim /etc/davfs2/davfs2.conf 

      # use_locks 1改为use_locks 0

    2. 修改secrets文件,添加账号信息

      shell 复制代码
      vim /etc/davfs2/secrets
    3. 文件底部添加账号信息

      shell 复制代码
      http://192.168.3.2:5005/185xxxx/very-mount/linuxServer myAccount myPassword
    4. 配置rc-local

      1. 检查rc-local状态

        复制代码
        sudo systemctl status rc-local

        可能的报错:

        复制代码
        ● rc-local.service - /etc/rc.local Compatibility
           Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
          Drop-In: /lib/systemd/system/rc-local.service.d
                   └─debian.conf
           Active: failed (Result: exit-code) since Thu 2018-11-01 10:56:36 CST; 1h 59min ago
             Docs: man:systemd-rc-local-generator(8)
          Process: 1961 ExecStart=/etc/rc.local start (code=exited, status=203/EXEC)
        
        11月 01 10:56:36 ubuntu systemd[1]: Starting /etc/rc.local Compatibility...
        11月 01 10:56:36 ubuntu systemd[1961]: rc-local.service: Failed to execute command: Exec format error
        11月 01 10:56:36 ubuntu systemd[1961]: rc-local.service: Failed at step EXEC spawning /etc/rc.local: Exec format e
        11月 01 10:56:36 ubuntu systemd[1]: rc-local.service: Control process exited, code=exited status=203
        11月 01 10:56:36 ubuntu systemd[1]: rc-local.service: Failed with result 'exit-code'.
        11月 01 10:56:36 ubuntu systemd[1]: Failed to start /etc/rc.local Compatibility.
      2. 尝试开启rc-local

        复制代码
        sudo systemctl enable rc-local

        可能的报错:

        复制代码
        xugaoxiang@ubuntu:~$ sudo systemctl enable rc-local
        The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
        settings in the [Install] section, and DefaultInstance for template units).
        This means they are not meant to be enabled using systemctl.
        Possible reasons for having this kind of units are:
        1) A unit may be statically enabled by being symlinked from another unit's
           .wants/ or .requires/ directory.
        2) A unit's purpose may be to act as a helper for some other unit which has
           a requirement dependency on it.
        3) A unit may be started when needed via activation (socket, path, timer,
           D-Bus, udev, scripted systemctl call, ...).
        4) In case of template units, the unit is meant to be enabled with some
           instance name specified.
      3. 修复问题:The unit files have no installation config

        复制一份rc-local文件到目标目录

        复制代码
        sudo cp /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

        修改rc-local.service文件,加入[Install]的内容

        复制代码
        #  SPDX-License-Identifier: LGPL-2.1+
        #
        #  This file is part of systemd.
        #
        #  systemd is free software; you can redistribute it and/or modify it
        #  under the terms of the GNU Lesser General Public License as published by
        #  the Free Software Foundation; either version 2.1 of the License, or
        #  (at your option) any later version.
        
        # This unit gets pulled automatically into multi-user.target by
        # systemd-rc-local-generator if /etc/rc.local is executable.
        [Unit]
        Description=/etc/rc.local Compatibility
        Documentation=man:systemd-rc-local-generator(8)
        ConditionFileIsExecutable=/etc/rc.local
        After=network.target
        
        [Service]
        Type=forking
        ExecStart=/etc/rc.local start
        TimeoutSec=0
        RemainAfterExit=yes
        GuessMainPID=no
        
        [Install]
        WantedBy=multi-user.target
    5. 创建/etc/rc.local文件,输入开机运行脚本

      复制代码
      #!/bin/bash
      
      mount -t davfs http://192.168.3.2:5005/185xxxx/very-mount/linuxServer /home/kono707da/nas-mount
    6. 重启即可自动挂载。

  5. 测试

    输入df -h检查服务是否自启动

相关推荐
牛奶咖啡1336 分钟前
从零到一使用Linux+Nginx+MySQL+PHP搭建的Web网站服务器架构环境——LNMP(上)
linux·lnmp·ngnix的源码安装部署·mysql的二进制文件安装部署·php源码的安装部署·记录并解决安装php的各种问题
Yuki’1 小时前
网络编程---UDP
c语言·网络·网络协议·udp
鲸屿1951 小时前
python之socket网络编程
开发语言·网络·python
软件测试很重要1 小时前
UOS20系统安装与 SSH/XRDP 远程访问功能配置指南
linux·运维·ssh
天天年年天天。1 小时前
TCP/IP、HTTP 和 HTTPS简介
网络
对你无可奈何2 小时前
关于Ubuntu的 update造成的内核升级
运维·服务器·ubuntu
想睡hhh2 小时前
网络原理——传输层协议UDP
网络·网络协议·udp
GanGuaGua2 小时前
Linux系统:线程的互斥和安全
linux·运维·服务器·c语言·c++·安全
lsnm2 小时前
【LINUX网络】IP——网络层
linux·服务器·网络·c++·网络协议·tcp/ip
不掰手腕3 小时前
在UnionTech OS Server 20 (统信UOS服务器版) 上离线安装PostgreSQL (pgsql) 数据库
linux·数据库·postgresql