Write Blogger in Linux

###blogtk Install it via “yaourt -S blogtk”

KALI Linux in Qemu

Download the iso from kali websitehttp://www.kali.org/downloads/:

	$ wget http://cdimage.kali.org/kali-images/kali-1.0.5/kali-linux-1.0.5-i386.iso

Create qemu img file:

	$ qemu-img create -f qcow2 kali.qcow2 30G
	Formatting 'kali.qcow2', fmt=qcow2 size=32212254720 encryption=off cluster_size=65536 lazy_refcounts=off 
Run installation. Here we use the run-qemu script which has been generated before under the same directory:
	[Trusty@DashArch kali]$ ./run-qemu -hda ./kali.qcow2 -boot d -cdrom /media/nfs/iso/kali-linux-1.0.5-i386.iso  -m 1024 -enable-kvm -usb

Choose “Graphic Install” because currently we are not familiar with this brand new distribution.
Command for startup the sytem is:

	[Trusty@DashArch kali]$ ./run-qemu -hda ./kali.qcow2 -boot d -cdrom /media/nfs/iso/kali-linux-1.0.5-i386.iso  -m 1024 -enable-kvm -usb

After installation finished, run “sudo apt-get update” and “sudo apt-get upgrade” to update your system to the newest version.

NTP in LAN based on OPENWRT

###Package Installation Disable the system default ntp server and install ntpd, this ntpd is the real ntpd package, not busybox-ntpd

	opkg update
	opkg install ntpd
	/etc/init.d/sysntpd disable
	/etc/init.d/ntpd enable
	/etc/init.d/ntpd start
	netstat -l | grep ntp

The client installation, on debian:

	apt-get install ntp

###Server Configuration Comment all of the possible reference server, use local time source.

	root@OpenWrt:~# cat /etc/ntp.conf 
	# use a random selection of 4 public stratum 2 servers
	# see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers
	
	restrict default nomodify notrap noquery
	#restrict default noquery
	
	#restrict 127.0.0.1
	restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap
	
	server 127.127.1.0	# LOCAL CLOCK
	fudge 127.127.1.0 stratum 0
	
	driftfile  /var/lib/ntp/ntp.drift

Then restart the service. Your ntp server is available. ###Client Configuration Enable saned to enable ntp client on beaglebone:

	# error message
	[....] Starting NTP server: ntpdsaned disabled; edit /etc/default/saned
	vim /etc/default/saned 
	# Set to yes to start saned
	RUN=yes

Then we have to enable the ntp client’s configuration:
For Client manually synchornize

	root@arm:~# ntpdate 10.0.0.1
	 1 Jan 05:18:55 ntpdate[2243]: the NTP socket is in use, exiting
	root@arm:~# ps -ef | grep ntp
	ntp       1805     1  0 04:30 ?        00:00:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 107:112
	root      2245  2127  0 05:19 pts/0    00:00:00 grep ntp
	root@arm:~# kill 1805
	root@arm:~# date
	Sat Jan  1 05:19:05 UTC 2000
	root@arm:~# ntpdate 10.0.0.1
	12 Dec 07:38:44 ntpdate[2247]: step time server 10.0.0.1 offset 440129967.397166 sec
	root@arm:~# date
	Thu Dec 12 07:38:46 UTC 2013

The client configuration for ntp, remove all of the possible server, use LAN server:

	server 10.0.0.1

tzselect will set the timezone of the equipment. The result is:

	TZ='Asia/Shanghai'; export TZ

Add it into the ~/.profile, then your time will be adjusted to Shanghai Time. ###Update time via http Since I located in UMT+8, I will use following commands for sync the time

	date $(wget -O - "http://www.timeapi.org/utc/in+eight+hours" 2>/dev/null | sed s/[-T:+]/\ /g | awk '{print $2,$3,$4,$5,".",$6}' | tr -d " " )

