2014年10月23日 星期四

快速格式化工具

假設需要格式化的分割區為 /dev/sdb1,

  • HPFS/NTFS/exFAT

我們一般的 Linux 下格式化 NTFS 檔案系統格式,
常用的指令有:
mkfs -t ntfs /dev/sdb1
mkfs.ntfs /dev/sdb1

接下來推薦,NTFS 的快速格式化工具 ntfsprogs
sudo apt-get install ntfsprogs
mkntfs -f /dev/sdb1


  • EXT4

快速格式化要加 -T largefile 參數:
mkfs.ext4  -T largefile  /dev/sdb1










OpenHardwareMonitor 系統監測工具



Open Hardware Monitor 可用於監測系統資訊、溫度,
如:CPU、顯卡、記憶體…等。


官網:
http://openhardwaremonitor.org/

載點:
openhardwaremonitor-v0.6.0-beta.zip


可以自行設定( View -> 勾選 Show Gadget ),加到桌面顯示,如下圖:


設定開機啟動及長駐:





2014年10月22日 星期三

用 iconv 將檔案轉換格式(BIG5 ←→ UTF-8) 


因為Big-5的檔案,看都會有亂碼,


所以就可以用

iconv

來將Big-5格式的檔案,


直接轉成UTF-8的格式。

(1) Big-5 To UTF-8


 

       
iconv -f big5 -t utf-8 big5.txt -o utf8.txt


(2) UTF-8 To Big-5


        
iconv -f utf-8 -t big5 utf8.txt -o big5.txt


MobaXterm 遠端連線工具



推薦軟體 MobaXterm
可以於 Windows 7 下,遠端連線至 SSH Server ,
且免 X Loader 直接支援圖形視窗、複製文字。

相似的軟體 PuTTY ,但是只裝 PuTTY 還要另裝 X Loader 。

官網:
MobaXterm

載點:
MobaXterm v7.3 (installer 安裝版)
MobaXterm v7.3 (portable edition 免安裝版)



開啟介面如下圖:


點選 Session 設定連線服務,支援相當多遠端方式:


點選在 Linux 最常用的 SSH,並直接打入要連的 IP (user 可以不用填):


從左側選單的 PuTTY sessions 可以選到所加的 IP。








安裝 QEMU Linaro 完整版

1. 修改鏡像站

先準備 Debian backports 鏡像站,後面安裝工具會需要:
sudo vi /etc/apt/sources.list

加入下面這行:
deb http://ftp.tw.debian.org/debian wheezy-backports main

下一步請更新套件:
sudo apt-get update && apt-get upgrade

2. 下載 QEMU-Linaro

至 qemu-linaro 官方下載其檔案:
官方位置: https://launchpad.net/qemu-linaro
載點: qemu-linaro-1.7.0-2014.01.tar.gz

下載完後解壓縮,並進去 ./configure
tar xfva qemu-linaro-1.7.0-2014.01.tar.gz
cd qemu-linaro-1.7.0-2014.01/
 ./configure

可能遇到以下 ERROR:

問題1:
ERROR: pixman not present. Your options:
         (1) Preferred: Install the pixman devel package (any recent
             distro should have packages as Xorg needs pixman too).
         (2) Fetch the pixman submodule, using:
             git submodule update --init pixman
解決1:
sudo apt-get install libseccomp-dev

問題2:
ERROR: DTC not present. Your options:
         (1) Preferred: Install the DTC devel package
         (2) Fetch the DTC submodule, using:
             git submodule update --init dtc
解決2:
sudo apt-get install -y libfdt-dev

成功後可以看到 ./configure 的內容後,
但是大多的功能都是 support no,
接下來要讓它們變 yes ,進行完整化。


3. 要安裝以下套件

libnss3-dev
libudev-dev
libpng12-dev
libghc6-zlib-dev
libogg-dev
libglobus-openssl-dev
libxrandr-dev
libxfixes-dev
libjpeg8-dev
libsasl2-dev
libiscsi-dev
librbd-dev
xfslibs-dev
libbrlapi-dev
libbluetooth-dev
libxen-dev
libvte-dev
libseccomp-dev
python-pyparsing

