顯示具有 Linux-Debian-進階其他 標籤的文章。 顯示所有文章
顯示具有 Linux-Debian-進階其他 標籤的文章。 顯示所有文章

2015年12月7日 星期一

GitHub/GitLab 分散式版本控管之指令整理

PM 實驗室之 GitLab (限校內 ip):http://120.117.72.71/
教學:http://blog.gogojimmy.net/2012/01/17/how-to-use-git-1-git-basic/
---
PM GitLab 實作範例:
‧ 上傳一個已完成之專案:
  1. 登入 GitLab (http://120.117.72.71/) → 進入/建立 Group (請整齊分類)
  2. 新增 Projects:
    1. 輸入 Project path:JAVA-CustomizablePizza
    2. 輸入Description:簡單說明…
    3. 權限(設內部會員可使用):Internal Project
  3. 至本機下載剛創立的 Git 專案:
    1. 選擇「HTTP」取得網址
    2. 本機下指令: git clone git@120.117.72.71:$USER/javaProject.CustomizablePizza.git
  4. 上傳做好的程式及檔案至 GitLab 的 javaProject.CustomizablePizza 專案:
    1. cd javaProject.CustomizablePizza.git
    2. cp ../CustomizablePizza .
    3. cp ../CustomizablePizza_v5.jar .
    4. cp ../README.md .
    5. git add .
    6. git commit -m "Java Project Customizable Pizza - OK"
    7. git push -u origin master
  5. master 下的後續更新:
    1. touch file1
    2. git add 
    3. git commit -m "add file1"
    4. git push -u origin master
  6. 建立新分支(版本)來加入新功能或 Debug
    1. git branch → 查看目前所在分支
    2. git branch TEST → 建立一個新分支名稱為 TEST
    3. git checkout TEST → 切換至分支 TEST
    4. git branch → 檢查所在分支
    5. edit file → 變動、更新檔案(原 master 下檔案不會被變動)
    6. git add <file>
    7. git commit -m "new message"
    8. git push -u origin TEST → 至 GitLab 會發現有新版本 TEST
  7. 合併分支至主版本 master (確定所增功能或 Debug 版本完成再做)
    1. git checkout master → 會發現剛剛所編的 file 不見為正常,因為是不同 branch
    2. git merge TEST → 可以 ls 又發現剛剛所編檔案合併過來了,接著只要上傳至 GitLab
    3. git add .
    4. git commit -m "Combine TEST and master"
    5. git push -u origin master → 此時可能會提示訊息要使用 git pull
    6. git pull
    7. 登入 GitLab 查看完成
---

  • 將私人專案共享至 Group 的方法


  1. 換入 GitLab
  2. Projects → 選則要共享的專案
  3. Settings → Project Settings → 「Transfer project」→ 選擇所要加到的 Group
  4. 輸入提示字串(粉底紅字) → 按 CONFIRM → 完成。

---
零、安裝 Git:
‧ Mac : 安裝 Homebrew
‧ Linux(APT):apt-get install git-core
‧ Linux(YUM):yum install git-core
‧ Windows:安裝 msysGit
---
壹、設定 Git UI
‧查看設定:
 git config --list

‧可以記錄 git commit 提交的作者資訊:
 git config --global user.name "廖凱霖"
 git config --global user.email "ma330101@stust.edu.tw"

‧自訂指令 alias 功能(git status → git st):
git config --global alias.st status

‧設定 git 自動忽略’空白’的變化(適需求而定):
git config --global apply.whitespace nowarn

‧設定 git 輸出加入顏色變化:
 git config --global color.ui true
---
貳、常用上傳基本指令:

‧ 查看 Git 狀態: 
git status

‧ git add 加入 stage 狀態(-i 互動模式): 
git add <File>
git add -i <File>

‧ git commit 提交 (-m 加入訊息)(-v 列出更動記錄): 
git commit
git commit -m <Message>
git commit -v

‧ 查過去記錄(更詳細過去 --stat)(-p 檔案詳細記錄)
git log
git log --stat
git log -p

‧ push 上傳流程:
1. mkdir workDirectory
2. git init
3. git remote add origin http://120.117.72.71/fate615030/gitProject.git
4. git add <File>
5. git commit -m “<Message>"
6. git push -u <remote> <branch> → 例如: git push -u origin master

‧ 讓 Git 忽略版本控制的追蹤(編輯檔案加入要忽略的檔名):
vim .gitignore 
---
參、第一次使用 Git
‧自建一個新的資料庫( Repository)

1. 建立一個目錄: mkdir gitProject
2. 進入目錄:  cd gitProject
3. git init
4. 輸出告訴我們建立好了一個新的 Git Repository 。
→ Initialized empty Git repository in /UsersPath/gitProject/.git/

‧複製別人的 Git Repository
git clone http://120.117.72.71/fate615030/gitProject.git
---
肆、管理分支(Branch):
‧ 安裝圖形化介面 GitGUI: 
sudo apt-get install gitk
gitk --all

‧ 查看分支(本機、-r 遠端、-a 全部): 
git branch
git branch -r
git branch -a

‧ 加入一個新分支名為 cat: 
git brach cat

‧ 切換至 cat 分支:
git checkout cat

‧ 建立新分支並切換過去: 
git checkout -b "branch名稱"

‧ 刪除分支:
 git branch -d "branch 名稱"

‧ 分支整理(cat 會保留並加到master):
git rebase master

‧ 分支完全合併:  
git merge cat

‧ 查看不同分支差異:  
git diff cat master

‧ 取消上一次合併 merge: 
git reset --hard ORIG_HEAD
---
伍、當合併 branch 發生衝突(conflict):
1. 將發生 conflict 的檔案打開,處理內容( 別忘了刪除<<<、===、>>> )。
2. 使用 git add 將處理好的檔案加入 stage(git add)。
3. 反覆步驟 1~2 直到所有 confict 處理完畢。
4. git commit 提交合併訊息。
5. 完成
---
陸、反回功能:
‧ 取消上一次 merge:  
git reset --hard ORIG_HEAD

‧ 取消暫存檔案(add):  
git reset HEAD <file>

‧ 放棄檔案修改(回到上次 commit): 
git checkout -- <file>

‧ 修改 commit 訊息:  
git commit --amend

‧將檔案1、檔案2加入上次 commit: 
git commit --amend 檔案1 檔案2 …

‧ 回複上一個 commit 版本:  
git reset --hard HEAD^

‧ 回複上兩個 commit 版本:  
git reset --hard HEAD~2

‧取消 commit,但保留修改過檔案: 
git reset HEAD^ --soft
---
柒、遠端 Git
‧建立一個 tracking 遠端
branch git branch --track <branch名稱> <遠端branch>

‧將已存在的 branch 設定成遠端 
git branch --set-upstream <branch> <遠端branch>

‧刪除一個 tracking 的遠端
branch git -r -d <遠端branch>

‧刪除一個 repository 的 branch 
git push <repository名稱> :<遠端branch>

‧加入一個 remote repository  
git remote add <remote名稱> <remote網址>

‧下載遠端的 branch 並合併至本機 
git pull <remote名稱> <branch名稱>

‧本機上傳至遠端的 branch  
git push <remote名稱> <branch名稱>
---
捌、Git 整體工作規程:
1. 在專案中會有一條主 branch 是大家將開發好或是修好的東西合併回去的對象,所有要開發的新功能或是修 bug 都是從主 branch 拉出一條新的 branch 去工作。

2. 當你完成一個階段性的任務時,將你剛剛 所新增的內容使用 git add 加入到 stage 的狀態,並且使用 git commit 加上 commit 的訊息來提交一次的 commit。

3. 反覆動作 2 直到你完成這支 branch 的主要目的(新功能/修 bug ),若這時你離主 branch 已經有一段時間,或是確定主 branch 上已經有新的 commit ,使用 git rebase 將自己的分支整理然後使用 git merge 合併回主 branch,反之則是直接使用 git merge 將自己 branch 的內容合併回去。




2015年8月25日 星期二

PXE Automated Install OS(Preseed)


影片Demo:https://youtu.be/_tEx_A1ZzBU


一、Mirror 鏡像站

1. 準備 200 GB 以上之硬碟空間,並建立裝鏡像站之目錄
mkdir -p /home/ftp

2. 寫一個 getdeb.sh
# 選擇一個外站來下載
HOST=ftp.tw.debian.org
#HOST=debian.nctu.edu.tw
#HOST=opensource.nchc.org.tw
#HOST=ftp.wa.au.debian.org
#HOST=120.117.72.71
#HOST=ftp.debian.org

debmirror \
        --arch=i386,amd64,armel,armhf,sha4 \
        --dist=jessie,jessie-updates \
        --di-arch=i386,amd64,armel \
        --di-dist=stable \
        --host=$HOST \
        --root=":debian" \
        --diff=none -p \
        --nosource \
        --method=rsync \
        --section main,contrib,non-free,main/debian-installer \
        --i18n \
        --ignore-release-gpg /home/ftp/debian/ ;

        #--section non-free,contrib,main,main/debian-installer,main/installer-armel,main/i18n,main/source \
#debmirror \
#       -v --nosource -d lenny/updates -a i386 \
#       -s non-free,contrib,main,main/debian-installer \
 #    --method=http -h security.debian.org \
 #    --ignore-release-gpg -r /debian-security /home/ftp/debian/security/
#       --section main,contrib,non-free,main/debian-installer,main/installer-armel,main/i18n,main/source \

#wget -r -l1 -nH ftp://$HOST/debian/dists/squeeze/main/source/
date

3. 將鏡像站載到 /home/ftp/debian 目錄下 
sh getdeb.sh

4. 修改/home/ftp/debian所有檔案權限
DIR=/home/ftp/debian
chown root.root -Rv $DIR
chmod ug-s -Rv $DIR
find $DIR -type -d -exec chmod 755 {} +
find $DIR -type -f -exec chmod 644 {} +

5. 修改 sources.list 檔:
cat >> /etc/apt/sources.list << EOF
deb ftp://localhost/debian jessie main contrib non-free
 deb-src ftp://localhost/debian jessie main contrib non-free
EOF

6. 測試更新
apt-get update

7. 若出現 installer 或 source… 缺少檔案,請自行去別的鏡像站補檔案到對應的目錄。
=============================================================

二、建立私有網路 192.168.10.0/24

1. 將建置環境之對外網路線先移除,
其他含有 DHCP Server 相關的設備也移除 (例如 WiFi 基地台)。

2. PXE Server 端,修改網路設定
vi /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

########## Eth0/DHCP ##########
#allow-hotplug eth0
#iface eth0 inet dhcp

########### PXE Server Machine ##########
allow-hotplug eth0
iface eth0 inet static
        address 192.168.10.254
        netmask 255.255.255.0
        network 192.168.10.0
        broadcast 192.168.10.255
        gateway 192.168.10.1

3. 重啟網卡
/etc/init.d/networking restart

4. 確認網路設定成功,若沒有出現 ip:192.168.10.254,再多重啟幾次。
/sbin/ifconfig
=============================================================

三、FTP / NFS /HTTP Server(擇一,本例使用 FTP)

‧FTP Server

1. 安裝
sudo apt-get install proftpd-basic

2.修改設定檔 /etc/proftpd/proftpd.conf
 sudo vi /etc/proftpd/proftpd.conf

搜尋 Anonymous ,解除註解,完成如下結果:
<Anonymous ~ftp>
   User                         ftp
   Group                                nogroup
   # We want clients to be able to login with "anonymous" as well as "ftp"
   UserAlias                    anonymous ftp
   # Cosmetic changes, all files belongs to ftp user
   DirFakeUser  on ftp
   DirFakeGroup on ftp

   RequireValidShell            off

   # Limit the maximum number of anonymous logins
   MaxClients                   10

   # We want 'welcome.msg' displayed at login, and '.message' displayed
   # in each newly chdired directory.
   DisplayLogin                 welcome.msg
   DisplayChdir         .message

   # Limit WRITE everywhere in the anonymous chroot
   <Directory *>
     <Limit WRITE>
       DenyAll
     </Limit>
   </Directory>

   # Uncomment this if you're brave.
   # <Directory incoming>
   #   # Umask 022 is a good standard umask to prevent new files and dirs
   #   # (second parm) from being group and world writable.
   #   Umask                            022  022
   #            <Limit READ WRITE>
   #            DenyAll
   #            </Limit>
   #            <Limit STOR>
   #            AllowAll
   #            </Limit>
   # </Directory>

 </Anonymous>

3.修改 /etc/passwd 設定
 sudo vi /etc/passwd

搜尋 ftp ,將其中的目錄路徑改為自訂 FTP 目錄 (例如: /home/ftp)
瀏灠器測試 ftp://192.168.10.254
-------------------------------------------------------------------------------------------------

‧NFS Server


‧PXE Server
1. 安裝 
sudo apt-get install nfs-kernel-server

2. 設定 
sudo vi /etc/exports
/srv/nfs 192.168.10.0/24(rw,no_root_squash,async,no_subtree_check)

3. 重啟
exportfs -rav
/etc/init.d/nfs-kernel-server restart

4. 檢查 
showmount -e localhost
正確輸出:
Export list for localhost:
/srv/nfs 192.168.10.0/24

‧NFS Client
1. Client 端套件安裝
sudo apt-get install nfs-common

2.建立掛載 NFS 目錄
mkdir -p /dev/nfs

3. 手動掛載 
mount -t nfs -nolock 192.168.10.1:/srv/nfs /dev/nfs
-------------------------------------------------------------------------------------------------

‧HTTP Server

1. 安裝
sudo apt-get install apache2

2. 修改 
vi /etc/apache2/apache2.conf`
<Directory /home/ftp>
        Options Indexes
        AllowOverride None
        Require all granted
</Directory>

3. 修改 
vi /etc/apache2/sites-available/000-default.conf`
 #DocumentRoot /var/www/html
 DocumentRoot /home/ftp

4. 重啟 
/etc/init.d/apache2 restart
=============================================================

四、DHCP Server

1. 安裝
sudo apt-get install isc-dhcp-server

2. 設定
vi /etc/dhcp/dhcpd.conf
option domain-name "example.org";
option domain-name-servers 120.117.2.1;
#option domain-name-servers 8.8.8.8;

default-lease-time 600;
max-lease-time 7200;
allow booting;

subnet 192.168.10.0 netmask 255.255.255.0{
        range 192.168.10.100 192.168.10.200;
        option subnet-mask 255.255.255.0;
        option broadcast-address 192.168.10.255;
        option routers 192.168.10.1;
        option domain-name-servers 120.117.2.1;
        next-server 192.168.10.254;
        filename "pxelinux.0";
}

3. 重啟
/etc/init.d/isc-dhcp-server restart
systemctl enable isc-dhcp-server
systemctl status isc-dhcp-server
=============================================================

五、TFTP Server

1. 安裝
sudo apt-get -y install tftpd-hpa

2.設定
vi /etc/default/tftpd-hpa
TFTP_RUN_DAEMON="yes"
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"

3. 下載開機套件
wget http://ftp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/netboot.tar.gz

4. 確立 /srv/tftp 目錄存在
mkdir -p /srv/tftp

5. 解壓至 tftp 目錄 
tar xfva netboot.tar.gz -C /srv/tftp

6. PXE 開機選單訊息(自行定義)  
vi /srv/tftp/boot.msg
        =========================
        |            INSTALL MENU              |
        =========================

        Choose installation type:

        0  Local Boot(Default)
        1  PXE Manual Install Debian/Jessie
        2  PXE Automated Install Debian/Jessie
        =========================

7. 原檔備份
mv /srv/tftp/pxelinux.cfg/default /srv/tftp/pxelinux.cfg/default.bak

8. PXE 開機選單  
vi /srv/tftp/pxelinux.cfg/default
DISPLAY boot.msg
PROMPT 1
timeout 3000

default 0

LABEL 0
        localboot 0

LABEL 1
        kernel debian-installer/amd64/linux
        append vga=normal initrd=debian-installer/amd64/initrd.gz --

LABEL 2
        kernel debian-installer/amd64/linux
        append vga=normal initrd=debian-installer/amd64/initrd.gz auto=true priority=critical url=http://192.168.10.254/preseed.cfg interface=eth0

9. 權限o+rx  
chmod -Rv 755 /srv/tftp

10. 重啟
 /etc/init.d/tftpd-hpa restart
 update-rc.d tftpd-hpa defaults
 systemctl enable tftpd-hpa
=============================================================

六、自動安裝設定 Preseed

#http://www.unt.edu/benchmarks/archives/2008/may08/auto_install_howto-2.pdf
#https://www.youtube.com/watch?v=YT7qUoEw0BY
#http://pastebin.com/jadh4U5n
#https://www.debian.org/releases/jessie/example-preseed.txt


 vim /home/ftp/preseed.cfg

#https://www.debian.org/releases/jessie/example-preseed.txt
# Localization
d-i debian-installer/locale string en_US
d-i console-keymaps-at/keymap select us
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select us
d-i keyboard-configuration/layoutcode string us

 # Networking
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

 # APT Mirror
d-i mirror/country string enter information manually
d-i mirror/http/hostname string ftp://192.168.10.254
d-i mirror/http/directory string /debian
#d-i mirror/suite string default
d-i mirror/http/proxy string

 # Timezone / Time
d-i clock-setup/utc boolean false
d-i time/zone string Asia/Taipei
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server tick.stdtime.gov.tw

 # Partitoning
# # https://wikitech.wikimedia.org/wiki/PartMan/Auto 
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
#    
d-i partman-auto/expert_recipe string   \
root ::                                 \
        5000 25000 -1 ext4              \
        $primary{ }                     \
        $bootable{ }                    \
        method{ format }                \
        format{ }                       \
        use_filesystem{ }               \
        filesystem{ xfs }               \
        mountpoint{ / }                 \
        .                               \
        1024 2048 8192 linux-swap       \
        $primary{ }                     \
        method{ swap }                  \
        format{ }                       \
        .

d-i partman-auto/choose_recipe select root
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean false
d-i partman/choose_partition select "Finish partitioning and write changes to disk"

# Grub Install
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev  string /dev/sda

# Account(s) setup
# ROOT
d-i passwd/root-login boolean true
d-i passwd/root-password password abc123
d-i passwd/root-password-again password abc123
# USER
d-i passwd/make-user boolean true
d-i passwd/user-fullname string student
d-i passwd/username string student
d-i passwd/user-password password abc123
d-i passwd/user-password-again password abc123
d-i user-setup/allow-password-weak boolean true
#d-i passwd/user-default-groups string users,audio,cdrom,video
#d-i passwd/user-uid string 1001

# tasksel / extra APT packages
#tasksel tasksel/first multiselect standard
tasksel tasksel/first multiselect minimal
d-i pkgsel/include string \
ssh sshpass sudo aptitude vim ntp rsync

popularity-contest popularity-contest/participate boolean true

# run shell script
d-i preseed/late_command string                         \
in-target wget ftp://192.168.10.254/env.sh -P /root/;   \
in-target /bin/chmod 700 /root/env.sh;                  \
in-target /bin/sh /root/env.sh

=============================================================

七、新機環境設定

自訂義於 /home/ftp/env.sh

#!/bin/bash
# KLin
# 2015/08/25

USER=student

# login directory: /root
cd /root/

# APT Package updates
#apt-get update

# sshd server
#apt-get -y install ssh sshpass rsh
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
mkdir -p /root/.ssh

## 使用 `ssh-keygen` 指令生成公鑰,Copy 起來
#cat >> /root/.ssh/authorized_keys << EOF
#ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLDfPtWH2zTq92nfsml5i6agoXWQRBzsb9VJzKGwY/jyPfyIL7rl+Q#hD4oGxDLW3pNmtflAkQ3/X3W8j/o7tW14Sdw2eW5HRl2Um2eSa9q2BWHbzT464R+xlGgAI3iUH0yPRgW602EYzeCZi3/#8zSoVHMVrjsZyjOzz5n+EFbNsirVtSOndF9iXa2ByT1GuxjOobBWoIue5/1jb7B8pG6QlRAf6kz0x/1xLWASiBmMaLPf#mHbQ5xvgBFbSOQTTG7vRevuVrpBaUdEHEGiRMY4TS8o/2bOzAoCa9hgCcxb1N3Ys/AKbwU00yWGUSKqhTK93tpbSsUmG#34MaDGmMWmfz root@KaiLin

#ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCllLrsVt7koI6q/erYCUubKW2fxHRGYB4xYkY7LacPxiSexnvrX6yk#vRQbWcEOtNig2SXZJ6NwJWIDnkAfehVLbYWSu1S4MfPMzPLQVQryAQxf3oajyLAg+D64QGeBfDmScJ0LIBwPJq9/oqSI#4QgiMUXjj+9kBn6VBzGaB9h2u6AN1YYRJYJbKHFt4mxiqbXuXalw2fC0VWoerp9La9weozvCWOXeuxL6SCYPyTcIDqQ7#t9hSvH93af6HqNtcBr0WzmrYdrVRyNW5KbCD0IFf35yOogzrAon86MVjReVAF2gLHnFYz+bjH4DstcRAAZgJTvT4HGuA#cGqrfXf11RhZ root@120-117-73-86
#EOF

# Black List
cat >> /etc/modprobe.d/fbdev-blacklist.conf << EOF 
blacklist nouveau
blacklist nv
blacklist ast
EOF

# Setting `sudo` 
echo "$USER     ALL=(ALL:ALL) ALL" >> /etc/sudoers

# .bashrc & .vimrc
for ACCOUNT in /root /home/$USER
do
# set .bashrc
cat >> $ACCOUNT/.bashrc << EOF
# Language Setting "zh.TW.UTF-8"
export LC_ALL=zh_TW.UTF-8
export LANG=zh_TW.UTF-8
export LANGUAGE=zh_TW.UTF-8

# define more command aliases
alias ls='ls -F --color=auto'
alias l='ls -lF --color=auto'
alias ll='ls -lF --color=auto'
alias lt='ls -lt --color=auto'
alias la='ls -aF --color=auto'
alias lh='ls -lhF --color=auto'
alias lz='ls -lZF --color=auto'
alias grep='grep --color=auto'
alias vi='vim'
alias df='df -h'
alias ifconfig='/sbin/ifconfig'
EOF

# set .vimrc
cat >> $ACCOUNT/.vimrc << EOF
set hlsearch
set bg=dark
syntax on
EOF
done

# end test
touch /root/env_run.ok

# Other shell...

=============================================================

八、遠端控制 rsh + sshpass

※ 注意,使用 rsh  時,Server 與 Client 必需有相同之使用者帳號,
若 Server 端使用 root 權限,則 rsh 所執行的指令於 Client 端也為 root 權限。

1. 於 server 端發遠端指令的方法參考 http://jamyy.us.to/blog/2013/08/5260.html 

2. 安裝
apt-get install sshpass rsh

3. 遠端 ssh 第一次,無需打 yes ,自動更新 known_hosts 檔方法:
建一設定檔於 PXE Server 端: /root/.ssh/config
StrictHostKeyChecking no

4 遠端下指令,注意目前執行 rsh 的使用者權限:
sshpass -p <密碼> rsh <主機 IP> <指令> &

※令 ssh 連線無需輸入密碼
於 PXE Server 端,指令` ssh-keygen `產生 public key ,
並 copy 至 Client 端:/root/.ssh/authorized_keys (自行建立)的檔案內。

=============================================================

九、Reference:

http://www.unt.edu/benchmarks/archives/2008/may08/auto_install_howto-2.pdf 

https://raymii.org/s/articles/virt-install_introduction_and_copy_paste_distro_install_commands.html 

http://www.tecmint.com/multiple-centos-installations-using-kickstart/# 

http://ubuntuforums.org/showthread.php?t=1463142 

http://www.syslinux.org/wiki/index.php/Comboot/menu.c32 

http://wiki.hackzine.org/sysadmin/debian-pxe-server.html 

http://www.iram.fr/~blanchet/tutorials/read-only_diskless_debian7.pdf 

https://www.debian.org/releases/jessie/amd64/ch04s05.html.en 

https://www.debian-administration.org/article/478/Setting_up_a_server_for_PXE_network_booting 

http://linux.vbird.org/somepaper/20100901-pxe_ks.pdf 

http://linux.vbird.org/somepaper/20101020-pxe_ks_2.pdf

https://help.ubuntu.com/community/DisklessUbuntuHowto 

https://www.debian.org/releases/jessie/example-preseed.txt 

2015年6月28日 星期日

QEMU VFIO實作

實作VFIO首先要先確定你的硬體是否有支援
  • Intel的CPU要有支援VT-D
  • AMD的CPU要有支援AMD-VI
  • 主機板也是要選用有支援VT-D/AMD-VI功能,才可以使用VFIO功能
我的電腦是Intel的E3-1230V2,以下用Intel的CPU為例
直接去Intel官網查CPU型號,找到以下技術且為YES就表示你的CPU有支援VT-D


 
接下來就要看主機板有沒有支援VT-D/AMD-VI,以國內4家華碩、微星、技嘉、華擎來說
依我使用的是Z77/H77晶片為例
  • 華碩:BIOS完全沒有支援VT-D功能,要X79、X99等級以上才有
  • 微星:BIOS大部份都有支援VT-D
  • 華擎:BIOS大部份都有支援VT-D
  • 技嘉:BIOS少部份支援,如UD5H、D3H等,剩下也是要X79、X99等級以上才有
以上主機板是我從網路找出來稍微整理的,所以除非你要買到伺服器級的主機板
不然BIOS想要有VT-D功能建議買微星或華擎的

#確定你硬體都有支援後在開始實作VFIO功能

########################################################

1. 把核心有關VFIO的都編譯起來之後重開機

2. 在/etc/modules加入以下模組

pci_stub
vfio
vfio_iommu_type1
vfio_pci
kvm
kvm_intel

3. 在/etc/default/grub加入以下參數
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1"

4. 執行以下指令
# update-grub

5. 重新開機
# shutdown -r now

接下來要設定給QEMU使用的顯卡

1. 使用 lspci -nn 觀察你所安裝的顯卡
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation G98 [GeForce 8400 GS Rev. 2] [10de:06e4] (rev a1) <-- HOSTGPU: 8400GS
02:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:13c2] (rev a1) <-- GUESTGPU: GTX 970
02:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:0fbb] (rev a1) <-- GTX 970 aduio

