文档章节

【原创】Mac 工作协同之文件共享问题

摩云飞
 摩云飞
发布于 2016/07/06 08:47
字数 1686
阅读 177
收藏 0

本文讨论的是共享问题针对 Mac 和 VirtualBox 之间的文件共享;

众所周知,跨系统文件共享问题有几种解决办法:

  • 通过 samba 协议解决
  • 通过 Web 服务解决
  • 通过 ftp 类协议解决

本文针对另外一种方法进行说明,即 Guest Additions ;


以下内容部分参考自:《How to install VirtualBox Guest Additions for Linux

------

下面内容假设你已经基于 vagrant + VirtualBox + Ubuntu 成功搭建起了虚拟机系统;

a.下载对应 VirtualBox 版本的 guest additions

vagrant@vagrant-ubuntu-trusty:~/workspace/WGET$ wget http://download.virtualbox.org/virtualbox/5.0.20/VBoxGuestAdditions_5.0.20.iso

b.安装必要的软件包

vagrant@vagrant-ubuntu-trusty:~/workspace/WGET$ sudo apt-get install dkms gcc

c.挂载 guest additions 对应的 ISO 文件

vagrant@vagrant-ubuntu-trusty:~/workspace/WGET$ sudo mount -o loop VBoxGuestAdditions_5.0.20.iso /mnt
mount: block device /home/vagrant/workspace/WGET/VBoxGuestAdditions_5.0.20.iso is write-protected, mounting read-only

查看挂载情况

vagrant@vagrant-ubuntu-trusty:~/workspace/WGET$ mount
…
/home/vagrant/workspace/WGET/VBoxGuestAdditions_5.0.20.iso on /mnt type iso9660 (ro)
vagrant@vagrant-ubuntu-trusty:~/workspace/WGET$ 

d.运行脚本进行安装

vagrant@vagrant-ubuntu-trusty:~/workspace/WGET$ cd /mnt
vagrant@vagrant-ubuntu-trusty:/mnt$ sudo ./VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.20 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
Starting the VirtualBox Guest AdditionsInstalling the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.

 ...done.

vagrant@vagrant-ubuntu-trusty:/mnt$ 

e.查看安装成功后,内核模块中增加的和 vbox 相关的内容

vagrant@vagrant-ubuntu-trusty:/mnt$ lsmod | grep vbox
vboxvideo              45696  1 
ttm                    85115  1 vboxvideo
drm_kms_helper         52758  1 vboxvideo
drm                   302817  3 ttm,drm_kms_helper,vboxvideo
syscopyarea            12529  1 vboxvideo
sysfillrect            12701  1 vboxvideo
sysimgblt              12640  1 vboxvideo
vboxsf                 43802  0 
vboxguest             276728  3 vboxsf,vboxvideo

vagrant@vagrant-ubuntu-trusty:/mnt$ 

------

上面给出的一切顺利的情况下,你能够看到的安装过程~~

然而,实际操作中你可能会遇以下情况:

a.针对 lucid64.box ,即使 guest additions 版本不一致也可以提供文件共享功能

sunfeideMacBook-Pro:lucid64 sunfei$ vagrant reload

==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of    -- 这里可以看到存在版本不一致问题
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 5.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/sunfei/workspace/vagrant/lucid64                -- 但依然能够成功挂载共享目录
    default: /vagrant_data => /Users/sunfei/workspace/vagrant/lucid64/data      -- 但依然能够成功挂载共享目录
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

sunfeideMacBook-Pro:lucid64 sunfei$ 

b.针对 ubuntu-14.04-amd64.box 的情况,则必须安装正确版本的 guest additions 才能共享文件

sunfeideMacBook-Pro:ubuntu-14.04-amd64 sunfei$ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu-14.04-amd64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: ubuntu-1404-amd64_default_1465201090522_12444
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest  - 这里看到当前 box 未提供 guest additions
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: 
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/sunfei/workspace/vagrant/ubuntu-14.04-amd64
Failed to mount folders in Linux guest. This is usually because       - 这里会看到共享文件夹挂载失败
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:
stdin: is not a tty
mount: unknown filesystem type 'vboxsf'

sunfeideMacBook-Pro:ubuntu-14.04-amd64 sunfei$ 

c.针对 ubuntu-14.04-amd64.box 安装完 guest additions 的情况

sunfeideMacBook-Pro:ubuntu-14.04-amd64 sunfei$ vagrant reload

==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...                  — 安装后,这里不再出现其他信息
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...

    default: /vagrant => /Users/sunfei/workspace/vagrant/ubuntu-14.04-amd64   - 根据配置文件成功挂载共享目录
    default: /vagrant_data => /Users/sunfei/workspace/vagrant/ubuntu-14.04-amd64/data

