Ubuntu添加网络映射路径

发布于:2024-05-11 ⋅ 阅读:(65) ⋅ 点赞:(0)

参考资料

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

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

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

系统版本:

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

    apt-get install davfs2
    
  2. 挂载网络磁盘

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

  4. 配置开机自启

    1. 修改use_locks

      sudo vim /etc/davfs2/davfs2.conf 
      

      # use_locks 1改为use_locks 0

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

      vim /etc/davfs2/secrets
      
    3. 文件底部添加账号信息

      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检查服务是否自启动

    在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到