2. 在/etc/initramfs-tools/modules加入QEMU要用的GPU,如下指令
pci_stub ids=10de:13c2,10de:0fbb

3. 再執行以下指令
# update-initramfs -u

4. 重新開機
# shutdown -r now

5. 輸入 dmesg | grep pci-stub 指令後,會看到底下訊息
[    1.834707] pci-stub: add 10DE:13C2 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[    1.834715] pci-stub 0000:02:00.0: claimed by stub
[    1.834720] pci-stub: add 10DE:0FBB sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[    1.834724] pci-stub 0000:02:00.1: claimed by stub

6. /etc/vfio-pci.cfg 建立這檔案,並加入在上面使用 lspci -nn 查到的顯卡
0000:02:00.0
0000:02:00.1

7. 接下來建立啟動虛擬機的script檔,我的script檔叫vm1
#!/bin/bash

configfile=/etc/vfio-pci.cfg
MEMORY=4096
HDA=win8.img
MAC="DE:AD:BE:CF:EC:B9"
BRIDGE=br10
VGA=02:00.0


vfiobind() {
    dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id


 }

modprobe vfio-pci

cat $configfile | while read line;do
    echo $line | grep ^# >/dev/null 2>&1 && continue
        vfiobind $line
done

qemu-system-x86_64 -enable-kvm -m $MEMORY -cpu host,kvm=off \
-smp 4,sockets=1,cores=4,threads=1 \
-vga none  \
-boot c \
-device vfio-pci,host=$VGA,x-vga=on \
-device vfio-pci,host=02:00.1
-drive file=win8.img,format=raw \
-net nic,macaddr=$MAC -net nic,model=e1000 -net bridge,br=$BRIDGE