Then add it to crontab

	root@OpenWrt:~# cat /bin/time.sh 
	#!/bin/sh
	#echo $http_proxy
	#echo $https_proxy
	date $(wget -O - "http://www.timeapi.org/utc/in+eight+hours" 2>/dev/null | sed s/[-T:+]/\ /g | awk '{print $2,$3,$4,$5,".",$6}' | tr -d " " )

The crontab -e should like following:

	* */3 * * * /bin/time.sh

This means every 3 hours the script will be called for synchronizing the time.
Now we can enjoy the precise time from the internet and make it availale for the service on LAN.

Western Digital Green Disk on Ubuntu

The WD20EARS (and other sizes include 1.0 and 1.5 TB driver in the series) will attempt to park the read heads once every 8 seconds FOR THE LIFE OF THE HDD which is just horrible! To see if you are affected use the smartctl command (part of smartmontools). If the last column changes rapidly, this section applies to your drive.

	# smartctl /dev/sdb -a | grep Load_Cycle
	193 Load_Cycle_Count        0x0032   001   001   000    Old_age   Always       -       597115	

We have to disable this feature. Add lines to /etc/rc.local

	hdparam -S 242 /dev/sda
	exit 0

The effect for upper comand is listed as:

	# hdparm -S 242 /dev/sda
	/dev/sda:
	 setting standby to 242 (1 hours)

By default the disk will standby when 1 hours reached, that will avoid our disk from broken.

BBBlack编译脚本解析

###Preparation Download the “linux-dev” repository from github:

	git clone git://github.com/RobertCNelson/linux-dev.git

View the downloaded packages:

	[Trusty@XXXyyy mykernel]$ du -hs linux-dev/
	19M	linux-dev/
	[Trusty@XXXyyy linux-dev]$ ls
	build_deb.sh  build_kernel.sh  build_mainline.sh  LICENSE  patches  patch.sh  README  repo_maintenance  scripts  system.sh.sample  tools  version.sh

Switch to the 3.12 Branch:

	git checkout origin/am33x-v3.12 -b tmp
	[Trusty@XXXyyy linux-dev]$ ls
	build_deb.sh  build_kernel.sh  LICENSE  patches  patch.sh  README  repo_maintenance  scripts  system.sh.sample  tools  version.sh

###Walk by lines Since we call ./build_kernel.sh will initialize the building, we will first see what’s in this file
a. Create the deploy directory, Line 23-Line 25

	DIR=$PWD
	mkdir -p ${DIR}/deploy/

Then the code goes to line 189, since all of the code between 25-189 are functions.

	/bin/sh -e ${DIR}/tools/host_det.sh || { exit 1 ; }

This line will call tools/host_det.sh to detect the host, the result is listed:

	[Trusty@XXXyyy linux-dev]$ tools/host_det.sh 
	which: no lsb_release in (/home/Trusty/.rvm/gems/ruby-1.9.3-p448/bin:/home/Trusty/.rvm/gems/ruby-1.9.3-p448@global/bin:/home/Trusty/.rvm/rubies/ruby-1.9.3-p448/bin:/home/Trusty/.rvm/bin:/media/y/embedded/cortex/gcc-arm-none-eabi-4_7-2013q3/bin:/home/Trusty/perl5/bin:/opt/cross/bin:/media/y/u-boot/4.3.2/bin/:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/usr/bin/site_perl:/usr/bin/core_perl)
	+ Detected build host []
	+ host: [x86_64]
	+ git HEAD commit: [858e7dbdedcb5d85d0e3b84323c5a6bfe6bd3b5e]
In host_det.sh, the code lines between 6~381 are all functions, till line 381. 
	if [ $(which lsb_release) ] ; then
	         info "Detected build host [`lsb_release -sd`]"
