Building ChromeOS Steps

TurnToJPG -->

My aim is for enable the bluetooth Networking in my Chromebook, AKA BNEP, so first I have to build out some experimentation platforms for investigation, following is the steps for building out the ChromeOS Images and let it run under kvm based virtual machine.


I use a 6-Giga-Byte memory machine for building, first install following packages:

$ sudo apt-get install git-core gitk git-gui subversion curl

Since I am in china mainland, the connection to googlesourcecode is blocked by Great Fire Wall(Fuck you!), I have to use proxychains for automatically convert my TCP/UDP flow to sock flow. That’s why in some steps I use proxychains4 in front of the commands. If you are free to reach Internet, you should remove the proxychains4 in front of each command.
Then install depot_tools.

dasdh@BuildMaasImage:~/Code$ pwd
dasdh@BuildMaasImage:~/Code$ mkdir depot_tools
dasdh@BuildMaasImage:~/Code$ proxychains4  git clone
$ export PATH=`pwd`/depot_tools:"$PATH"
$ echo $PATH

Config git:

dasdh@BuildMaasImage:~/Code$ git config --global ""
dasdh@BuildMaasImage:~/Code$ git config --global "Dash"

Maybe in the future you will use github repository, better you use ssh-keygen to generate the public ssh key and upload it to github. Make sure your architecture is x86_64, and add following into your ~/.bashrc:

dasdh@BuildMaasImage:~/Code$ uname -m
dasdh@BuildMaasImage:~/Code$ cat ~/.bashrc | grep umask
umask 022

Get Source Code

Get the code via following commands:

dasdh@BuildMaasImage:~$ mkdir chromiumos
dasdh@BuildMaasImage:~$ pwd

Then get the credential for chromiumOS( go to for getting the commands):

$  touch ~/.gitcookies
$  chmod 0600 ~/.gitcookies
$  git config --global http.cookiefile ~/.gitcookies
$  tr , \\t <<\__END__ >>~/.gitcookies,TRUE,/,TRUE,2147483647,o,
$  git config --global "url." ""
$  git config --global --add "url." ""
$  proxychains4 git ls-remote

The final output result should be a list of file.
Because the google source code use https connection, so we need to define the .netrc like following:

$ touch ~/.netrc
$ chmod 0600 ~/.netrc
$ vim ~/.netrc
password agowugoweugowugouwoguoweugoeugo

password agowugoweugowugouwoguoweugoeugo

Now your configuration is ready, initialize the repository via:

$ proxychains4 repo init -u --repo-url
$ proxychains4 repo sync 

repo sync will take a very long time for getting all of the source code down, and it will takes arount 8G disk size.

Build Source Code

After source code is avaiable, start building it via:

$ proxychains cros_sdk

Since the proxychains failed, I’ve enable the redsocks for crossing the GFW, in the last part of this article shows its installation and configuration.
Using redsocks we could continue the building:

$ cros_sdk
dasdh@BuildMaasImage ~/trunk/src/scripts $ 

Now start building via:

#  export BOARD=amd64-generic
# ./setup_board --board=${BOARD}
# ./
# ./build_packages --board=${BOARD}
# ./build_image --board=${BOARD} --noenable_rootfs_verification dev

If you met hostname error, make sure your hostname is added in /etc/hosts.

The building result is listed as:

(cr) dasdh@BuildMaasImage ~/trunk/src/build/images/amd64-generic/R44-7040.0.2015_05_06_0543-a1 $ pwd
(cr) dasdh@BuildMaasImage ~/trunk/src/build/images/amd64-generic/R44-7040.0.2015_05_06_0543-a1 $ ls -l -h
total 1.2G
-rw-r--r-- 1 dasdh eng  399 May  6 05:52 boot.config
-rw-r--r-- 1 dasdh eng  214 May  6 05:49 boot.desc
-rw-r--r-- 1 dasdh eng 2.5G May  6 05:52 chromiumos_image.bin
-rw-r--r-- 1 dasdh eng  586 May  6 05:52 config.txt
drwxr-xr-x 2 dasdh eng 4.0K May  6 05:52 esp
-rwxr-xr-x 1 dasdh eng 5.6K May  6 05:43
-rwxr-xr-x 1 dasdh eng 4.8K May  6 05:43
-rw-r--r-- 1 dasdh eng  12K May  6 05:43
-rwxr-xr-x 1 dasdh eng 4.7K May  6 05:43
-rwxr-xr-x 1 dasdh eng 5.0K May  6 05:43

