Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62906
  • 博文数量: 17
  • 博客积分: 1430
  • 博客等级: 上尉
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 12:56
文章分类
文章存档

2011年(1)

2008年(16)

我的朋友

分类: LINUX

2008-04-06 01:50:43

在 VMWare 中安装 Linux 操作系统,最好在装好后安装 VMWare Tools。其好处是可以接管运行于 VMWare 中的操作系统的一些设备驱动程序,使之更好地支持 VMWare 提供的各项功能。比如,安装 VMWare Tools 之后,鼠标就可以在虚拟机和宿主机之间平滑移动,而无需按 Ctrl+Alt 进行切换。安装的方法很简单,在 VM 菜单中选择“Install VMWare Tools”项即可。其实现的机制是:将虚拟机的光驱中的内容改换成一个含有 VMWare Tools 安装文件的 .iso 文件(可以在宿主机 VMWare 安装目录中找到为不同操作系统预备的这个 VMWare Tools “安装光盘”镜像)。

然而,在新版本 VMWare 中安装 Linux 下的 VMWare Tools,却遇到一些问题。更确切地,是 2.6.22 内核版本,在编译“vmhgfs”模块时出现问题。这个模块的功能是为虚拟机提供共享宿主文件系统的功能。这项功能允许用户在虚拟机中直接挂载宿主文件系统中的某个目录,并进行一些操作。

编译内核模块时的错误如下:

Trying to find a suitable vmhgfs module for your running kernel.

None of the pre-built vmhgfs modules for VMware Tools is suitable for your
running kernel.  Do you want this program to try to build the vmhgfs module for
your system (you need to have a C compiler installed on your system)? [yes]
Extracting the sources of the vmhgfs module.

Building the vmhgfs module.

Using 2.6.x kernel build system.
make: Entering directory `/tmp/vmware-config2/vmhgfs-only'
make -C /lib/modules/2.6.22-14-generic/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.22-14-generic'
  CC [M]  /tmp/vmware-config2/vmhgfs-only/backdoor.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/backdoorGcc32.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/bdhandler.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/cpName.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/cpNameLinux.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/cpNameLite.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/dbllnklst.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/dentry.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/dir.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/eventManager.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/file.o
  CC [M]  /tmp/vmware-config2/vmhgfs-only/filesystem.o
/tmp/vmware-config2/vmhgfs-only/filesystem.c: In function ‘HgfsInitFileSystem’:
/tmp/vmware-config2/vmhgfs-only/filesystem.c:582: error: too few arguments to function ‘kmem_cache_create’
/tmp/vmware-config2/vmhgfs-only/filesystem.c:593: error: too few arguments to function ‘kmem_cache_create’
make[2]: *** [/tmp/vmware-config2/vmhgfs-only/filesystem.o] Error 1
make[1]: *** [_module_/tmp/vmware-config2/vmhgfs-only] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.22-14-generic’
make: *** [vmhgfs.ko] Error 2
make: Leaving directory `/tmp/vmware-config2/vmhgfs-only’
Unable to build the vmhgfs module.

The filesystem driver (vmhgfs module) is used only for the shared folder
feature. The rest of the software provided by VMware Tools is designed to work
independently of this feature.
If you wish to have the shared folders feature, you can install the driver by
running vmware-config-tools.pl again after making sure that gcc, binutils, make
and the kernel sources for your running kernel are installed on your machine.
These packages are available on your distribution’s installation CD.
[ Press Enter key to continue ]

根据上面提示的错误,可以发现,是编译器在编译某个文件时发生语法错误。这种低级的错误居然会在 VMWare 这个成熟的产品中发生?感到不可思议。于是展开 vmware-tools-distrib/lib/module/source/vmhgfs.tar 文件,打开 filesystem.c,找到 593 行附近代码在调用函数:

   /* Setup the inode slab allocator. */
   hgfsInodeCache = compat_kmem_cache_create("hgfsInodeCache",
                                             sizeof (HgfsInodeInfo),
                                             0,
                                             SLAB_HWCACHE_ALIGN,
                                             HgfsInodeCacheCtor);

这段代码调用的函数 compat_kmem_cache_create 并非 Linux 本身的 system call,而是经过一层兼容性嵌套。很快就能够找到这个定义,在同一 tar 包中的 compat_slab.h 文件中,到有关片段如下:

/*
 * Destructor is gone since 2.6.23-pre1.
 */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) || defined(VMW_KMEMCR_HAS_DTOR)
#define compat_kmem_cache_create(name, size, align, flags, ctor) 
                kmem_cache_create(name, size, align, flags, ctor, NULL)
#else
#define compat_kmem_cache_create(name, size, align, flags, ctor) 
                kmem_cache_create(name, size, align, flags, ctor)
#endif

这段代码的目的是,根据不同的 Linux 内核版本选择不同的系统调用形式。根据注释,意思是说从 2.6.23-pre1 版本的内核开始,系统调用 kmem_cache_create 将少了一个参数。而开始所提到的错误恰好是这个函数调用出现参数不够的问题。仔细分析后发现,原来 2.6.22 版本的内核也被当成了 2.6.23 以后的处理办法,当然不对了!

解决方法:将第 26 行的

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) || defined(VMW_KMEMCR_HAS_DTOR)

改为

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22) || defined(VMW_KMEMCR_HAS_DTOR)

重新打包,执行安装程序,问题即可解决。

================================================================

解决VMWare安装tools后/mnt/hgfs里面什么都没有的问题

参考:

------------------------------------------------------------------------
Bug fixed:

CC [M] /tmp/vmware-config3/vmhgfs-only/filesystem.o
/tmp/vmware-config3/vmhgfs-only/filesystem.c: En la función ‘HgfsInitFileSystem’:
/tmp/vmware-config3/vmhgfs-only/filesystem.c:582: error: muy pocos argumentos para la función ‘kmem_cache_create’
/tmp/vmware-config3/vmhgfs-only/filesystem.c:593: error: muy pocos argumentos para la función ‘kmem_cache_create’
make[2]: *** [/tmp/vmware-config3/vmhgfs-only/filesystem.o] Error 1
make[1]: *** [_module_/tmp/vmware-config3/vmhgfs-only] Error 2
make[1]: se sale del directorio `/usr/src/linux-headers-2.6.22-14-generic'
make: *** [vmhgfs.ko] Error 2
make: se sale del directorio `/tmp/vmware-config3/vmhgfs-only'
Unable to build the vmhgfs module.


Software necesario
- sudo aptitude install build-essential linux-headers-$(uname -r)

vmwaretools
- cd /tmp
- tar -xzvf VMwareTools-6.0.2-59824.tar.gz
- cd vmware-tools-distrib/lib/modules/source
- cp vmhgfs.tar vmhgfs.tar.old
- tar xvf vmhgfs.tar
- cd vmhgfs-only
- chmod 644 compat_slab.h
- vi compat_slab.h
Search-> #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) || defined(VMW_KMEMCR_HAS_DTOR)
Fix-> #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 22) || defined(VMW_KMEMCR_HAS_DTOR)
Save Chages
- chmod 444 compat_slab.h
- cd ..
- rm vmhgfs.tar
- tar cvf vmhgfs.tar vmhgfs-only
- cd /tmp/vmware-tools-distrib
- sudo ./vmware-install.pl

Enjoy!!

--- by aNyBosZ ---

__________________

阅读(2883) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~