8. 把vm1權限改成755
# chmod 755 vm1

9. 這樣就可以直接執行vm1
# ./vm1

2015年1月10日 星期六

運用 Bumblebee 啟動 Nvidia Optimus 技術

首先說明,筆者使用硬體:
筆電:Acer V3-772g
系統:Debian Jessie
核心:3.16.7
顯卡:Nvidia GTX-760M
CPU:Intel Core i7-4702MQ
GUI 環境:Icewm


一、設定鏡像站

vi /etc/apt/sources.list
deb http://opensource.nchc.org.tw/debian/ jessie main
deb-src http://opensource.nchc.org.tw/debian/ jessie main

deb http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main

# jessie-updates, previously known as 'volatile'
deb http://opensource.nchc.org.tw/debian/ jessie-updates main
deb-src http://opensource.nchc.org.tw/debian/ jessie-updates main

# jessie-backports, previously on backports.debian.org
deb http://opensource.nchc.org.tw/debian/ jessie-backports main
deb-src http://opensource.nchc.org.tw/debian/ jessie-backports main

## Bumblebee
deb http://http.debian.net/debian wheezy-backports main contrib non-free

二、更新

apt-get update

三、安裝套件
1. 使用 APT 下載
bumblebee
primus
bbswitch-dkms
nvidia-cuda-toolkit
nvidia-driver
nvidia-glx
nvidia-detect
nvidia-settings