sudo apt-get install libnss3-dev libudev-dev libpng12-dev libghc6-zlib-dev libogg-dev libglobus-openssl-dev libxrandr-dev libxfixes-dev libjpeg8-dev libsasl2-dev libiscsi-dev librbd-dev xfslibs-dev libbrlapi-dev libbluetooth-dev libxen-dev libvte-dev libseccomp-dev python-pyparsing

接下來處理幾個比較麻煩的套件,
可以查看  qemu-linaro-1.7.0-2014.01/ 目錄下的 configure 內容,
vi configure

輸入關鍵字(例如 spice),可以找到所缺少的套件。

spice support 要讓這個功能需要裝有
 --atleast-version=0.12.0 spice-server  (至少 0.12.0 版以上)
--atleast-version=0.12.3 spice-protocol (至少 0.12.3 版以上)

我們要到 spice 官方,下載,安裝如下面步驟:

4. 安裝 spice-0.12.5 

(如有遇到問題,解決方法在下面)
下載 spice-0.12.5.tar.bz2

tar xfva spice-0.12.5.tar.bz2
cd spice-0.12.5/

這邊的設定要多加 smartcard 開啟
./configure --enable-smartcard

會看到輸出:
Spice 0.12.5
        ==============
        prefix:                   /usr/local
        c compiler:               gcc -std=gnu99
        c++ compiler:             g++
        python:                   /usr/bin/python2
        Build Spice client:       no
        Smartcard:                yes
        SASL support:             yes
        Automated tests:          no
        Manual:                   no
        Now type 'make' to build spice

才接著編譯及安裝:
make -j ${core number}
sudo make install


裝 spice 問題一 (如果沒有就跳過此步驟)
Alternatively, you may set the environment variables CELT051_CFLAGS
and CELT051_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

因為 spice-0.12.5 只接受 CELT 051 版。

解決:
下載 celt-0.5.1.3.tar.gz
tar xfva celt-0.5.1.3.tar.gz
cd celt-0.5.1.3/
./configure
make  -j ${core number}
sudo make install

裝 spice 問題二 (如果沒有就跳過此步驟)
checking for pyparsing python module... not found
configure: error: pyparsing python module is required to compile this package
解決:
sudo apt-get install python-pyparsing

裝 spice 問題三 (如果沒有就跳過此步驟)
checking sasl/sasl.h usability... no
checking sasl/sasl.h presence... no
checking for sasl/sasl.h... no
checking for sasl_client_init in -lsasl2... no
checking for sasl_client_init in -lsasl... no
configure: error: Missing required Cyrus SASL development package
解決:
sudo apt-get install libsasl2-dev


裝 spice 問題四 (如果沒有就跳過此步驟)
checking for SMARTCARD... no
configure: error: Package requirements (libcacard >= 0.1.2) were not met:
No package 'libcacard' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix.
Alternatively, you may set the environment variables SMARTCARD_CFLAGS
and SMARTCARD_LIBS to avoid the need to call pkg-config.
解決:
下載 libcacard-0.1.2.tar.bz2
tar xfva libcacard-0.1.2.tar.bz2
cd  libcacard-0.1.2/
./configure
make -j ${core number}
sudo make install

承上面問題,裝 libcacard 問題 (如果沒有就跳過此步驟)
checking for NSS... no
configure: error: Package requirements (nss) were not met:
No package 'nss' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix.
Alternatively, you may set the environment variables NSS_CFLAGS
and NSS_LIBS to avoid the need to call pkg-config.
解決:
sudo apt-get install libnss3-dev


5. 安裝 spice-protocol-0.12.7

下載 spice-protocol-0.12.7.tar.bz2
tar xfva spice-protocol-0.12.7.tar.bz2
cd spice-protocol-0.12.7/
./configure
make -j ${core number}
sudo make install


