一、系統與軟件
WIN7 64bit、VirtualBox 5.0.14、CentOS 6.5、SecureCRT 7.2.3
二、使用文件夾共享需要安裝增強功能,但是安裝時無法讀取光盤iso文件
三、為了方便操作,配置靜態IP,並使用CRT連接上去(參考http://my.oschina.net/allman90/blog/294847?fromerr=CotpElUe)

[root@pc ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 //指出設備名稱 HWADDR=08:00:27:20:01:4A //硬件Mac地址 TYPE=Ethernet //網絡類型 UUID=c1d0e14c-cd39-4817-af44-37daca90c1f9 //設備UUID編號 ONBOOT=yes //是否啟動應用 NM_CONTROLLED=yes //設備是否被NetworkManager管理 BOOTPROT=static //啟動類型 dhcp|static BROADCAST=192.168.88.203 //廣播地址 IPADDR=192.168.88.111 //IP地址 NETMASK=255.255.255.0 //子網掩碼 NETWORK=192.168.88.0 //網絡地址 GATEWAY=192.168.88.254 //網關地址 DNS1=8.8.8.8 //DNS [root@pc ~]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ] [root@pc ~]# ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:57:73:2C inet addr:192.168.88.111 Bcast:192.168.88.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe57:732c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:9520 errors:0 dropped:0 overruns:0 frame:0 TX packets:5348 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12491456 (11.9 MiB) TX bytes:349639 (341.4 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@pc ~]# ping www.baidu.com PING www.baidu.com (111.13.100.92) 56(84) bytes of data. 64 bytes from 111.13.100.92: icmp_seq=1 ttl=49 time=59.1 ms 64 bytes from 111.13.100.92: icmp_seq=2 ttl=49 time=65.4 ms
四、既然無法讀取光盤,便采用FTP上傳,配置FTP(參考http://os.51cto.com/art/201408/448630.htm)

[root@pc ~]# yum -y install vsftpd // 安裝FTP ... Complete! [root@pc ~]# service vsftpd start // 啟動FTP Starting vsftpd for vsftpd: [ OK ] [root@pc ~]# vi /etc/sysconfig/iptables // 防火牆開啟21端口 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT [root@pc ~]# service iptables restart // 重啟防火牆 iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] [root@pc ~]# cat /etc/passwd | grep ftp // 新增一個賬戶ftpuser,並設置密碼 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin [root@pc ftp]# useradd -g ftp ftpuser [root@pc ftp]# passwd ftpuser Changing password for user ftpuser.
無法讀取目錄

[root@pc ~]# getsebool -a | grep ftp // 開啟外網訪問 allow_ftpd_full_access --> off ftp_home_dir --> off [root@pc ~]# setsebool -P allow_ftpd_full_access 1 [root@pc ~]# setsebool -P ftp_home_dir 1 [root@pc ~]# vi /etc/vsftpd/vsftpd.conf // 設定passive模式端口范圍 pasv_min_port=30000 pasv_max_port=30999 [root@pc ~]# service vsftpd restart // 重啟FTP [root@pc ~]# vi /etc/sysconfig/iptables // 開啟防火牆對應范圍端口 -A INPUT -m state --state NEW -m tcp -p tcp --dport 30000:30999 -j ACCEPT [root@pc ~]# service iptables restart // 重啟防火牆
正常連接上虛擬機
把VirtualBox安裝目錄下的 VBoxGuestAdditions.iso 解壓,並通過FTP客戶端filezilla上傳到虛擬機

[root@pc ~]# cd /home/ftpuser/ [root@pc ftpuser]# ll total 4 drwxr-xr-x. 6 ftpuser ftp 4096 Apr 19 22:28 VBoxGuestAdditions
五、開始安裝增強功能

[root@pc ~]# cd /home/ftpuser/VBoxGuestAdditions/ [root@pc VBoxGuestAdditions]# ll total 51296 drwxr-xr-x. 2 ftpuser ftp 4096 Apr 19 22:28 32Bit drwxr-xr-x. 2 ftpuser ftp 4096 Apr 19 22:28 64Bit -rw-r--r--. 1 ftpuser ftp 647 Apr 19 22:28 AUTORUN.INF -rw-r--r--. 1 ftpuser ftp 6909 Apr 19 22:28 autorun.sh drwxr-xr-x. 2 ftpuser ftp 4096 Apr 19 22:28 cert drwxr-xr-x. 2 ftpuser ftp 4096 Apr 19 22:28 OS2 -rw-r--r--. 1 ftpuser ftp 5519 Apr 19 22:28 runasroot.sh -rw-r--r--. 1 ftpuser ftp 7515597 Apr 19 22:28 VBoxLinuxAdditions.run -rw-r--r--. 1 ftpuser ftp 17449472 Apr 19 22:28 VBoxSolarisAdditions.pkg -rw-r--r--. 1 ftpuser ftp 16950032 Apr 19 22:28 VBoxWindowsAdditions-amd64.exe -rw-r--r--. 1 ftpuser ftp 316016 Apr 19 22:28 VBoxWindowsAdditions.exe -rw-r--r--. 1 ftpuser ftp 10245216 Apr 19 22:28 VBoxWindowsAdditions-x86.exe [root@pc VBoxGuestAdditions]# chmod +x runasroot.sh [root@pc VBoxGuestAdditions]# ./runasroot.sh Usage: runasroot.sh DESCRIPTION COMMAND [ADVICE] Attempt to execute COMMAND with root privileges, displaying DESCRIPTION if possible and displaying ADVICE if possible if no su(1)-like tool is available. [root@pc VBoxGuestAdditions]# chmod +x VBoxLinuxAdditions.run [root@pc VBoxGuestAdditions]# ./VBoxLinuxAdditions.run Verifying archive integrity... All good. Uncompressing VirtualBox 5.0.14 Guest Additions for Linux............ VirtualBox Guest Additions installer Copying additional installer modules ... Installing additional modules ... Removing existing VirtualBox non-DKMS kernel modules [ OK ] Building the VirtualBox Guest Additions kernel modules The gcc utility was not found. If the following module compilation fails then this could be the reason and you should try installing it. The headers for the current running kernel were not found. If the following module compilation fails then this could be the reason. The missing package can be probably installed with yum install kernel-devel-2.6.32-358.el6.x86_64 Building the main Guest Additions module [FAILED] (Look at /var/log/vboxadd-install.log to find out what went wrong) Doing non-kernel setup of the Guest Additions [ OK ] Installing the Window System drivers Could not find the X.Org or XFree86 Window System, skipping. [root@pc VBoxGuestAdditions]# cat /var/log/vboxadd-install.log /tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop. Creating user for the Guest Additions. Creating udev rule for the Guest Additions kernel module.
查找報錯 Building the main Guest Additions module [FAILED](參考 http://www.xuebuyuan.com/2039380.html)
[root@pc VBoxGuestAdditions]# yum -y install gcc make gcc-c++ [root@pc VBoxGuestAdditions]# yum -y install kernel [root@pc VBoxGuestAdditions]# yum -y install kernel-devel [root@pc VBoxGuestAdditions]# yum -y install kernel-headers
重啟CentOS並再次執行VBoxLinuxAdditions.run,依舊報錯(參考 http://askubuntu.com/questions/22743/how-do-i-install-guest-additions-in-a-virtualbox-vm)
[root@pc VBoxGuestAdditions]# yum update [root@pc ~]# /opt/VBoxGuestAdditions-5.0.14/uninstall.sh [root@pc ~]# /home/ftpuser/VBoxGuestAdditions/VBoxLinuxAdditions.run [root@pc ~]# cat /var/log/vboxadd-install.log /bin/sh: perl: command not found
這次變成報沒有 perl,於是 yum -y install perl 補齊
再次進行安裝

[root@pc ~]# /opt/VBoxGuestAdditions-5.0.14/uninstall.sh [root@pc ~]# /home/ftpuser/VBoxGuestAdditions/VBoxLinuxAdditions.run Verifying archive integrity... All good. Uncompressing VirtualBox 5.0.14 Guest Additions for Linux............ VirtualBox Guest Additions installer You appear to have a version of the VBoxGuestAdditions software 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 Removing existing VirtualBox non-DKMS kernel modules [ OK ] grep: /opt/VBoxGuestAdditions-*/init/*: No such file or directory Copying additional installer modules ... Installing additional modules ... Removing existing VirtualBox non-DKMS kernel modules [ OK ] Building the VirtualBox Guest Additions kernel modules Building the main Guest Additions module [ OK ] Building the shared folder support module [ OK ] Building the OpenGL support module [FAILED] (Look at /var/log/vboxadd-install.log to find out what went wrong. The module is not built but the others are.) Doing non-kernel setup of the Guest Additions [ OK ] Starting the VirtualBox Guest Additions [ OK ] Installing the Window System drivers Could not find the X.Org or XFree86 Window System, skipping.
終於成功了,其中 OpenGL 失敗是因為我的CentOS是精簡版沒有界面的!
六、設置共享
[root@pc ~]# ll /media/ total 4 drwxrwx---. 1 root vboxsf 4096 Mar 27 16:59 sf_win_www
----------------------------------2019-01-10----------------------------------
1 [root@localhost ~]# df 2 Filesystem 1K-blocks Used Available Use% Mounted on 3 /dev/mapper/VolGroup-lv_root 4 19035432 7226256 10835560 41% / 5 tmpfs 502380 0 502380 0% /dev/shm 6 /dev/sda1 487652 57642 404410 13% /boot 7 .host://www 165686344 81123004 84563340 49% /datas/htdocs 8 .host://log 165686344 81123004 84563340 49% /datas/log 9 .host://vmware 157300384 89902340 67398044 58% /datas/vmware 10 [root@localhost ~]# vmware-hgfsclient #查看共享目錄 11 www 12 vmware 13 log 14 python 15 [root@localhost ~]# mount -t vmhgfs .host:/python /datas/python #掛載 16 Error: cannot canonicalize mount point: No such file or directory 17 [root@localhost ~]# mkdir /datas/python 18 [root@localhost ~]# mount -t vmhgfs .host:/python /datas/python 19 [root@localhost ~]# df 20 Filesystem 1K-blocks Used Available Use% Mounted on 21 /dev/mapper/VolGroup-lv_root 22 19035432 7226256 10835560 41% / 23 tmpfs 502380 0 502380 0% /dev/shm 24 /dev/sda1 487652 57642 404410 13% /boot 25 .host:/www 165686344 81123004 84563340 49% /datas/htdocs 26 .host:/log 165686344 81123004 84563340 49% /datas/log 27 .host:/vmware 157300384 89902340 67398044 58% /datas/vmware 28 .host:/python 165686344 81123004 84563340 49% /datas/python 29 [root@localhost ~]# ll /datas/python/ 30 total 1 31 -rwxrwxrwx 1 root root 0 May 4 2017 1.log 32 [root@localhost ~]# vim /etc/fstab #自動掛載 33 .host:/python /datas/python vmhgfs iocharset=utf8,rw,uid=www,gid=www 0 1 34 [root@localhost ~]# init 6 35 [root@localhost ~]# df 36 Filesystem 1K-blocks Used Available Use% Mounted on 37 /dev/mapper/VolGroup-lv_root 38 19035432 7226256 10835560 41% / 39 tmpfs 502380 0 502380 0% /dev/shm 40 /dev/sda1 487652 57642 404410 13% /boot 41 .host:/www 165686344 81123004 84563340 49% /datas/htdocs 42 .host:/log 165686344 81123004 84563340 49% /datas/log 43 .host:/vmware 157300384 89902340 67398044 58% /datas/vmware 44 .host:/python 165686344 81123004 84563340 49% /datas/python
https://blog.csdn.net/qq_30309813/article/details/79830356
https://www.cnblogs.com/qiyebao/p/4484047.html