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

对上面命令做下说明:

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

这里重点说下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
  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fananchong2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值