6. 安裝 libusb-1.0.1

下載 libusb-1.0.19/libusb-1.0.19.tar.bz2
tar xfva libusb-1.0.19.tar.bz2
cd libusb-1.0.19/
./configure
make -j ${core number}
sudo make install


7. 安裝 usbredir-0.7

下載 usbredir-0.7.tar.bz2
tar xfva usbredir-0.7.tar.bz2
cd usbredir-0.7/
./configure
make -j ${core number}
sudo make install


8. 再回到(步驟 2.)  裝 qemu-linaro

cd qemu-linaro-1.7.0-2014.01/
./configure
內容如下:
tcg debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
-Werror enabled   no
pixman            system
SDL support       yes
GTK support       yes
curses support    yes
curl support      yes
mingw32 support   no
Audio drivers     oss
Block whitelist (rw)
Block whitelist (ro)
VirtFS support    yes
VNC support       yes
VNC TLS support   yes
VNC SASL support  yes
VNC JPEG support  yes
VNC PNG support   yes
VNC WS support    yes
xen support       yes
brlapi support    yes
bluez  support    yes
Documentation     yes
GUEST_BASE        yes
PIE               yes
vde support       yes
Linux AIO support yes
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
RDMA support      yes
TCG interpreter   no
fdt support       yes
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
sigev_thread_id   yes
uuid support      yes
libcap-ng support yes
vhost-net support yes
vhost-scsi support yes
Trace backend     nop
Trace output file trace-
spice support     yes (0.12.7/0.12.5)
rbd support       yes
xfsctl support    yes
nss used          yes
libusb            yes
usb net redir     yes
GLX support       yes
libiscsi support  yes
build guest agent yes
QGA VSS support   no
seccomp support   yes
coroutine backend ucontext
coroutine pool    yes
GlusterFS support no
virtio-blk-data-plane yes
gcov              gcov
gcov enabled      no
TPM support       no
libssh2 support   yes
TPM passthrough   no
QOM debugging     yes
vhdx              yes
接著編譯:
make -j ${core number}
安裝:
sudo make install


9. 重整 qemu 檔案路徑

安裝完後可能出現檔案路徑問題,請執行:
ldconfig


10. 查看版本

qemu-system-arm -version
QEMU emulator version 1.7.0 (qemu-linaro 2014.01), Copyright (c) 2003-2008 Fabrice Bellard

qemu-system-arm -M ?
Supported machines are:
none                 empty machine
beagle               Beagle board (OMAP3530)
beaglexm             Beagle board XM (OMAP3630)
collie               Collie PDA (SA-1110)
nuri                 Samsung NURI board (Exynos4210)
smdkc210             Samsung SMDKC210 board (Exynos4210)
connex               Gumstix Connex (PXA255)
verdex               Gumstix Verdex (PXA270)
highbank             Calxeda Highbank (ECX-1000)
midway               Calxeda Midway (ECX-2000)
integratorcp         ARM Integrator/CP (ARM926EJ-S) (default)
kzm                  ARM KZM Emulation Baseboard (ARM1136)
mainstone            Mainstone II (PXA27x)
musicpal             Marvell 88w8618 / MusicPal (ARM926EJ-S)
n800                 Nokia N800 tablet aka. RX-34 (OMAP2420)
n810                 Nokia N810 tablet aka. RX-44 (OMAP2420)
n900                 Nokia N900 (OMAP3)
sx1                  Siemens SX1 (OMAP310) V2
sx1-v1               Siemens SX1 (OMAP310) V1
overo                Gumstix Overo board (OMAP3530)
cheetah              Palm Tungsten|E aka. Cheetah PDA (OMAP310)
realview-eb          ARM RealView Emulation Baseboard (ARM926EJ-S)
realview-eb-mpcore   ARM RealView Emulation Baseboard (ARM11MPCore)
realview-pb-a8       ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9      ARM RealView Platform Baseboard Explore for Cortex-A9
akita                Akita PDA (PXA270)
spitz                Spitz PDA (PXA270)
borzoi               Borzoi PDA (PXA270)
terrier              Terrier PDA (PXA270)
lm3s811evb           Stellaris LM3S811EVB
lm3s6965evb          Stellaris LM3S6965EVB
tosa                 Tosa PDA (PXA255)
versatilepb          ARM Versatile/PB (ARM926EJ-S)
versatileab          ARM Versatile/AB (ARM926EJ-S)
vexpress-a9          ARM Versatile Express for Cortex-A9
vexpress-a15         ARM Versatile Express for Cortex-A15
xilinx-zynq-a9       Xilinx Zynq Platform Baseboard for Cortex-A9
z2                   Zipit Z2 (PXA27x)





