Android Container
Download source code;Kernel's subproject has kernel source code corresponding to the devices here:
https://android.googlesource.com
You can find kernel source code path corresponding to your device here
http://source.android.com/source/building-kernels.html
Download of this git project is slow,you can use bitbucket or deveo to transfer
checkout branch;Change to the source directory,use
$ git branch -a
View all branches,then use
$ git checkout <branch_name>
Check codes,here branch_name may have remotes/origin prefix,and there is no need to add -b option,else it will create a new branch
Configuration compiling environment;Clone this repo(you may need transfer):
https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
set PATH environment variable,add bin directory beneath repo
Compile source code
$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ make xx_defconfig # (Here you can find) config:http://source.android.com/source/building-kernels.html)
$ make
Compiled kernel is arch/arm/boot/zImage
(Nexus 5 is zImage-dtb
)
Method One:set TARGET_PREBUILT_KERNEL environment variable as compiled kernel,then m make boot.img,using
$ fastboot flash boot boot.img
Flush
Download source code;Here you can find Android versions which devices support:
https://developers.google.com/android/nexus/drivers
Download driver;Here has driver corresponding to devices:
https://developers.google.com/android/nexus/drivers
Get a script after download and extract,put it in Android directory to execute
Configuration compiling environment
System:Ubuntu x86_64 EN
Package:
build-essential/gcc&g++/lib32stdc++6
jdk6
python 2.6.x/2.7.x
gperf
libzip/zlib1g&zlib1g-dev/libzzip-dev
lib32z1
bison
flex
libxml2-utils
git
bc
zip
squashfs-tools
libncurses5-dev
Enter Android source code directory;Execute following command to compile source code:
$ source build/envsetup.sh
$ lunch # (choose target corresponding to device)
$ m
Connecting devices;Execute following command to flush a new ROM(you need run as root):
$ adb reboot bootloader
$ fastboot devices
$ fastboot flashall -w
drivers/staging/android/
directoryconbinder.h
and conbinder.c
binder.c
to conbinder.h
,then include "conbinder.h"
static
from binder_fops
struct's function,then add its declaration in conbinder.h
CONBINDER_GET_CURRENT_CONTAINER
macro definition in conbinder.h
(ioctl
operation gets container's ID in which current process is)conbinder.c
binder_ioctl
function in binder.c
,add treatment codes of CONBINDER_GET_CURRENT_CONTAINER
commandKconfig
,add ANDROID_CONBINDER_IPC
optionMakefile
,add conbinder.o
compilation configurationdrivers/rtc/
directoryalarm-dev.c
,add conalarm_fops
and conalarm_device
data struct,initialize code and customize conalarm_open
functionANDROID_CONALARM
to control relevant conalarm
code if compiledKconfig
,add ANDROID_CONALARM_DEV
optionMakefile
,add compilation configuration(ccflags
) of macro definition ANDROID_CONALARM
drivers/staging/android/
directorycontainer.h
and container.c
ioctl
command in container.h
container.c
Kconfig
,add ANDROID_CONTAINER
optionMakefile
,add container.o
compilation configurationModify .config
,add following compilation configuration options
ANDROID_CONBINDER_IPC
ANDROID_CONALARM_DEV
ANDROID_CONTAINER
IKCONFIG
IKCONFIG_PROC
lxc-checkconfig
,add compilation configuration optionsAccording toStep II
,compileRemove
mount rootfs rootfs / ro remount
Add
mount tmpfs tmpfs /run
symlink /system/bin /bin
Add it after PATH environment variable
:/system/busybox/bin:/system/busybox/sbin:/system/local/bin
Add it after LD_LIBRARY_PATH:
:/system/local/lib
Add
export ANDROID_CT /system/local/var/lib/lxc/android4.x.x
Add
/dev/conbinder1 0666 root root
...
/dev/conbinder9 0666 root root
Add
/dev/conalarm 0664 system radio
Add
/dev/container 0666 root root
Extract NDK,then execute in it
$ build/tools/make-standalone-toolchain.sh
Find tool chain in /tmp directory
Add tool chain directory after PATH environment variable
Download lxc-1.0.0.alpha*
source code
Execute in lxc source code
$ autogen.sh
Execute
$ ./configure --host=arm-linux-androideabi --prefix=/system/local CC=arm-linux-androideabi-gcc --disable-capabilities
Execute
$ sudo make prefix=/system/local install
You can find compiled procedure in /system/local
Put compiled busybox in system directory
Pack the folders in lxc's installation directory,then extractit in /system/local directory
Create cgroup directory beneath /system/,and Create following directory beneath cgroup
cpuset
memory
blkio
freezer
device
Create script file mount-cgroups.sh
beneath /system/local/bin,to mount cgroups and ashmem;command is following:
for t in `ls /system/cgroup`
do
mount -t cgroup -o $t cgroup /system/cgroup/$t
done
mkdir /dev/shm
mount -t tmpfs -o nodev,noexec tmpfs /dev/shm
androidx.x.x
beneath /system/local/var/lib/lxc
to save container systemlxc.utsname = android4.1.2
lxc.tty = 0
lxc.rootfs = /system/local/var/lib/lxc/android4.1.2/rootfs
lxc.cgroup.devices.allow = a
Create directories beneath system root directory,following the principles:(copy means copying directories of host;empty means creating a empty directory;the same below)
/firmware copy
/persist copy
/storage empty
/config copy
/cache empty
/acct empty
/mnt empty
/sys empty
/sbin empty
/run empty
/res copy
/proc empty
/data empty
/root empty
/dev empty
/system empty
Create folder and directory beneath system directory,as following rules:
app empty
bin copy
build.prop copy
busybox copy
etc copy
fonts copy
framework empty
lib empty
media empty
priv-app empty
tts copy
usr copy
vendor copy
xbin copy
Create script file mount-bind.sh
in android4.x.x
directory,Enter the following command:
mount -o bind /system/app rootfs/system/app
mount -o bind /system/framework rootfs/system/framework
mount -o bind /system/lib rootfs/system/lib
mount -o bind /system/media rootfs/system/media
mount -o bind /system/priv-app rootfs/system/priv-app
mount -o bind /dev/conbinder1 rootfs/dev/binder
mount -o bind /dev/conalarm rootfs/dev/alarm
Create script file share.sh
in android4.x.x
directory,Enter the following command:
echo "SurfaceFlinger" >>/proc/conbinder/sharedservices
Enter shell using following command as root:
# adb root
# adb shell
Execute following command to mount various folders:
# mount-rw.sh
# mount-cgroups.sh
Enter directory in which container is,and execute following command:
# ./mount-bind.sh
# ./share.sh
Execute following command to clear log:
# dmesg -c
# logcat -c
Execute following command to start container:
lxc-start -n <container name>