ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Virtualbox 设置虚拟机和物理机共享文件夹

2019-12-22 20:56:53  阅读:214  来源: 互联网

标签:kernel 虚拟机 VirtualBox 文件夹 Virtualbox root localhost


Virtualbox 设置虚拟机和物理机共享文件夹

概述

当我们在本地机安装好一个虚拟机后,特别是安装linux系统的朋友们,经常需要将本地机的文件传递到虚拟机中, 能实现的方式肯定是多式多样的,就本人来说,没有设置共享文件夹之前,一直都是用的sftp方式利用ssh通道传递,由于是本地网络,用得也顺手。这种方式唯一需要的就是需要下载一个好的sftp传递工具,可是有的朋友就会想,虚拟机也是建立在物理机上,为什么不能直接从物理机传递进去呢?对的,vmware 和virtualbox 虚拟机都有共享文件夹功能,直接将本地一个文件夹挂载到虚拟机中,下面介绍如何实现此过程。

由于我这里使用的是virtualbox,所以用virtualbox来演示,其他虚拟的原理是一样的,这里不做介绍。

步骤1

virtuabox建立共享文件夹

先选定需要建立共享文件夹的虚拟机,选择设置=》共享文件夹,点击右侧蓝色+号图标新建共享文件夹。

选择一个本地机文件夹作为共享文件夹,如果没有特殊权限要求,勾选固定分配项。

步骤2

添加驱动

选择存储=》控制器IDE=》添加光驱=》VBoxGuestAdditions.iso,VBoxGuestAdditions.iso光驱镜像在virtualBox的安装目录下

步骤3

挂载到系统

启动系统后执行以下命令

[root@localhost ~]# mount -t auto /dev/cdrom /mnt/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cd /mnt/cdrom/
[root@localhost cdrom]# ls
32Bit  AUTORUN.INF  cert  runasroot.sh  VBoxLinuxAdditions.run    VBoxWindowsAdditions-amd64.exe  VBoxWindowsAdditions-x86.exe
64Bit  autorun.sh   OS2   TRANS.TBL     VBoxSolarisAdditions.pkg  VBoxWindowsAdditions.exe
[root@localhost cdrom]# ls
32Bit  AUTORUN.INF  cert  runasroot.sh  VBoxLinuxAdditions.run    VBoxWindowsAdditions-amd64.exe  VBoxWindowsAdditions-x86.exe
64Bit  autorun.sh   OS2   TRANS.TBL     VBoxSolarisAdditions.pkg  VBoxWindowsAdditions.exe
[root@localhost cdrom]# ./VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........
bzip2 not found.  Please install: bzip2 tar; and try again.
[root@localhost cdrom]# yum install bzip2
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 bzip2.x86_64.0.1.0.6-13.el7 将被 安装
--> 解决依赖关系完成

...
## 这里我的centos 虚拟机缺少bzip2依赖,提示缺少什么就安装什么,安装依赖后继续执行 VBoxLinuxAdditions.run


已安装:
  bzip2.x86_64 0:1.0.6-13.el7                                                                                                                                                          

完毕!


[root@localhost cdrom]# ./VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.  This may take a while.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-1062.4.1.el7.x86_64
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.  This may take a while.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-1062.4.1.el7.x86_64
[root@localhost ~]# mkdir /local
[root@localhost ~]# mount -t vboxsf local /local
ls /local/
test
[root@localhost ~]# ls /
bin  boot  dev  etc  home  lib  lib64  local  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

# 挂载成功 /local 文件夹显示绿色
# mount -t vboxsf local(该目录为virtualbox界面创建的文件夹名称,根据自己修改) /local

标签:kernel,虚拟机,VirtualBox,文件夹,Virtualbox,root,localhost
来源: https://www.cnblogs.com/h-gallop/p/12080984.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有