apt-get install bumblebee primus bbswitch-dkms nvidia-cuda-toolkit nvidia-driver nvidia-glx nvidia-detect nvidia-settings

2. 手動下載安裝
bumblebee-nvidia

Debian Jessie 載點:

安裝:
dpkg -i bumblebee-nvidia_3.2.1-7_amd64.deb

三、設定檔
1. 第一個要改的 bumblebee
vi /etc/bumblebee/bumblebee.conf 

修改:
Driver=               ->      Driver=nvidia
KernelDriver=nvidia  ->      KernelDriver=nvidia-current
PMMethod=auto         ->      PMMethod=bbswitch

改完要重啟 Bumblebee 
service bumblebeed restart

2. 第二個要改的 grub
vi /etc/default/grub

找到
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
改為
GRUB_CMDLINE_LINUX_DEFAULT="quiet rcutree.rcu_idle_gp_delay=1"

改完記得更新
update-grub

四、加群組
將目前的使用者 $USER 加到 bumblebee 群組中!
usermod -a -G bumblebee $USER

Debug
[ERROR]Cannot access secondary GPU - error: [XORG] (EE) /dev/dri/card0: failed to set DRM interface version 1.4: Permission denied

Solution
dpkg-reconfigure nvidia-kernel-dkms
dpkg-reconfigure bbswitch-dkms
dpkg-reconfigure bumblebee-nvidia

