Building ChromeOS Steps

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.

Prerequistites

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
/home/dasdh/Code
dasdh@BuildMaasImage:~/Code$ mkdir depot_tools
dasdh@BuildMaasImage:~/Code$ proxychains4  git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"
$ echo $PATH
/home/dasdh/Code/depot_tools:/home/dasdh/Code/depot_tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Config git:

dasdh@BuildMaasImage:~/Code$ git config --global user.email "kkkttt@gmail.com"
dasdh@BuildMaasImage:~/Code$ git config --global user.name "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
x86_64
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
/home/dasdh

Then get the credential for chromiumOS( go to https://chromium-review.googlesource.com/new-password for getting the commands):

$  touch ~/.gitcookies
$  chmod 0600 ~/.gitcookies
$  git config --global http.cookiefile ~/.gitcookies
$  tr , \\t <<\__END__ >>~/.gitcookies
 .googlesource.com,TRUE,/,TRUE,2147483647,o,git-kkkttt.gmail.com=1/goeugoueogewoguoweugoawohouaohuowauhoaeuo
 __END__
$  git config --global "url.https://chromium.googlesource.com/a/.insteadOf" "https://chromium.googlesource.com/"
$  git config --global --add "url.https://chromium.googlesource.com/a/.insteadOf" "https://chromium.googlesource.com/a/"
$  proxychains4 git ls-remote https://chromium.googlesource.com/a/chromiumos/manifest.git

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
machine chromium.googlesource.com
login git-kkkttt.gmail.com
password agowugoweugowugouwoguoweugoeugo

machine chromium-review.googlesource.com
login git-kkkttt.gmail.com
password agowugoweugowugouwoguoweugoeugo

Now your configuration is ready, initialize the repository via:

$ proxychains4 repo init -u https://chromium.googlesource.com/chromiumos/manifest.git --repo-url https://chromium.googlesource.com/external/repo.git
$ 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}
# ./set_shared_user_password.sh
# ./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
/home/dasdh/trunk/src/build/images/amd64-generic/R44-7040.0.2015_05_06_0543-a1
(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 mount_image.sh
-rwxr-xr-x 1 dasdh eng 4.8K May  6 05:43 pack_partitions.sh
-rw-r--r-- 1 dasdh eng  12K May  6 05:43 partition_script.sh
-rwxr-xr-x 1 dasdh eng 4.7K May  6 05:43 umount_image.sh
-rwxr-xr-x 1 dasdh eng 5.0K May  6 05:43 unpack_partitions.sh

I think the chromiumos_image.bin is what we want.

RedSocks

Download the redsocks source code and compile it:

# cd /opt/src
# git clone https://github.com/darkk/redsocks.git
# cd redsocks
# apt-get install libevent-dev 
# make 

Write configuration files:

# cat redsocks.sh
#! /bin/sh

case "$1" in
  start|"")
    cd /opt/src/redsocks
    if [ -e redsocks.log ] ; then
      rm redsocks.log
    fi
    ./redsocks -p /opt/src/redsocks/redsocks.pid #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
    ;;

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

  start_ssh)
    #ssh -NfD 1234 user@example.cc #TODO: change it!!!
    ssh -NfD 1234 544644af4382ec37bc0009da@weatherapp-kkkttt.rhcloud.com
    ;;

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

  clean_dns)
    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
    ;;
