Oracle VM VirtualBox技巧

@date:2015-12-30 18:40:00

配置文件 #

Linux 虚拟机配置文件分为两处。

windows下:
1、用户名/.VirtualBox/
这里面有2个配置文件:
VirtualBox.xml 和 VirtualBox.xml-prev. 后面一个是备份文件, 可以不用管他, 前面一个我们可以看看里面的内容:

<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE.
** If you make changes to this file while any VirtualBox related application
** is running, your changes will be overwritten later, without taking effect.
** Use VBoxManage or the VirtualBox Manager GUI to make changes.
-->
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.12-windows">
  <Global>
    <ExtraData>
      <ExtraDataItem name="GUI/DetailsPageBoxes" value="general,system,preview,display,storage,audio,network,usb,sharedFolders,description"/>
      <ExtraDataItem name="GUI/GroupDefinitions/" value="m=83d5321d-32f6-438b-b81c-3e336ccc1460,m=ef9627ae-2637-4f90-a9e9-1423fbdccbd1"/>
      <ExtraDataItem name="GUI/HostScreenSaverDisabled" value="false"/>
      <ExtraDataItem name="GUI/Input/AutoCapture" value="true"/>
      <ExtraDataItem name="GUI/Input/HostKeyCombination" value="163"/>
      <ExtraDataItem name="GUI/LastItemSelected" value="m=xp"/>
      <ExtraDataItem name="GUI/LastWindowPosition" value="298,89,770,550"/>
      <ExtraDataItem name="GUI/SplitterSizes" value="192,573"/>
      <ExtraDataItem name="GUI/SuppressMessages" value="confirmInputCapture"/>
    </ExtraData>
    <MachineRegistry>
      <MachineEntry uuid="{ef9627ae-2637-4f90-a9e9-1423fbdccbd1}" src="D:\VirtualBox VMs\xp\xp.vbox"/>
      <MachineEntry uuid="{55a1a18a-0cb6-4238-bcdb-2df5d647e255}" src="D:\VirtualBox VMs\centos\centos.vbox"/>
    </MachineRegistry>
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <NetserviceRegistry>
      <DHCPServers>
        <DHCPServer networkName="HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter" IPAddress="192.168.56.100" networkMask="255.255.255.0" lowerIP="192.168.56.101" upperIP="192.168.56.254" enabled="1"/>
      </DHCPServers>
    </NetserviceRegistry>
    <SystemProperties defaultMachineFolder="D:\VirtualBox VMs" defaultHardDiskFormat="VDI" VRDEAuthLibrary="VBoxAuth" webServiceAuthLibrary="VBoxAuth" LogHistoryCount="3" exclusiveHwVirt="false"/>
    <USBDeviceFilters/>
  </Global>
</VirtualBox>

注意此处定义虚拟机文件uuid及所在位置:

<MachineRegistry>
  <MachineEntry uuid="{ef9627ae-2637-4f90-a9e9-1423fbdccbd1}" src="D:\VirtualBox VMs\xp\xp.vbox"/>
  <MachineEntry uuid="{55a1a18a-0cb6-4238-bcdb-2df5d647e255}" src="D:\VirtualBox VMs\centos\centos.vbox"/>
</MachineRegistry>

其中uuid来自于src对应文件.vbox里面的:

<Machine uuid="{55a1a18a-0cb6-4238-bcdb-2df5d647e255}" name="centos" OSType="RedHat" snapshotFolder="Snapshots" lastStateChange="2015-12-02T14:16:08Z">

如果不小心重新重新安装VirtualBox或者删除了VirtualBox的配置文件,只要虚拟机没有删除(如.vbox、.vdi文件),可以重新安装虚拟机后仿照MachineRegistry里MachineEntry添加一行。注意uuid不错,必须和.vbox里的一致。

2、虚拟机目录里的.vbox文件
这是个文本文件,可以直接编辑。例如:

<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE.
** If you make changes to this file while any VirtualBox related application
** is running, your changes will be overwritten later, without taking effect.
** Use VBoxManage or the VirtualBox Manager GUI to make changes.
-->
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.15-windows">
  <Machine uuid="{55a1a18a-0cb6-4238-bcdb-2df5d647e255}" name="centos" OSType="RedHat" snapshotFolder="Snapshots" lastStateChange="2015-12-02T14:16:08Z">
    <MediaRegistry>
      <HardDisks>
        <HardDisk uuid="{e1e7ffe5-9b7c-4c94-932f-72b4810a274f}" location="centos-disk2_1.vmdk" format="VMDK" type="Normal"/>
        <HardDisk uuid="{b914d8b0-b772-427b-a840-cadc1cf0391a}" location="data.vdi" format="VDI" type="Normal"/>
      </HardDisks>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="PowerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="720,400"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="8,30,720,445"/>
      <ExtraDataItem name="GUI/RestrictedRuntimeDevicesMenuActions" value="HardDrives"/>
      <ExtraDataItem name="GUI/RestrictedRuntimeMachineMenuActions" value="SaveState,PowerOff"/>
      <ExtraDataItem name="GUI/StatusBar/IndicatorOrder" value="HardDisks,OpticalDisks,FloppyDisks,Network,USB,SharedFolders,Display,VideoCapture,Features,Mouse,Keyboard"/>
    </ExtraData>
    <Hardware version="2">
      <CPU count="1" hotplug="false">
        <HardwareVirtEx enabled="true"/>
        <HardwareVirtExNestedPaging enabled="true"/>
        <HardwareVirtExVPID enabled="true"/>
        <HardwareVirtExUX enabled="true"/>
        <PAE enabled="true"/>
        <HardwareVirtExLargePages enabled="true"/>
        <HardwareVirtForce enabled="false"/>
      </CPU>
      <Memory RAMSize="512" PageFusion="false"/>
      <HID Pointing="PS2Mouse" Keyboard="PS2Keyboard"/>
      <HPET enabled="false"/>
      <Chipset type="PIIX3"/>
      <Boot>
        <Order position="1" device="HardDisk"/>
        <Order position="2" device="DVD"/>
        <Order position="3" device="None"/>
        <Order position="4" device="None"/>
      </Boot>
      <Display VRAMSize="12" monitorCount="1" accelerate3D="false" accelerate2DVideo="false"/>
      <VideoCapture enabled="false" screens="18446744073709551615" horzRes="1024" vertRes="768" rate="512" fps="25" maxTime="0" maxSize="0"/>
      <RemoteDisplay enabled="false" authType="Null" authTimeout="5000"/>
      <BIOS>
        <ACPI enabled="true"/>
        <IOAPIC enabled="false"/>
        <Logo fadeIn="true" fadeOut="true" displayTime="0"/>
        <BootMenu mode="MessageAndMenu"/>
        <TimeOffset value="0"/>
        <PXEDebug enabled="false"/>
      </BIOS>
      <USB>
        <Controllers>
          <Controller name="OHCI" type="OHCI"/>
          <Controller name="EHCI" type="EHCI"/>
        </Controllers>
        <DeviceFilters/>
      </USB>
      <Network>
        <Adapter slot="0" enabled="true" MACAddress="080027F9C460" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <InternalNetwork name="intnet"/>
            <NATNetwork name="NatNetwork"/>
          </DisabledModes>
          <NAT>
            <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
            <Alias logging="false" proxy-only="false" use-same-ports="false"/>
          </NAT>
        </Adapter>
        <Adapter slot="1" enabled="true" MACAddress="080027597536" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
            <InternalNetwork name="intnet"/>
            <NATNetwork name="NatNetwork"/>
          </DisabledModes>
          <BridgedInterface name="Microsoft Loopback Adapter"/>
        </Adapter>
        <Adapter slot="2" enabled="true" MACAddress="080027E33818" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
            <InternalNetwork name="intnet"/>
            <NATNetwork name="NatNetwork"/>
          </DisabledModes>
          <BridgedInterface name="Broadcom 802.11n &#x7F51;&#x7EDC;&#x9002;&#x914D;&#x5668;"/>
        </Adapter>
        <Adapter slot="3" enabled="false" MACAddress="08002724B024" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
          </DisabledModes>
        </Adapter>
        <Adapter slot="4" enabled="false" MACAddress="0800275ACDE2" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
          </DisabledModes>
        </Adapter>
        <Adapter slot="5" enabled="false" MACAddress="080027715437" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
          </DisabledModes>
        </Adapter>
        <Adapter slot="6" enabled="false" MACAddress="08002733EDEE" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
          </DisabledModes>
        </Adapter>
        <Adapter slot="7" enabled="false" MACAddress="080027B318D4" cable="true" speed="0" type="82540EM">
          <DisabledModes>
            <NAT>
              <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/>
              <Alias logging="false" proxy-only="false" use-same-ports="false"/>
            </NAT>
          </DisabledModes>
        </Adapter>
      </Network>
      <UART>
        <Port slot="0" enabled="false" IOBase="0x3f8" IRQ="4" hostMode="Disconnected"/>
        <Port slot="1" enabled="false" IOBase="0x2f8" IRQ="3" hostMode="Disconnected"/>
      </UART>
      <LPT>
        <Port slot="0" enabled="false" IOBase="0x378" IRQ="7"/>
        <Port slot="1" enabled="false" IOBase="0x378" IRQ="7"/>
      </LPT>
      <AudioAdapter controller="AC97" driver="DirectSound" enabled="true"/>
      <RTC localOrUTC="UTC"/>
      <SharedFolders/>
      <Clipboard mode="Disabled"/>
      <DragAndDrop mode="Disabled"/>
      <IO>
        <IoCache enabled="true" size="5"/>
        <BandwidthGroups/>
      </IO>
      <HostPci>
        <Devices/>
      </HostPci>
      <EmulatedUSB>
        <CardReader enabled="false"/>
      </EmulatedUSB>
      <Guest memoryBalloonSize="0"/>
      <GuestProperties>
        <GuestProperty name="/VirtualBox/HostInfo/GUI/LanguageID" value="zh_CN" timestamp="1449065768536626000" flags=""/>
      </GuestProperties>
    </Hardware>
    <StorageControllers>
      <StorageController name="IDE" type="PIIX4" PortCount="2" useHostIOCache="true" Bootable="true">
        <AttachedDevice passthrough="false" type="DVD" hotpluggable="false" port="1" device="0"/>
      </StorageController>
      <StorageController name="SATA" type="AHCI" PortCount="2" useHostIOCache="false" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3">
        <AttachedDevice type="HardDisk" hotpluggable="true" port="0" device="0">
          <Image uuid="{e1e7ffe5-9b7c-4c94-932f-72b4810a274f}"/>
        </AttachedDevice>
        <AttachedDevice type="HardDisk" hotpluggable="false" port="1" device="0">
          <Image uuid="{b914d8b0-b772-427b-a840-cadc1cf0391a}"/>
        </AttachedDevice>
      </StorageController>
    </StorageControllers>
  </Machine>