sunfeideMacBook-Pro:ubuntu-14.04-amd64 sunfei$ 

此时,登录到虚拟机系统中可以看到

sunfeideMacBook-Pro:ubuntu-14.04-amd64 sunfei$ vagrant ssh
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

Last login: Mon Jun  6 09:05:32 2016 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty:~$ 
vagrant@vagrant-ubuntu-trusty:~$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
vagrant on /vagrant type vboxsf (uid=1000,gid=1000,rw)      — 共享目录成功挂载
vagrant_data on /vagrant_data type vboxsf (uid=1000,gid=1000,rw)     — 共享目录成功挂载

vagrant@vagrant-ubuntu-trusty:~$ 

 

补充:Guest Additions 除了能够解决文件共享问题外,还能解决一些其它宿主机和虚拟机之间的问题,详细内容可以查阅相关资料~

 

© 著作权归作者所有

摩云飞
粉丝 375
博文 534
码字总数 952694
作品 0
徐汇
程序员
私信 提问
苹果发布 Mac OS X 10.10.3,拍照更方便了

苹果发布 Mac OS X Yosemite 10.10.3 ,编译版本号为 14D130a,用户可通过 App Store 的“更新”选项卡,免费更新此版本。 新增功能: 增强了照片中“按钮”功能,如:提供了简单的自动修复功...

oschina
2015/04/09
5.4K
24
Python开发文件分享系统,让协同工作变得简单!

在工作中,大家应该都遇到过这类问题:一项工作需要多人配合协调来完成,或者个人的工作内容会影响整个团队等问题,这个时候,能及时记录与分享个人的工作就显得尤为重要。也许你可以微信、Q...

妄心xyx
03/08
0
0
Mobox多人共同在线文档协同编辑的技术实现

问题概述 企业日常经营中经常会出现多个部门及人员共同服务于一个项目的情况,往往需要文件反复传输,传输过程中经常会出现文件丢失的情况,并且使传输成本增高。跨地域文档协同编辑则更难,...

APM项目管理
2016/11/02
0
0
TCP/IP协议族-四层网络模型(真正的实现不是7层)

TCP/IP分层模型(TCP/IP Layening Model)被称作因特网分层模型(Internet Layering Model)、因特网参考模型(Internet Reference Model)。图表示了TCP/IP分层模型的四层。 TCP/IP协议被组...

疯狂的艺术家
2012/03/19
2.1K
0
Office 2016 正式发布!新功能眼花缭乱

Windows 10 发布两个月后,微软旗下的另一款支柱产品终于迎来了最新版,Office 2016 正式发布了! 在此之前,微软已经先后推出了面向苹果平台的 Office 2016 for Mac、Windows 10 通用版的 ...

oschina
2015/09/23
13.7K
56

没有更多内容

加载失败,请刷新页面

加载更多

手持式人证核验设备助力国家安全系统

手持式人证核验设备,是针对公共安全领域的移动化身份核验、追逃等需求推出的手持式一体化设备。其特点是具备人员信息采集、存储和比对功能,将采集到的人脸信息与居民身份证芯片中的人脸信息...

非思丸智能FaceTo
8分钟前
2
0
好程序员web前端教程分享JavaScript简写方法

今天好程序员web前端教程为大家分享JavaScript简写方法,小伙伴们快来看一看吧。 1.三元操作符 当想写if...else语句时,使用三元操作符来代替。 constx =20; let answer; if(x >10) { answer...

好程序员官网
12分钟前
3
0
PHP面试题2019年小米工程师面试题和答案解析

一、单选题(共29题,每题5分) 1.PHP面向对象方法重写描述错误的是? A、子类必须继承父类 B、子类可以重写父类已有方法 C、重写之后子类会调用父类方法 D、子类也可以具有与父类同名的属性...

一个PHP程序媛
15分钟前
2
0
K8s 从懵圈到熟练 – 镜像拉取这件小事

导读:相比 K8s 集群的其他功能,私有镜像的自动拉取,看起来可能是比较简单的。而镜像拉取失败,大多数情况下都和权限有关。所以,在处理相关问题的时候,我们往往会轻松的说:这问题很简单...

Mr_zebra
16分钟前
3
0
分布式锁简单入门以及实现方法

学过Java多线程的应该都知道什么是锁,没学过的也不用担心,Java中的锁可以简单的理解为多线程情况下访问临界资源的一种线程同步机制。 在学习或者使用Java的过程中进程会遇到各种各样的锁的...

yanlijun_java
19分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部