Ubuntu 虚拟机挂接 Windows 目录

Windows 共享目录

首先 Windows 下共享目录

我这里偷懒直接直接 Everyone ,也可以指定用户啥的

在这里插入图片描述

Ubuntu 挂接

挂接命令,类似如下:

sudo mount -o 'username=fananchong,password=xxxx,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,dynperm' //xx.xx.xx.xx/dep2 /home/fananchong/xxxx/gameserver/dep

对上面命令做下说明:

内容 说明
username Windows 系统的登录账号
password Windows 系统的登录密码
uid Ubuntu 系统账号的 uid 。执行 id -u 可以获得
gid Ubuntu 系统账号的 gid 。执行 id -g 可以获得
file_mode 创建文件时,设置文件权限是什么
dir_mode 创建目录时,设置目录权限是什么
dynperm Ubuntu 下可以更改文件、目录权限
//xx.xx.xx.xx/dep2 Windows 要共享的目录
/home/fananchong/xxxx/gameserver/dep Ubuntu 下挂接到哪个目录

这里重点说下dynperm
如果没有这个参数,Ubuntu 下会无法更改文件目录的权限,导致 chmod 命令执行无效
这对于 git 库下的文件会导致都有 diff 差异

设置开机启动

这里使用在/etc/rc.local里配置挂接命令
Ubuntu 默认没开启 /etc/rc.local 的功能

步骤1:查看服务是否开启

>systemctl status rc-local.service                                                                                             
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Sat 2024-01-06 02:32:46 UTC; 5h 2min ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 739 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
        CPU: 11ms

这里打印的是已开启的

步骤2:开启服务

如果没有开启,修改/lib/systemd/system/rc-local.service

在该文件内添加Install的内容。修改后,完整文件内容如下:

cat /lib/systemd/system/rc-local.service                                                                          ✔  took 1m 12s  with fananchong@myubuntu  at 07:36:33 
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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  
Alias=rc-local.service

然后设置开机启动:

sudo systemctl enable rc-local.service

步骤3:创建/etc/rc.local

sudo touch /etc/rc.local
sudo chmod +x /etc/rc.local

步骤4:设置开机启动内容

然后把刚才的 mount 命令写到/etc/rc.local

步骤5:启动服务

sudo systemctl start rc-local.service

相关推荐

  1. 小白用Windows(ssh)连接使用 ubuntu(虚拟)

    2024-01-10 21:16:02       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-10 21:16:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-10 21:16:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-10 21:16:02       82 阅读
  4. Python语言-面向对象

    2024-01-10 21:16:02       91 阅读

热门阅读

  1. 53、实战 - 手写一个全连接算法

    2024-01-10 21:16:02       55 阅读
  2. 深度解读:微信返利机器人是如何实现的?

    2024-01-10 21:16:02       60 阅读
  3. react useEffect

    2024-01-10 21:16:02       53 阅读
  4. 在 Docker 中配置 MySQL 数据库并初始化 Project 项目

    2024-01-10 21:16:02       51 阅读
  5. 盛京天海专升本咋样

    2024-01-10 21:16:02       54 阅读
  6. onreadystatechange事件详解

    2024-01-10 21:16:02       53 阅读
  7. RabbitMQ的关键概念解析

    2024-01-10 21:16:02       53 阅读
  8. 组件中使用定时器及销毁问题(vue的问题)

    2024-01-10 21:16:02       61 阅读
  9. 第九节 初始化项目

    2024-01-10 21:16:02       59 阅读
  10. 面试宝典之消息中间件面试题

    2024-01-10 21:16:02       57 阅读