Following is the lsb_relase result, lsb_release is the linux standard base base package, which will provide enough infomations of the installed linux system. 
	$ lsb_release
	LSB Version:	:core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
	[Tomcat@MisteryPlace:  [] /opt/home/Tomcat]                                                                                        $ lsb_release -sd
	"Scientific Linux SL release 5.5 (Boron)"
	[Tomcat@MisteryPlace:  [] /opt/home/Tomcat]                                                                                        $ uname -m
	i686

Testing the host and the git head commit

	info "host: [`uname -m`]"
	info "git HEAD commit: [`git rev-parse HEAD`]"

This script is for testing the known hosts which runs redhat/debian/suse, and verify if you have installed all of the package need to support kernel build.

Copy the system.sh.sample to current directory

if [ ! -f ${DIR}/system.sh ] ; then
	cp ${DIR}/system.sh.sample ${DIR}/system.sh

Next lines from 199 to 218 is to detect if the branches.list and branch.expired exists, if exists then some testing will be done.

	if [ -f "${DIR}/branches.list" ] ; then
		echo "-----------------------------"
		echo "Please checkout one of the active branches:"
		echo "-----------------------------"
		cat ${DIR}/branches.list | grep -v INACTIVE
		echo "-----------------------------"
		exit
	fi

Then go to line 220 and 221, unset 2 system variable

	unset CC
	unset LINUX_GIT

Then run system.sh

	. ${DIR}/system.sh

Then we will prepare the gcc.

	/bin/sh -e "${DIR}/scripts/gcc.sh" || { exit 1 ; }
Switching to scripts/gcc.sh, the following lines will set the system variables, which will be used to choose the suitable linaro toolchain. 
	. ${DIR}/system.sh
	
	#For:
	#linaro_toolchain
	. ${DIR}/version.sh
Test the CC existence, if not then start building:
	if [ "x${CC}" = "x" ] && [ "x${ARCH}" != "xarmv7l" ] ; then
		gcc_linaro_toolchain
	fi

The code are funny, because echo x${CC} is actually x , so the gcc_linaro_toolchain will surely be called.

	$ echo ${linaro_toolchain}
	cortex_gcc_4_8

The variable {linaro_toolchain} is set via . version.sh, then the corresponding code lines will be called

		cortex_gcc_4_8)
			#https://launchpad.net/linaro-toolchain-binaries/+download
			#https://launchpad.net/linaro-toolchain-binaries/trunk/2013.10/+download/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux.tar.xz
	
			gcc_version="4.8"
			release="2013.10"
			toolchain_name="gcc-linaro-arm-linux-gnueabihf"
			site="https://launchpad.net/linaro-toolchain-binaries"
			version="trunk/${release}"
			directory="${toolchain_name}-${gcc_version}-${release}_linux"
			filename="${directory}.tar.xz"
			datestamp="${release}-${toolchain_name}"
			untar="tar -xJf"
	
			binary="bin/arm-linux-gnueabihf-"
			;;
		*)
			echo "bug: maintainer forgot to set:"
			echo "linaro_toolchain=\"xzy\" in version.sh"
			exit 1
			;;

dl_gcc_generic will be called. download the corresponding packages from the linaro website.

After set the cross-compiler, we can get the kernel using git.sh, the git.sh is listed in scripts/git.sh

	/bin/sh -e "${DIR}/scripts/git.sh" || { exit 1 ; }

In git.sh, detect the user’s email and user’s name:

	unset git_config_user_email
	git_config_user_email=$(git config --get user.email || true)
	
	unset git_config_user_name
	git_config_user_name=$(git config --get user.name || true)

Then set using http or git, call git_kernel to git clone the corresponding resources from github.
git_kernel will call check_and_or_clone() to get the source code from the github.

	git clone ${torvalds_linux} ${DIR}/ignore/linux-src

and set the LINUX_GIT variable to

	LINUX_GIT="${DIR}/ignore/linux-src"

The downloaded packages are so large, that it occupies 1.4G disk space.

	[Trusty@XXXyyy ignore]$ du -hs *
	1.4G	linux-src