MAC下用VirtualBox跑ubuntu的一点经验

来源:互联网 发布:怪物世界源码 编辑:程序博客网 时间:2024/06/03 16:22

软件版本:

MAC OSX:10.8.4,VirtualBox:4.2.16,ubuntu:ubuntu-12.04.2-desktop-amd64。

安装ubuntu

安装有两种方式:
  1. 跳过安装,直接从虚拟光驱启动。这有两个问题,一是会占用虚拟光驱,二是重启ubuntu后,以前的配置都丢失了。
  2. 安装ubuntu到虚拟硬盘上。

安装Guest Additions

如果要用VirtualBox自带的共享文件夹功能,必须先安装Guest Additions。安装方法:置顶的菜单条->devices->Install Guest Additions。
点击安装后,VirtualBox会把虚拟光驱中的已有的iso文件弹出,加载VBoxGuestAdditions.iso,然后运行。
如果直接从虚拟光驱启动,会出现已有iso不能弹出。在google上搜了半天,没有找到适合的解决方案。我后来自己想出一个好办法。
  1. 把/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso复制到home目录下,这一步是因为在下一步选择iso文件时,我不知道怎么进入/Applications/VirtualBox.app/Contents/MacOS目录。
  2. 在存储树里面增加一个光驱,用它来加载VBoxGuestAdditions.iso,如图所示。把ubuntu的iso设置成第一IDE控制器主通道,VBoxGuestAdditions.iso设置成从通道。
  3. 在ubuntu中,进入cdrom,执行autorun.sh,输出如下:
Verifying archive integrity... All good.Uncompressing VirtualBox 4.2.16 Guest Additions for Linux............VirtualBox Guest Additions installerRemoving installed version 4.2.16 of VirtualBox Guest Additions...Copying additional installer modules ...Installing additional modules ...Removing existing VirtualBox non-DKMS kernel modules ...done.Building the VirtualBox Guest Additions kernel modulesThe headers for the current running kernel were not found. If the followingmodule compilation fails then this could be the reason.Building the main Guest Additions module ...done.Building the shared folder support module ...done.Building the OpenGL support module ...done.Doing non-kernel setup of the Guest Additions ...done.You should restart your guest to make sure the new modules are actually usedInstalling the Window System driversInstalling X.Org Server 1.13 modules ...done.Setting up the Window System to use the Guest Additions ...done.You may need to restart the hal service and the Window System (or just restartthe guest system) to enable the Guest Additions.Installing graphics libraries and desktop services components ...done.Press Return to close this window...

按回车关闭窗口后,安装完成。

设置共享文件夹

点击置顶的菜单条->devices->shared folders后,弹出shared folders窗口,在里面设置共享文件夹。这里有个权限问题,如果让VirtualBox自动mount这个共享文件夹,它会以root用户mount。普通用户访问不了这个目录。我试过用chmod把目录权限改成所有人都能访问,但是没有成功。
在网上找到一个手动挂共享目录的方法:
ubuntu@ubuntu:~$ umask && id0002uid=999(ubuntu) gid=999(ubuntu) groups=999(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),124(sambashare)ubuntu@ubuntu:~$ sudo mkdir -p /media/sf_codesubuntu@ubuntu:~$ cd /mediaubuntu@ubuntu:/media$ lscdrom  sf_codesubuntu@ubuntu:/media$ cd sf_codes/ubuntu@ubuntu:/media/sf_codes$ lsubuntu@ubuntu:/media/sf_codes$ cd ..ubuntu@ubuntu:/media$ sudo mount -t vboxsf -o umask=002,uid=999,gid=999 codes /media/sf_codes
codes是VirtualBox设置的共享文件夹的目录名,/media/sf_codes是ubuntu上挂接的目录名。

在/etc/fstab增加下面这行,可以自动挂接:
codes /media/sf_codes vboxsf umask=002,uid=999,gid=999


原创粉丝点击