</VirtualBox>

以直接修改这个文件, 但是文件注释告诉我们不要手动修改. 所以还是老老实实用程序或者通过界面修改吧。

CentOS 6.6 Minimal设置文件夹共享 #

安装增强功能 #

需要先更新内核

yum clean all
yum install kernel-devel
yum install kernel-headers
yum install gcc
yum install make  
reboot

然后安装增强功能:

mount -t auto /dev/cdrom /mnt
cd /mnt
sh ./VBoxLinuxAdditions.run

配置共享文件夹 #

打开 VirtualBox 界面,选择对应的虚拟系统进行"设置",选中设置窗口中的最后一项"共享文件夹",再选中"固定分配",右键单击并确定共享文件夹的路径,下面的复选框一个都不用勾选,最后"确定"。

启动虚拟系统,进入系统以后,执行以下命令来挂载共享文件夹:mount -t vboxsf shared /mnt,其中 shared 为共享文件夹的名字,/mnt 表示当前挂载到 mnt 目录下。如果需要取消挂载,可以直接使用命令:umount -f /mnt

设置开机自动挂载:上述挂载方法只能起到临时挂载的效果,无法做到每次开机自动挂载,如果想要实现自动挂载,可以在开机时执行挂载脚本:vi /etc/rc.d/rc.local,在文件的最后面加上挂载命令:mount -t vboxsf shared /mnt,这样就可以实现每次开机时自动挂载共享文件夹了。

参考 #

1、CentOS 6.6 Minimal设置VirtualBox的共享文件夹 - 互联网小青年 - SegmentFault https://segmentfault.com/a/1190000002475493
2、VirtualBox--CentOS6.4设置文件夹共享 - 简书 http://www.jianshu.com/p/34e42a7e2235
3、VirtualBox安装Centos后实现文件夹共享 - VincentFu - 博客园 http://www.cnblogs.com/vincentfu/p/6893925.html
4、/sbin/mount.vboxsf: mounting failed with the error: No such device - daiyudong2020的博客 - CSDN博客 http://blog.csdn.net/daiyudong2020/article/details/58073520

Build by Loppo 0.6.14