VMWare 6安裝 VMWare Tools for Linux的一個問題
在 VMWare 中安裝 Linux 操作系統(tǒng),最好在裝好后安裝安裝VMWare Tools for Linux。其好處是可以接管運行于VMWare 中的操作系統(tǒng)的一些設(shè)備驅(qū)動程序,使之更好地支持VMWare 提供的各項功能。比如,安裝VMWare Tools for Linux之后,鼠標就可以在虛擬機和宿主機之間平滑移動,而無需按Ctrl+Alt 進行切換。安裝VMWare Tools for Linux的方法很簡單,在VM 菜單中選擇“Install VMWare Tools”項即可。其實現(xiàn)的機制是:將虛擬機的光驅(qū)中的內(nèi)容改換成一個含有VMWare Tools 安裝文件的 .iso 文件(可以在宿主機 VMWare 安裝目錄中找到為不同操作系統(tǒng)預備的這個 VMWare Tools “安裝光盤”鏡像)。
然而,在新版本VMWare 中安裝VMWare Tools for Linux,卻遇到一些問題。更確切地,是 2.6.22 內(nèi)核版本,在編譯“vmhgfs”模塊時出現(xiàn)問題。這個模塊的功能是為虛擬機提供共享宿主文件系統(tǒng)的功能。這項功能允許用戶在虛擬機中直接掛載宿主文件系統(tǒng)中的某個目錄,并進行一些操作。
編譯內(nèi)核模塊時的錯誤如下:
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 ]
根據(jù)上面提示的錯誤,可以發(fā)現(xiàn),是編譯器在編譯某個文件時發(fā)生語法錯誤。這種低級的錯誤居然會在 VMWare 這個成熟的產(chǎn)品中發(fā)生?感到不可思議。于是展開 vmware-tools-distrib/lib/module/source/vmhgfs.tar 文件,打開 filesystem.c,找到 593 行附近代碼在調(diào)用函數(shù):
/* Setup the inode slab allocator. */
hgfsInodeCache = compat_kmem_cache_create("hgfsInodeCache",
sizeof (HgfsInodeInfo),
0,
SLAB_HWCACHE_ALIGN,
HgfsInodeCacheCtor);
這段代碼調(diào)用的函數(shù) compat_kmem_cache_create 并非 Linux 本身的 system call,而是經(jīng)過一層兼容性嵌套。很快就能夠找到這個定義,在同一 tar 包中的 compat_slab.h 文件中,到有關(guān)片段如下:
/*
* 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
這段代碼的目的是,根據(jù)不同的 Linux 內(nèi)核版本選擇不同的系統(tǒng)調(diào)用形式。根據(jù)注釋,意思是說從 2.6.23-pre1 版本的內(nèi)核開始,系統(tǒng)調(diào)用 kmem_cache_create 將少了一個參數(shù)。而開始所提到的錯誤恰好是這個函數(shù)調(diào)用出現(xiàn)參數(shù)不夠的問題。仔細分析后發(fā)現(xiàn),原來 2.6.22 版本的內(nèi)核也被當成了 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)
重新打包,執(zhí)行安裝程序,安裝VMWare Tools for Linux問題即可解決。
【編輯推薦】