reboot





補充:
查看 Nvidia 設定:
optirun nvidia-settings -c :8

查看 Nvidia 溫度:
optirun nvidia-settings -c :8 -q gpucoretemp -t | tail -n 1






2014年12月30日 星期二

tmpfs 於 Linux 用記憶體當硬碟用 ( RAMDisk)



因為筆者所使用的 Linux 是安裝在 m-SATA 上,
硬態硬碟 SSD 等類型的硬碟有一定的寫入次數限制,
因此我在裝 Linux 時,把一些做 "寫入" 動作高的目錄,
且無需儲存資料的分割區放到 RAM 裡面跑。



一、哪些目錄可以掛載到 tmpfs 中?

本筆者將「暫存用」的區塊掛載到 tmpfs,主要如下:
/tmp
/var/spool
/var/tmp
/var/lib/apt/lists
/var/cache/apt/archives

還有常用的瀏灠器 Chrome、Iceweasel (Firefox) ,
也常常做暫存寫入的動作,
若把它們都移到 tmpfs ,
則理論上可以延長 SSD 或 m-SATA 的壽命。

二、規劃分割區

本筆者使用的硬體規格如下:
Laptop : Acer v3-772g
RAM : 20 GB
m-SATA : 120 GB
HDD (7200 rpm) : 750 GB
HDD2 (5400 rpm) : 1 TB

依我所使用的需求來規劃,設計如下:
黃色區塊為 Linux Debian
白色區塊為 Windows 8.1
灰色區塊為兩系統共用的資料區

三、設定 /etc/fstab

sudo vi /etc/fstab
tmpfs   /tmp                    tmpfs   size=10G,noatime,mode=1777       0 0
tmpfs   /var/spool              tmpfs   size=10G,noatime,mode=1777       0 0
tmpfs   /var/tmp                tmpfs   size=10G,noatime,mode=1777       0 0
tmpfs   /var/lib/apt/lists      tmpfs   size=10G,noatime,mode=1777       0 0
tmpfs   /var/cache/apt/archives tmpfs   size=10G,noatime,mode=1777       0 0

記得測試及檢查,否則下次開機可能會有問題!
mount -a
mount
df -h

四、設定 Iceweasel

1. 開啟 iceweasel 瀏灠器
2. 於網址列輸入:about:config
3. 點擊滑鼠右鍵、new
4. String : browser.cache.disk.parent_directory
5. Value : /tmp

五、設定 Google-Chrom

1. 以下面指令來開 Chrom ,可以用 alias 加到 .bashrc

/opt/google/chrome/google-chrome --disk-cache-dir="/tmp"

2. 修改開啟設定檔

vi /usr/share/applications/google-chrome.deskto

Change
Exec=/usr/bin/google-chrome-stable %U

to
#Exec=/usr/bin/google-chrome-stable %U
Exec=/opt/google/chrome/google-chrome --disk-cache-dir="/tmp" %U

六、接著到家目錄下設定:

cd ~.cache
rm -rf google-chrome mozilla
ln -s /tmp/ google-chrome
ln -s /tmp mozilla








Reference:
http://blog.longwin.com.tw/2011/01/linux-firefox-chrome-ram-2011/

http://allisonxu.pixnet.net/blog/post/22698958-ubuntu-8.10---eeebuntu-2.0--%E8%A8%93%E7%B7%B4%E6%88%91%E7%9A%84%E6%80%AA%E5%92%96%E5%B0%8F%E7%99%BD(eeepc-7

http://blog.longwin.com.tw/2006/01/ram_disk_build_method/

http://linux-wiki.cn/wiki/zh-tw/SSD_(%E5%9B%BA%E6%80%81%E7%A1%AC%E7%9B%98)