esac
# 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 127.0.0.1 for security reasons,
         * use 0.0.0.0 if you want to listen on every interface.
         * `local_*' are used as port to redirect to.
         */
        local_ip = 127.0.0.1;
        local_port = 12345;

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

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


Everytime you use the redsocks, enable it via:

# ./redsocks.sh start_ssh
# ./redsocks.sh start

Disable it via:

# ./redsocks.sh stop
# ./redsocks.sh 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 $ ./image_to_vm.sh --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

Modification SWAP on RPI Installation

First disable the swap partition, for it will save your sd card:
Know where is your swap file:

$ cat /proc/swap*

Disable it via change the S to K under /etc/rcx.d, and reboot the services:

$ sudo mv S02dphys-swapfile K02dphys-swapfile

Build CentOS Image For MAAS

MAAS could only deploy Ubuntu in its official support, this artcle will introduce how to Build CentOS based images.

Preparation

First you need a Ubuntu14.04 machine with kvm enabled.

$ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade
$ sudo apt-get install build-essential

Get Build Scripts

Get the source code from the launchpad, and run following command for preparing the building environment.

$  bzr branch lp:maas-image-builder
$ cd maas-images-builder
$ make install-dependencies

For speed-up building, I use china mainland’s repository,
Replace the http://mirror.centos.org/centos/6/os/x86_64 like following:

$ vim ./src/mib/builders/centos.py
      #"http://mirror.centos.org/centos/6/os/i386")
      "http://mirrors.aliyun.com/centos/6/os/i386")
      #"http://mirror.centos.org/centos/6/os/x86_64")
      "http://mirrors.aliyun.com/centos/6/os/x86_64")
  #"http://mirror.centos.org/centos/7/os/x86_64")
  "http://mirrors.aliyun.com/centos/7/os/x86_64/")

$ vim ./contrib/centos/centos6/centos6-amd64.ks
repo --name="repo0" --baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64/
repo --name="repo1" --baseurl=http://mirrors.aliyun.com/centos/6/updates/x86_64/
repo --name="repo2" --baseurl=http://mirrors.aliyun.com/epel/6/x86_64/

Build Images

Install python-dev and begin to make:

# apt-get install python-dev
# make

Now begin to generate the image:

#./bin/maas-image-builder -o centos6-amd64-root-tgz centos --edition 6

On-Building:
/images/2015_04_29_18_00_43_674x328.jpg

After building the image is listed as:

# ls -l centos6-amd64-root-tgz 
-rw-r--r-- 1 root root 353086181 Apr 29 13:16 centos6-amd64-root-tgz

Import Images

First login into your own profile with following command:

$ maas login my-maas http://10.17.17.202/MAAS/api/1.0 ntQBr8QTPgeTyfYuMq:xxxxxxxxxxxxxxxxxxxxxxxxx7HNspYLch4kc6RLs
$ maas my-maas boot-sources read

Above command will readout the boot-sources, now we need to import our newly-built images, import it via:

$ maas my-maas boot-resources create name=centos/centos6 architecture=amd64/generic content@=/home/Trusty/centos6-amd64-root-tgz

Login

Use following commands:

maas@MassTestOnUbuntu1404:~$ ssh cloud-user@10.17.17.172
The authenticity of host '10.17.17.172 (10.17.17.172)' can't be established.
ECDSA key fingerprint is a5:57:5b:d1:ac:c0:8f:67:32:43:d8:6f:17:67:65:cb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.17.17.172' (ECDSA) to the list of known hosts.
[cloud-user@CentOS ~]$ ls
[cloud-user@CentOS ~]$ cat /etc/issue
\S
Kernel \r on an \m

[cloud-user@CentOS ~]$ uname -a
Linux CentOS 3.10.0-229.1.2.el7.x86_64 #1 SMP Fri Mar 27 03:04:26 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

From Now on,you could use CentOS 6 for deploying!!!!!!!!!!!!!!1

ENJOY IT!!!!!!!

Trouble Shooting

The version could not be speicified via –edition, everytime we got CentOS 7 based image , so we need to manually change the file:

 root@BuildMaasImage:~/Code/once# vim src/mib/builders/centos.py
    def populate_parser(self, parser):
        """Add parser options."""
        parser.add_argument(
            #'--edition', default='7',
            #help="CentOS edition to generate. (Default: 7)")
            '--edition', default='6',
            help="CentOS edition to generate. (Default: 6)")



Now re-generate the image again, we got CentOS 6.5 based images.
To-Be-Done:
How to generate the CentOS 6.5/6.4/6.3 version? we always get the newest CentOS 6 images.

Trouble Shooting On Juju's Local Deployment

When deploying juju, after juju bootstrap, use juju ssh for login, it will hint me:

$ juju ssh 1
......
Permission denied (publickey).

That could be solved by specify the id_rsa.pub key:

$ ssh-keygen -t rsa -b 2048
$ juju bootstrap
$ juju bootstrap
$ juju deploy wordpress
$ juju deploy mysql
$ juju add-relation wordpress mysql
$ juju status
$ juju expose wordpress

By doing this you could make your juju deployment on local successfully.

Use reave for testing wireless security

For those who want to test the wireless security(Wireless Router), following is a serial of tools for automatically scan the WIFI and try to find the entrance to inner network.

Preparation

Install following packages:

$ sudo apt-get install macchanger  aircrack-ng reaver

Testing

Suppose the wireless port in our equipment is mlan0, following are the detailed steps:

# macchanger -m 00:11:22:33:44:55 mlan0
# airmon-ng start mlan0
# ifconfig mlan0mon down
# macchanger -m 00:11:22:33:44:55 mlan0mon
# ifconfig mlan0mon up
# airodump-ng mlan0mon
# reaver -i mlan0mon -b xx:xx:xx:xx:xx -vv -dh-small