Integrating vboxsf

With the loadable module vboxsf.ko, we have the capability to exchange files between the host and the guest at the runtime of the Android system. To create a shared folder between the host and guest, we need to load the vboxsf.ko module first.

To use vboxsf.ko, we need a tool called mount.vboxsf, which can be used to mount a shared folder on the host filesystem to the Android filesystem. This mount.vboxsf tool is part of the utilities provided by VirtualBox Guest Additions. We put it under our x86vbox device folder as follows:

$ ls mount.vboxsf/ 
Android.mk mount.vboxsf.c vbsfmount.h

It includes a C file and a header file. We created the following Android Makefile to build it:

LOCAL_PATH:= $(call my-dir) 
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= mount.vboxsf.c

LOCAL_CFLAGS:=-O2 -g
#LOCAL_CFLAGS+=-DLINUX

LOCAL_MODULE:=mount.vboxsf
LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

To include it in the system image, we also need to add it to the x86vbox.mk Makefile as follows:

... 
PRODUCT_PACKAGES +=
mount.vboxsf
...

In order to load vboxsf.ko during the system boot up, we need to add the loading of vboxsf.ko to the start up script in initrd.img. If we recall from Chapter 6, Debugging the Boot Up Process Using a Customized Ramdisk, we discussed the init script in the initrd.img. The shell script function load_modules is called to load most of the device drivers in the first stage boot up. We can change this script to load VirtualBox device drivers as follows:

load_modules() 
{
if [ -z "$FOUND" ]; then
auto_detect
fi

# 3G modules
for m in $EXTMOD; do
busybox modprobe $m
done

if [ -n "$VBOX_GUEST_ADDITIONS" ]; then
echo "Loading VBOX_GUEST_ADDITIONS ..."
insmod /android/system/vendor/vbox/vboxguest.ko
insmod /android/system/vendor/vbox/vboxsf.ko
if [ ! -e /android$SDCARD ]; then
mkdir /android$SDCARD
/android/system/bin/mount.vboxsf sdcard /android$SDCARD
fi
fi
}

We defined a VBOX_GUEST_ADDITIONS kernel parameter, which can be used to enable the loading of VirtualBox-specific device drivers. If this kernel parameter is defined, we will load both loadable modules, vboxguest.ko and vboxsf.ko. Another kernel parameter, SDCARD, is also defined so that we can mount the shared folder to be an external SD card storage. The SDCARD kernel parameter is used by the shell script function mount_sdcard as well.

To define these two kernel parameters on the kernel command line, we need to change the PXE boot script at $HOME/.VirtualBox/TFTP/pxelinux.cfg/default as follows:

label 1. x86vbox (2 stages boot) 
menu x86vbox_initrd
kernel x86vbox/kernel
append ip=dhcp console=ttyS3,115200 androidboot.selinux=permissive buildvariant=eng initrd=x86vbox/initrd.img androidboot.hardware=x86vbox DEBUG=2 SRC=/android-x86vbox ROOT=/dev/sda1 VBOX_GUEST_ADDITIONS=1 SDCARD=vendor DATA=sda2 X86VBOX=1

Pay attention to the two variables SDCARD and VBOX_GUEST_ADDITIONS. They are the two new kernel parameters that we added to support the loading of VirtualBox device drivers. To mount the shared folder, we add the following command in the script:

/android/system/bin/mount.vboxsf sdcard /android$SDCARD 

The first parameter to mount.vboxsf is the shared folder that we defined in the VirtualBox settings, as shown in the following screenshot:

With all the changes related to the shared folder, we can have a method that can be used to share data between the host and the guest very easily.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.236.191