http://yblog.org/archive/index.php/11734

2014年10月11日 星期六

DHCP Server

可以自建 Bridge ,並設一個虛擬網段,能給虛擬機使用,
讓虛擬機自動抓到 ip 。
(以下皆需要 ROOT )

1. 安裝
sudo apt-get -y install isc-dhcp-server


2.建立虛擬網段
可以參考 Bridge 建立橋接網路 來建立!

3. 設定 dhcpd.conf
vi /etc/dhcp/dhcpd.conf

subnet 192.168.9.0 netmask 255.255.255.0{
        range 192.168.9.51 192.168.9.100;
        option subnet-mask 255.255.255.0;
        option broadcast-address 192.168.9.255;
        option routers 192.168.9.1;
        option domain-name-servers 120.117.2.1;
        next-server 192.168.9.254;
        filename "pxelinux.0";


4. 重啟 DHCP 服務
/etc/init.d/isc-dhcp-server restart
update-rc.d isc-dhcp-server defaults






2014年10月8日 星期三

Android Compile on Ubuntu (整理中


此篇目的是為了編譯一個 Android source code,
過程中有遇到許多問題,全部都整理在最底部 Debug 區。

一、下載 Android Open Source 

1. 建立一個 Ubuntu-12.04_amd64 環境

下例為 QEMU 虛擬機跑 Ubuntu ,可參考:
安裝 QEMU 虛擬機
建立一個 arm.img 並且可以用虛擬機開機

Ubuntu Official: http://www.ubuntu.com/
Download: ubuntu-12.04.5-desktop-amd64.iso

開啟虛擬機:
qemu-img create ubuntuOS.img 80G

qemu-system-x86_64 -enable-kvm \
-cpu host \
-smp 4 \
-m 4000 \
-hda ubuntuOS.img \
-boot c 
-net nic \
-net bridge,br=br9 &

開始 Ubuntu 安裝…

2. 虛擬機連上網路:

本例使用 Bridge ,可以參考文章 Bridge 建立橋接網路
來讓虛擬機連上網際網路!
之後就可以透過 ssh 連線自己的虛擬機比較方便工作。

### 後面都是虛擬機環境下 ###

3. 下載 Android source code準備

下載 AOSP (Android Open Source Project),
需要準備幾個工具:curlgitpython
sudo apt-get update && apt-get install curl git python

### 接下來後面都用一般 User 權限 ###

4. 設定版本控制系統工具 git 

(於一般User 權限下) 
假設我的使用者帳號:myUser
假設我的 e-mail:myMail@gmail.com
git config --global user.name myUser
git config --global user.email myMail@gmail.com

5. 下載 repo 管理工具

(repo 是 Google所發展出來的工具, 適用於Android之初始化)
(於一般User 權限下)
mkdir ~/bin
echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
source ~/.bashrc

curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

chmod u+x ~/bin/repo


6. repo 設定初始化

(於一般User 權限下)
mkdir ~/android_src ; cd ~/android_src
repo init -u https://android.googlesource.com/platform/manifest

後面的過程中,會出現問題(y/n),只要跟著預設選就行。

7. 開始下載 Source Code 

(需要漫長等待時間!容量近30GB)

cd ~/android_src
repo sync -j核心數


二、Android 核心編譯

1. 裝編譯相關套件
sudo apt-get update && apt-get install libglapi-mesa:i386 git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib gcc-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386

2. 安裝 Open JDK 7
sudo apt-get update && apt-get install openjdk-7-jdk

(於一般User 權限下)
加到可執行路徑:
echo 'export PATH=$PATH:/usr/lib/jvm/java-7-openjdk-amd64/bin' >> ~/.bashrc
source ~/.bashrc

3. 安裝 Java SE 6 JDK
(於一般User 權限下)
Oracle載點:Java SE Development Kit 6u45 ,
記得勾選「Accept License Agreement 」,可能需要會員,
 Ubuntu-12.04_amd64 下,這邊要載 jdk-6u45-linux-x64.bin
chmod u+x ./jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
sudo mv jdk1.6.0_45 /opt

加到可執行路徑:
echo 'export PATH=$PATH:/opt/jdk1.6.0_45/bin' >> ~/.bashrc
source ~/.bashrc

4. 下載 Prebuilt Binaries
要去找自己所使用的手機或硬體廠商所推出的驅動或 Binaries,本例所要編的硬體為 Cubieboard 1 (A10核心)

Web Site:Cubieboard Android 4.0.x Release
Download:Livesuit Program Linux(64bit)

下載會得到一個「LiveSuitV306_For_Linux64.zip」,接著:
unzip LiveSuitV306_For_Linux64.zip
cp LiveSuit_For_Linux64/LiveSuit.run ~/android-src/
cd ~/android-src/
chmod u+x LiveSuit.run
./LiveSuit.run

5. 開始編譯
設定環境參數
cd ~/android
source ~/android/build/envsetup.sh

開始編譯
lunch full-eng
make -j核心數

如果成功會看到下面訊息:


6. 模擬器開啟 Android
./out/host/linux-x86/bin/emulator








<pre class="codeblock prettyprint"></pre>






Debug1.
進入 Ubuntu 進行套件更新時出現:
GPG error: http://www.debian-multimedia.org etch Release: The following signatures couldn't be verified because teh public key is not available: NO_PUBKEY 123456789123456789
Sol 1:
APT 套件安裝管理

Debug2. 
若 apt-get install 安裝時出現訊息:
dpkg: error: configuration error: /etc/dpkg/dpkg.cfg.d/multiarch:1: unknown option 'foreign-architecture
Sol 2:
sudo rm /etc/dpkg/dpkg.cfg.d/multiarch


Debug3.
安裝「編譯相關套件」時,若出現:
E: Unable to locate package mingw32
E: Package 'python-markdown' has no installation candidate
Sol 3:
sudo vim /etc/apt/sources.list

找到鏡像站設定:
deb http://archive.ubuntu.com/ubuntu precise main
在 main 後面加上 universe

Debug4.
執行 ./LiveSuit.run 出現:
<pre class="codeblock prettyprint">Selecting previously unselected package awdev-dkms.
(Reading database ... 153279 files and directories currently installed.)
Unpacking awdev-dkms (from /tmp/awdev-dkms_0.5_all.deb) ...
dpkg: dependency problems prevent configuration of awdev-dkms:
 awdev-dkms depends on dkms (>= 1.95); however:
  Package dkms is not installed.
dpkg: error processing awdev-dkms (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
awdev-dkms</pre>
Sol 4:
<pre class="codeblock prettyprint">sudo apt-get install awdev-dkms</pre>

Debug5.
進行 make ARCH=arm menuconfig,出現:
<pre class="codeblock prettyprint">[scripts/kconfig/mconf] Error</pre>

Sol 5:
<pre class="codeblock prettyprint">sudo apt-get install lib32ncurses5-dev</pre>

Debug 6.
當執行編譯指AT "make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage modules -j核心數",出現:
<pre class="codeblock prettyprint">make: arm-none-linux-gnueabi-gcc: Command not found
/bin/sh: 1: arm-none-linux-gnueabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Error 127
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [scripts] Error 2</pre>

Sol 6:
FriendlyARM下載 arm-toolchain

Debug7.
執行「./build.sh -p sun4i_crane -k 3.0」,出現:
[arch/arm/boot/uImage] Error

Sol 7:
sudo apt-get install u-boot-tools

Debug8.
執行「./build.sh -p sun4i_crane -k 3.0」,出現:
[dhd_linux.o] Error 1
[dhd-cdc-sdmmc-gpl] Error 2

Sol 8:
$ sudo apt-get install git gnupg flex bison gperf build-essential \
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
  libgl1-mesa-dev g++-multilib mingw32 tofrodos \
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

如果還是不行:
1. rm -r /home/user/a10_android/cb-A10/lichee/linux-3.0/modules/wifi/bcm40181/5.90.125.69.2/open-src/src/dhd/linux/dhd-cdc-sdmmc-gpl-3.0.8"
2. rm -r /home/user/a10_android/cb-A10/linux-3.0/modules/wifi/bcm40183/5.90.125.95.3/open-src/src/dhd/linux/dhd-cdc-sdmmc-gpl-3.0.8"

最後解決:
rm -r /home/user/a10_android/cb-A10/lichee/linux-3.0/modules/wifi/usi-bcm4329/v4.218.248.15/open-src/src/dhd/linux/dhd-cdc-sdmmc-gpl-3.0.8

Debug 9.
執行 make -j 4時:
dalvik/CleanSpec.mk:47: * missing separator. Stop.
#### make failed to build some targets (5 seconds) ####

Sol 9:
重開 Terminal,重新執行
source build/envsetup.sh
lunch
選11 apollo_cubieboard-eng
make -j8

Debug10.
執行 make -j4時:
Checking build tools versions...
******************************************************
You are attempting to build with the incorrect version
of java.

Your version is: java version "1.7.0_65".
The correct version is: Java SE 1.6.

Please follow the machine setup instructions at
    http://source.android.com/source/download.html
******************************************************
build/core/main.mk:131: *** stop.  Stop.

Sol 10:
1. java -version 出現「java version "1.6.0_45"」是正確的,
如果不對,就改 ~/.bashrc,加入以下:
export PATH=$PATH:/opt/jdk1.6.0_45/bin

重新載入 ~/.bashrc :
source ~/.bashrc

2. 先做 sudo update-alternatives --config java
以我的為例出現「There is only one alternative in link group java: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java」,代表現在的系統預設沒設對,操作如下(記得ROOT):
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.6.0_45/bin/java 300

sudo update-alternatives --config java
設定預設為「/opt/jdk1.6.0_45/bin/java」

同上,javac 也要改
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.6.0_45/bin/javac 300

sudo update-alternatives --config javac
設定預設為「/opt/jdk1.6.0_45/bin/javac」

Debug11.
執行 make -j 4時,出現一堆:
error: unmappable character for encoding ASCII

Sol:

Debug12.
執行 make -j 4時,
[out/target/common/docs/api-stubs-timestamp] Error

Sol:



Debug12.
執行 make -j 4時,
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
make: *** Waiting for unfinished jobs....

Sol:



Debug13.
執行 time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4,出現:
arm-linux-gnueabi-ld: final link failed: No space left on device
make: *** [.tmp_vmlinux1] Error 1

sol:
硬磁空間不足,清出空間。

Debug14.
執行 time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4,出現:
drivers/built-in.o: In function `static_key_false':
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_start'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_start'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_start'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_start'
make: *** [.tmp_vmlinux1] Error 1

sol 14:
http://linux-sunxi.org/FirstSteps#Building_the_kernel


Debug 15.
執行 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig 出現:
collect2: ld returned 1 exit status
make[1]: *** [scripts/kconfig/mconf] Error 1
make: *** [menuconfig] Error 2


Sol 15.
apt-get install libncurses5-dev

Debug 16. 
android 下執行 make 出現:
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1

Sol 16.
sudo apt-get install lib32ncurses5-dev












Reference:
http://weiwei.pixnet.net/blog/post/31481109-%E7%B7%A8%E8%AD%AFandroid-source-code-%E9%8C%AF%E8%AA%A4%E8%A7%A3%E6%B1%BA%E8%BE%A6%E6%B3%95

https://github.com/crossfire77/Android_Toolchains

http://blog.logan.tw/2011/10/android-open-source-project-android.html

http://blog.logan.tw/2013/09/build-android-aosp.html


Android Official Website:
https://source.android.com/compatibility/downloads.html

Cubieboard Official:
http://cubieboard.org/download/

Cubieboard Open Source:
https://github.com/cubieboard

CC-A80-kernel-source:
https://github.com/cubieboard/CC-A80-kernel-source

http://cubian.org/sources/

http://dywang.csie.cyut.edu.tw/moodle23/dywang/clanguage/node106.html

http://dl.cubieboard.org/software/a10-cubieboard/android/

http://docs.cubieboard.org/tutorials/cb1/installation/building_android_ics_a10_image

http://source.android.com/source/initializing.html

http://persevere.iteye.com/blog/1479524

http://code.google.com/p/metadata-extractor/issues/detail?id=90

http://blog.csdn.net/zeng622peng/article/details/6837250

http://cheng-min-i-taiwan.blogspot.tw/2012/05/ubuntu-1204-64bit-android-ics.html

http://bbs.chinaunix.net/thread-2121093-1-1.html

https://github.com/linux-sunxi/linux-sunxi/issues/150

http://linux-sunxi.org/Toolchain

http://linux-sunxi.org/FirstSteps#Building_the_kernel

http://linux-sunxi.org/Linux_Kernel#A10

Bridge 建立橋接網路 (還有缺,待補中)


1. 安裝套件

sudo apt-get install bridge-utils uml-utilities


2. 常用brctl 橋接指令,需要root權限

brctl help
brctl show
brctl addbr [Bridge Name]
brctl addif [Interface Name]
brctl delbr [Bridge Name]
brctl delif [Interface Name]


3. 建立橋接網路br0

sudo brctl addbr br0

4. 將 br0 橋接給 eth0 使用

sudo brctl addif br0 eth0

5.設定網路

sudo vi /etc/network/interfaces
## 說明
# 
#                 ->  eth0 -> 實體機
# Internet -> br0 ->
#                 ->  br1 -> N 個虛擬機
# 

# The loopback network interface
auto lo
iface lo inet loopback

iface eth0 inet manual
## interent -> br0 -> eth0 -> 實體機
auto br0
iface br0 inet static
       address [本機 ip]
       netmask [本機 netmask]
       gateway [本機 gateway]
       bridge_ports eth0
       bridge_fd 9
       bridge_hello 2
       bridge_maxage 12
       bridge_stp off

## interent -> br0 ->  br1 -> 虛擬機
auto br1
iface br1 inet static
       address 192.168.1.1
       netmask 255.255.255.0
       gateway [本機 ip]
       bridge_ports tap0
       bridge_fd 9
       bridge_hello 2
       bridge_maxage 12
       bridge_stp off 

6. 重啟動網路

ifconfig eth0 down
ifconfig eth0 up
/etc/init.d/netwroking restart

7. 查看網路連線

ifconfig
route -n
ping gateway
ping 8.8.8.8

8. 設定防火牆 iptables (ROOT)


echo 1 > /proc/sys/net/ipv4/ip_forward


### 下面的 br1 要看上面連虛擬機的 Bridge 設多少
iptables -A INPUT -i br1 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

9. 開啟 DHCP 服務

可以參考文章 DHCP Server 來安裝設定。

10. 開虛擬機連上網路

下面的 OS.img 檔案,可以參考文章
建立一個 arm.img 並且可以用虛擬機開機 來建立!


qemu-system-x86_64 -enable-kvm \
-cpu host \
-smp 4 \
-m 6000 \
-hda OS.img \
-boot c \
-net nic \
-net bridge,br=br1 &

------------------- Debug -------------------
# Question 1
Could not access KVM kernel module: No such file or directory
failed to initialize KVM: No such file or directory
Back to tcg accelerator.
qemu: could not load PC BIOS 'bios.bin'

#  Solution 1
sudo apt-get install seabios
sudo cd /usr/local/share/qemu
sudo ln -sf /usr/share/seabios/*.bin .

-----------------------------------------------------------------------------
# Question 2
failed to create tun device: Operation not permitted
failed to launch bridge helper
qemu-system-x86_64: -net bridge,br=br10: Device 'bridge' could not be initialized

qemu-bridge-helper 需要有 root 的權限才能執行

# Solution 2
chmod u+s /usr/local/libexec/qemu-bridge-helper

------------------------------------------------------------------------------
# Question 3
failed to initialize KVM: No such file or directory
Back to tcg accelerator.

# Solution 3
忘了…

-------------------------------------------------------------------
# Question 4
failed to parse default acl file `/usr/local/etc/qemu/bridge.conf'
failed to launch bridge helper

# Solution 4
vi /usr/local/etc/qemu/bridge.conf -> allow br1

---------------------------------------------------------------------
# Question 5
Could not access KVM kernel module: Permission denied
failed to initialize KVM: Permission denied

# Solution 5
建立 kvm 群組:
groupadd kvm

將自己的使用者 $USER 加到 kvm 群組中:
usermod -a -G kvm $USER

調整 /dev/kvm 使用者權限
chown root:kvm /dev/kvm
chmod 660 /dev/kvm

重新載入 kvm 驅動模組
rmmod kvm_intel kvm
modprobe kvm_intel kvm


# 如果還是不行,就請重新開機再試試
shutdown -r now

---------------------------------------------------------------------
# Question 6
qemu-system-x86_64: symbol lookup error: qemu-system-x86_64: undefined symbol: libusb_get_port_numbers

# Solution 6
先確認 libusb-1.0 有無安裝,版本對不對,再做以下指令重新連結:
sudo ln -sf /lib/x86_64-linux-gnu/libusb-1.0.so.0 /usr/local/lib/libusb-1.0.so.0





2014年10月3日 星期五

PCI 音效卡設定

音效卡型號:Onkyo SE-90PCI


查看晶片模組:
lspci -v

06:00.0 Multimedia audio controller: VIA Technologies Inc. VT1720/24 [Envy24PT/HT] PCI Multi-Channel Audio Controller (rev 01)
 Subsystem: Device 160b:0010
 Flags: bus master, medium devsel, latency 64, IRQ 16
 I/O ports at ec00 [size=32]
 I/O ports at e880 [size=128]
 Capabilities: 
 Kernel driver in use: snd_ice1724

查看驅動模組有沒有啟動:
lsmod |grep snd_ice1724

snd_ice1724           123182  2
snd_ak4113             13661  1 snd_ice1724
snd_pt2258             12712  1 snd_ice1724
snd_ak4114             13642  1 snd_ice1724
snd_i2c                13184  2 snd_pt2258,snd_ice1724
snd_ice17xx_ak4xxx     12763  1 snd_ice1724
snd_ak4xxx_adda        13382  2 snd_ice1724,snd_ice17xx_ak4xxx
snd_ac97_codec        106699  1 snd_ice1724
snd_pcm                68848  7 snd_ice1724,snd_pcm_oss,snd_ac97_codec,snd_hda_codec,snd_hda_intel,snd_ak4113,snd_ak4114
snd_rawmidi            22995  2 snd_ice1724,snd_seq_midi
snd                    53159  31 snd_pt2258,snd_ice1724,snd_pcm_oss,snd_ac97_codec,snd_hwdep,snd_timer,snd_hda_codec_via,snd_i2c,snd_pcm,snd_seq,snd_rawmidi,snd_hda_codec_generic,snd_hda_codec,snd_ak4xxx_adda,snd_hda_intel,snd_seq_oss,snd_seq_device,snd_mixer_oss,snd_ak4113,snd_ak4114


如果沒啟動,就下載入摸組指令:
modprobe snd_ice1724

如果都沒辦法載入所需要的驅動摸組,就必須要重新編譯核心,驅動「snd_ice1724」 這個模組,才可以驅動VT1720/24 [Envy24PT/HT] PCI 晶片。

接下來,安裝 PulseAudio :
sudo apt-get install pulseaudio


並去修改設定檔 /etc/pulse/default.pa:
vi /etc/pulse/default.pa

找到:
#load-module module-alsa-sink ...
改為
load-module module-alsa-sink device=dmix

找到:
load-module module-suspend-on-idle
改為
#load-module module-suspend-on-idle

找到: (解決錄音問題,如skype)
load-module module-hal-detect
改為:
#load-module module-hal-detect

在家目錄下寫一個 .asoundrc 檔,新增一個項目到 alsa ,讓它與 PulseAudio 做連結:

vi ~/.asounds

pcm.softvol
{
        type softvol
        slave.pcm "hw:1,0"
        control.name "paMaster"
        control.card 1
}

pcm.!default
{
        type pulse
}

ctl.!default
{
        type pulse
}


之後重新登出再登入,接著重新啟動 PulseAudio:
/etc/init.d/pulseaudio restart


如果出現錯誤訊息「[warn] PulseAudio configured for per-user sessions ... (warning).」,就要去修改 /etc/default/pulseaudio:
vi /etc/default/pulseaudio

改成下面
PULSEAUDIO_SYSTEM_START=1

最後裝輔助控制介面:
sudo apt-get install pavucontrol paman

直接下上面套件名稱「pavucontrol」,「paman」來啟動程式,並選擇自己所使用的音效卡。


Reference:
https://packages.debian.org/squeeze/pulseaudio

http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?viewmode=compact&type=&topic_id=10102&forum=10

http://rueiyuanlu.blogspot.tw/2011/04/pulseaudio-alsa-softvol.html