I think the chromiumos_image.bin is what we want.


Download the redsocks source code and compile it:

# cd /opt/src
# git clone
# cd redsocks
# apt-get install libevent-dev 
# make 

Write configuration files:

# cat
#! /bin/sh

case "$1" in
    cd /opt/src/redsocks
    if [ -e redsocks.log ] ; then
      rm redsocks.log
    ./redsocks -p /opt/src/redsocks/ #set daemon = on in config file
    # start redirection
    iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to 12345
    iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to 12345

    cd /opt/src/redsocks
    if [ -e ]; then
      kill `cat`
      echo already killed, anyway, I will try killall
      killall -9 redsocks
    # stop redirection
    iptables -t nat -F OUTPUT

    #ssh -NfD 1234 #TODO: change it!!!
    ssh -NfD 1234

    ps aux|grep "ssh -NfD 1234"|awk '{print $2}'|xargs kill

    iptables -A INPUT -p udp --sport 53 -m state --state ESTABLISHED -m gfw -j DROP -m comment --comment "drop gfw dns hijacks"

    echo "Usage: redsocks start|stop|start_ssh|stop_ssh|clean_dns" >&2
    exit 3
# cat redsocks.conf
base {
        // debug: connection progress & client list on SIGUSR1
        log_debug = on;

        // info: start and end of client session
        log_info = on;

        /* possible `log' values are:
         *   stderr
         *   file:/path/to/file
         *   syslog:FACILITY  facility is any of "daemon", "local0"..."local7"
        log = stderr;

        // detach from console
        daemon = on;

        /* Change uid, gid and root directory, these options require root
         * privilegies on startup.
         * Note, your chroot may requre /etc/localtime if you write log to syslog.
         * Log is opened before chroot & uid changing.
        // user = nobody;
        // group = nobody;
        // chroot = "/var/chroot";

        /* possible `redirector' values are:
         *   iptables   - for Linux
         *   ipf        - for FreeBSD
         *   pf         - for OpenBSD
         *   generic    - some generic redirector that MAY work
        redirector = iptables;

redsocks {
        /* `local_ip' defaults to for security reasons,
         * use if you want to listen on every interface.
         * `local_*' are used as port to redirect to.
        local_ip =;
        local_port = 12345;

        // `ip' and `port' are IP and tcp-port of proxy-server
        ip =;
        port = 1234;

        // known types: socks4, socks5, http-connect, http-relay
        type = socks5;

Everytime you use the redsocks, enable it via:

# ./ start_ssh
# ./ start

Disable it via:

# ./ stop
# ./ stop_ssh

Run ChromeOS in kvm

Now Transfer the image to image for vm:

$ export BOARD=amd64-generic
(cr) dasdh@BuildMaasImage ~/trunk/src/build/images/amd64-generic/latest $ cd ~/trunk/src/scripts/
(cr) ((df83602...)) dasdh@BuildMaasImage ~/trunk/src/scripts $ ./ --board=${BOARD}
Resizing stateful partition to 3072MB

Verify if kvm is supported on your system:

dasdh@BuildMaasImage:~/src/scripts$ kvm-ok
INFO: /dev/kvm exists                                                                                                                          
KVM acceleration can be used      

Now run via:

$ cd ~/chromiumos/src/scripts
$ ./bin/cros_start_vm --image_path=../build/images/${BOARD}/latest/chromiumos_qemu_image.bin