其他 QEMU Bug 排除,參考文章:Bridge 建立橋接網路(QEMU Debug) 下方內容。

Reference:
http://pominglee.blogspot.tw/2014/06/linaro-qemu.html


2014年10月14日 星期二

用 QEMU 來開機 arm.img


1. 查看 .img 

查看一下我們做好的 image 檔案:
file arm.img
hexdump arm.img

再做一個空的 arm_test.img 測試 & 比較:
dd if=/dev/zero of=arm_test.img bs=1G count=2
file arm_test.img
hexdump arm_test.img

然後會發現, arm.img 裡頭有很多東西,但 arm_test.img 就是一個空的data。

2. 練習運算指令:expr

加法: expr 5 + 2
減法: expr 5 - 2
乘法: expr 5 \* 2
除法: expr 5 / 2

只有乘法比較特別,因為 * 是萬用特殊字元。

3. 對 image 檔案做連接,指令:losetup

到 ~/qemu_image 目錄下,需要 superUser
cd ~/qemu_image
su

查看連接狀況:
losetup -a

將 /dev/loop0 連接 arm.img:
losetup /dev/loop0 arm.img


4. 做磁區偏移(一樣 ROOT 下)

fdisk -lu /dev/loop0
所用裝置 開機      開始         結束      區塊   識別號  系統
/dev/loop0p1            2048     3913727     1955840   83  Linux
/dev/loop0p2         3915774     4192255      138241    5  延伸
/dev/loop0p5         3915776     4192255      138240   82  Linux 交換區/ Solaris

其中 /dev/loop0p1 的開始(0ffset)為 2048,我們需要修正 512 * 2048 個 sector:
losetup -o `expr 512 \* 2048` /dev/loop1 /dev/loop0


5. 核心檔案擷取

掛載:
sudo mount /dev/loop1 /mnt

複製核心檔案(這邊要一般 User)
cd /mnt/boot
cp vmlinuz-3.2.0-4-versatile ~/qemu_image
cp initrd.img-3.2.0-4-versatile ~/qemu_image

6. 用 QEMU 來做 arm.img 開機

我們先做一個 Shell Script:
vi runarm.sh

# !/bin/bash
#
# Run arm.img

qemu-system-arm -M versatilepb -m 512 \
-kernel ~qemu_image/vmlinuz-3.2.0-4-versatile \
-initrd ~qemu_image/initrd.img-3.2.0-4-versatile \
-hda ~qemu_image/arm.img \
-append "root=/dev/sda1" &

執行 runarm.sh
sh runarm.sh

7. 進入 QEMU - arm.img

開機以後,在QEMU中查看一下核心,證明我們是用 ARM 核心開機
cat /proc/cpuinfo

接下來套件更新
sudo apt-get update && apt-get upgrade -y

安裝 X-Window 套件
sudo apt-get install icewm xorg

清除套件,省空間
apt-get clean

進入圖形介面
startx

裝瀏灠器及 http 伺服器測試
sudo apt-get install iceweasel apache2
iceweasel &
網址列: localhost
可以看到 網頁 work 中...

關機
sudo halt





Reference:
http://pominglee.blogspot.tw/2013/11/qemu-arm.html