VirtualBox虚拟机安装增强工具及配置共享文件夹

一、系统环境及概述

1、概述

VirtualBox虚拟机安装好linux系统后,需要安装增强工具(VBoxGuestAdditions),增强工具用于鼠标自由切换,配置共享文件夹等辅助功能

2、虚拟机系统环境

内核:3.10.0-693.e17.x86_64

发行版:CentOS 7.4

[root@localhost /]# cat /proc/version
Linux version 3.10.0-693.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017
[root@localhost /]# cat /etc/system-release
CentOS Linux release 7.4.1708 (Core)
[root@localhost /]# uname -r
3.10.0-693.el7.x86_64
二、安装VBoxGuestAdditions

1、虚拟机加载 VBoxGuestAdditions.iso 镜像:

正常启动虚拟机系统,选择设备-分配光驱-VBoxGuestAdditions.iso

2、更新系统内核kernel,并安装kernel-devel和gcc,注意kernel-devel工具要跟系统kernel版本一致

[root@localhost /]# yum update kernel
[root@localhost /]# yum install kernel-devel gcc
查看版本:

[root@localhost /]# yum list grep|kernel-devel
[root@localhost /]# rpm -qa kernel-devel
安装结束,重启 reboot

3、手动挂载 VBoxGuestAdditions.iso镜像

[root@localhost /]# ls /dev/cdrom
/dev/cdrom
[root@localhost /]# mount /dev/cdrom /mnt/cdrom
mount: 挂载点 /mnt/cdrom 不存在
[root@localhost /]# mkdir /mnt/cdrom
[root@localhost /]# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载

4、运行安装脚本

[root@localhost cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.20 Guest Additions for Linux...........
VirtualBox Guest Additions installer
Copying additional installer modules ...
./install.sh:行365: bzip2: 未找到命令
tar: 它似乎不像是一个 tar 归档文件
tar: 由于前次错误,将以上次的错误状态退出
./install.sh:行378: bzip2: 未找到命令
tar: 它似乎不像是一个 tar 归档文件
tar: 由于前次错误,将以上次的错误状态退出
这里发现错误,缺少bzip2工具,先安装bzip2

[root@localhost cdrom]# yum install bzip2
然后再次运行脚本

[root@localhost cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.1.20 Guest Additions for Linux...........
VirtualBox Guest Additions installer
You appear to have a version of the VirtualBox Guest Additions
on your system which was installed from a different source or using a
different type of installer.  If you installed it from a package from your
Linux distribution or if it is a default part of the system then we strongly
recommend that you cancel this installation and remove it properly before
installing this version.  If this is simply an older or a damaged
installation you may safely proceed.

Do you wish to continue anyway? [yes or no]
yes
Copying additional installer modules ...
Installing additional modules ...
vboxadd.sh: Starting the VirtualBox Guest Additions.
安装成功!

5、设置共享文件夹

目标:将 E:\wamp\www 共享到 虚拟机系统 /VirtualBox/www

先创建 /VirtualBox/www

在VirtualBox虚拟机界面,当前虚拟机上点右键-设置-共享文件夹

如图设置:

VirtualBox虚拟机安装增强工具及配置共享文件夹_第1张图片

虚拟机执行挂载共享文件夹命令:mount -t vboxsf www /VirtualBox/www

发生错误:

[root@localhost /]# mount -t vboxsf www /VirtualBox/www
mount: 文件系统类型错误、选项错误、www 上有坏超级块、
       缺少代码页或助手程序,或其他错误

       有些情况下在 syslog 中可以找到一些有用信息- 请尝试
       dmesg | tail  这样的命令看看。
[root@localhost /]# dmesg | tail
[  108.896572] ISO 9660 Extensions: Microsoft Joliet Level 3
[  108.939100] ISO 9660 Extensions: RRIP_1991A
[  609.110175] vboxguest: loading out-of-tree module taints kernel.
[  609.110324] vboxguest: module verification failed: signature and/or required key missing - tainting kernel
[  609.125499] vgdrvHeartbeatInit: Setting up heartbeat to trigger every 2000 milliseconds
[  609.125579] input: Unspecified device as /devices/pci0000:00/0000:00:04.0/input/input6
[  609.127462] vboxguest: misc device minor 58, IRQ 20, I/O port d020, MMIO at 00000000f0000000 (size 0x400000)
[  609.127483] vboxguest: Successfully loaded version 5.1.20 (interface 0x00010004)
[  609.143392] vboxsf: Successfully loaded version 5.1.20 (interface 0x00010004)
[ 1265.165626] sf_read_super_aux err=-22
最后一条,这里的错误原因:/sbin下的mount.vboxsf 坏掉了,而我们刚才安装的位置在 /opt 下,删掉坏的做一个软链即可

[root@localhost /]# cd /sbin
[root@localhost sbin]# rm mount.vboxsf
[root@localhost sbin]# ln -s /opt/VBoxGuestAdditions-5.1.20/lib/VBoxGuestAdditions/mount.vboxsf
[root@localhost sbin]# mount -t vboxsf www /VirtualBox/www
挂载共享文件夹成功!

6、开机自动挂载共享文件夹

目前每次开机都需要手动挂载一遍,为方便我们做一个开机脚本,自动挂载

CentOS的开机启动脚本位置:/etc/rc.d/rc.local

可以直接在rc.local中编写,也可以单独写一个文件,在rc.local中运行,这里单独写一个脚本 VirtualBox.sh

[root@localhost rc.d]# touch VirtualBox.sh
[root@localhost rc.d]# vi VirtualBox.sh
[root@localhost rc.d]# cat VirtualBox.sh
#!/bin/bash
mount -t vboxsf www /VirtualBox/www
然后添加到rc.local启动文件中:

[root@localhost rc.d]# vi rc.local
/etc/rc.d/VirtualBox.sh
最后修改权限:

由于CentOS7.4中 rc.local 默认权限已经被降低,所以这里加上运行权限

[root@localhost rc.d]# chmod +x rc.local VirtualBox.sh

再次重启,查看,已经可以自动挂载共享文件夹~!

完成



你可能感兴趣的:(Other)