顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2017年6月19日 星期一

手動快速編譯 Ubuntu 16.04 當中 Linux kernel 4.4 裡面的 kernel module

以前寫過一篇「手動快速編譯 Ubuntu 14.04 當中 Linux kernel 裡面的 i915 module」這次是要針對 Ubuntu 16.04 LTS 上面的 Linux kernel 4.4 編譯,步驟都差不多只是有些不一樣的地方。

首先是 Linux kernel git tree 的來源改從 Launchpad 而來,是的! Ubuntu 使用的 Linux kernel 現在也放到 Launchpad 上面了。

$ git clone https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/xenial

然後是編譯的設定檔的位置不一樣了,不過大致上只要找出 config.common.ubuntu config.common.amd64 config.flavour.generic 這三個檔案的位置出來就可以了。

cat ./debian.master/config/config.common.ubuntu ./debian.master/config/amd64/config.common.amd64 ./debian.master/config/amd64/config.flavour.generic > .config

然後這次我的目標是 ubuntu/i915 底下的 kernel module 其它的部份就直接參考前一份文章就可以了。

2017年1月6日 星期五

使用 zenity 進度條的小眉角

zenity 是一個小程式用來顯示簡單的 GTK+ 對話框,其中也有進度條的選項。

$ zenity --help-progress
用法:
  zenity [選項…]

進度列選項
  --progress                              顯示進度指示窗
  --text=文字                             指定對話方塊中的文字
  --percentage=百分比                     指定開始時的百份比數值
  --pulsate                               令進度列內的方塊來回移動
  --auto-close                            當進度達到 100% 時關閉對話方塊
  --auto-kill                             若按下取消按鈕則中止父程序
  --no-cancel                             隱藏取消按鈕
  --time-remaining                        估計當進度到達 100% 的時間

使用上可將其它程式的標準輸入當成輸入,例如:

$ for i in {0..100..20}; do echo $i; sleep 1; done | \
  zenity --progress

如果想讓進度達到百分之百時自動結束可以加上 --auto-close

$ for i in {0..100..20}; do echo $i; sleep 1; done | \
  zenity --progress --auto-close
或是加上 --no-cancel 讓確定跟取消的按鈕都不見。
$ for i in {0..100..20}; do echo $i; sleep 1; done | \
  zenity --progress --auto-close --no-cancel

再加上 --time-remaining 剩餘時間的估計。

$ for i in {0..100..20}; do echo $i; sleep 1; done | \
  zenity --progress --auto-close --no-cancel --time-remaining

當然還可以使用其它元件都有的 --title 跟 --text 來客製對話框的訊息。

$ for i in {0..100..20}; do echo $i; sleep 1; done | \
  zenity --progress --auto-close --no-cancel --time-remaining --title "新建築正在倒塌中" --text "貓在鋼琴上昏倒了"

另外就是 --text 有支援一些簡單的 HTML 標籤,所以可以有一些變化。

$ for i in {0..100..20}; do echo $i; sleep 1; done | \
  zenity --progress --auto-close --no-cancel --time-remaining --title "新建築正在倒塌中" --text "<b>貓</b>在<u>鋼琴</u>上<i>昏倒</i>了\n謠言真可怕"

最後就是要小心其它程式所產生的標準輸出,像是 apt-get upgrade --yes 的輸出有時候會有數字開頭的訊息,這樣的訊息在使用 zenity --progress --auto-close 時都會導致對話框突然結束,任何超過 100 的數字都會結束程式。

2016年9月5日 星期一

Linux 系統上面的 NVIDIA 圖形顯示的私有驅動程式

NVIDIA 官方網站上面有提供驅動程式的下載,只是不曉得是否有支援我們正在使用的顯示晶片。

最直接的方式是將驅動程式下載後解開來看裡面的 README.txt 的內容,例如目前最新的 Beta 版本 NVIDIA-Linux-x86_64-370.23.run,下載後可執行以下指令來解開它。

$ bash NVIDIA-Linux-x86_64-370.23.run -x

然後就可以去查看 NVIDIA-Linux-x86_64-370.23 目錄底下的 README.txt 檔案。

然後直接跳轉到 Appendix A. Supported NVIDIA GPU Products 的地方,就可以看到許多的 Device PCI ID,這時候再去對一下自己系統上面的 lspci -vnn 的輸出上面的 NVIDIA 顯示都是 10de 開頭的。

Appendix A. Supported NVIDIA GPU Products
______________________________________________________________________________
...
A1. NVIDIA GEFORCE GPUS


    NVIDIA GPU product                    Device PCI ID*     VDPAU features
    ----------------------------------    ---------------    ---------------
    GeForce GTX 480                       06C0               C
    ...
    GeForce GT 620M                       0DE9 1025 0692     C
    ...
...

像是 06C0 對應到 [10de:06c0] 只要對一組 PCI ID 就好了,而 0DE9 1025 0692 則是對應到 [10de:0de9] 然後還要檢查 Subsystem ID 是不是 [1025:0692],類似下面的輸出(假造的)。

00:02.0 VGA compatible controller [0300]: NVIDIA GeForce GT 620M [10de:0de9] (rev 00) (prog-if 00 [VGA controller])
 Subsystem: Foo bar system [1025:0692]

如果系統上面的 Device PCI ID 跟 Subsystem PCI ID 有跟 README.txt 裡面的符合就表示這個驅動程式應該有支援,如果沒有出現在 README.txt 裡面的話,就是沒有支援。

而 Ubuntu 上面的 NVIDIA 私有驅動也是透過同樣的 README.txt 轉換成 dh-modaliases 使用的格式,讓使用者可以透過 ubuntu-drivers 來自動找到合適的驅動程式。

$ apt-cache show nvidia-361
Package: nvidia-361
Priority: optional
Section: restricted/misc
Installed-Size: 292039
Maintainer: Ubuntu Core Developers <...>
Architecture: amd64
Source: nvidia-graphics-drivers-361
...
Description: NVIDIA binary driver - version 361.42
Description-md5: 2f2445ec5e04329593078984a32bc2ae
Modaliases: nvidia_361(pci:v000010DEd000006C0sv*sd*bc03sc*i*,...

2016年7月25日 星期一

Disable Secure Boot in shim-signed

The latest Ubuntu kernel updates bring some Secure Boot enhancement for the kernel modules when the Secure Boot is enabled in BIOS settings. However there is no easy way to sign those kernel modules in DKMS packages automatically so far. If we want to use those DKMS packages, we need to disable Secure Boot in BIOS settings temporarily or we can also disable Secure Boot in shim-signed temporarily. The following steps introduced how to disable Secure Boot in shim-signed.

  1. Open a terminal by Ctrl + Alt + T, execute `sudo update-secureboot-policy` and then select ‘Yes’.
  2. Enter a temporary password between 8 to 16 digits. (For example, 12345678, we will use this password later.)
  3. Enter the same password again to confirm.
  4. Reboot the system and press any key when you see the blue screen (MOK management).
  5. Select “Change Secure Boot state”.
  6. Press the corresponding password character and press Enter. Repeat this step several times to confirm previous temporary password like ‘12345678’ in step 2&3. For exmaple, '2' for this screen.
  7. Select ‘Yes’ to disable Secure Boot in shim-signed.
  8. Press Enter key to finish the whole procedure.

We can still enable Secure Boot in shim-signed again. Just execute `sudo update-secureboot-policy --enable` and then follow the similar steps above.

2016年5月30日 星期一

編譯 Ubuntu 的 Linux kernel 來使用 USB to RS-232 輸出訊息

如果曾經有參加過台北的 Ubuntu Hardware Summit,應該都會拿到一本橘色小手冊 Ubuntu Debugging,當中有提到可以設定幾個 Linux kernel 編譯選項中

CONFIG_USB_SERIAL_CONSOLE=y
CONFIG_USB_SERIAL=y
CONFIG_USB_SERIAL_PL2303=y

然後就可以在 Linux kernel 開機參數加上

console=tty console=ttyUSB0,115200n8

這樣就可以透過 USB to RS-232 傳輸線將 Linux kernel 訊息輸出到另外一台電腦上面,為什麼要這樣做有時候是因為 Linux kernel 開機時是什麼畫面也沒有,也不曉得中間到底發生了什麼事情,又或者是 Linux kernel 訊息出現的太快了,來不及看清楚完整的訊息一下子就過去了,也沒有來得及儲存到檔案系統上面就當機了,有著許許多多不同的情況可能會需要。

但是實際上要怎麼做才能夠編譯出 Ubuntu 上面所使用的 Linux kernel 呢?

首先是將 Ubuntu 所使用的 Linux kernel 的原始碼下載回來。

$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-xenial.git

然後我自己 commit 了一些修改 (主要是針對 amd64)。

$ git diff HEAD^..HEAD
diff --git a/debian.master/abi/4.4.0-22.39/amd64/generic.modules b/debian.master/abi/4.4.0-22.39/amd64/generic.modules
index e1b9392..53d7914 100644
--- a/debian.master/abi/4.4.0-22.39/amd64/generic.modules
+++ b/debian.master/abi/4.4.0-22.39/amd64/generic.modules
@@ -2873,7 +2873,6 @@ pixcir_i2c_ts
 pkcs7_test_key
 pktcdvd
 pktgen
-pl2303
 platform_lcd
 plat_nand
 plat-ram
@@ -4236,7 +4235,6 @@ usblp
 usbmon
 usbmouse
 usbnet
-usbserial
 usb-serial-simple
 usbsevseg
 usb-storage
diff --git a/debian.master/config/annotations b/debian.master/config/annotations
index 825012f..167ab6e 100644
--- a/debian.master/config/annotations
+++ b/debian.master/config/annotations
@@ -6609,7 +6609,7 @@ CONFIG_USB_STORAGE_ENE_UB6250                   policy<{'amd64': 'm', 'arm64': '
 CONFIG_USB_UAS                                  policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 
 # Menu: Device Drivers >> USB support >> Support for Host-side USB >> USB Serial Converter support
-CONFIG_USB_SERIAL                               policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
+CONFIG_USB_SERIAL                               policy<{'amd64': 'y', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_GENERIC                       policy<{'amd64': 'y', 'arm64': 'y', 'armhf': 'y', 'i386': 'y', 'powerpc': 'y', 'ppc64el': 'y'}>
 CONFIG_USB_SERIAL_SIMPLE                        policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_AIRCABLE                      policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
@@ -6641,7 +6641,7 @@ CONFIG_USB_SERIAL_MOS7715_PARPORT               policy<{'amd64': 'y', 'arm64': '
 CONFIG_USB_SERIAL_MOS7840                       policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_MXUPORT                       policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_NAVMAN                        policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
-CONFIG_USB_SERIAL_PL2303                        policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
+CONFIG_USB_SERIAL_PL2303                        policy<{'amd64': 'y', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_OTI6858                       policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_QCAUX                         policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
 CONFIG_USB_SERIAL_QUALCOMM                      policy<{'amd64': 'm', 'arm64': 'm', 'armhf': 'm', 'i386': 'm', 'powerpc': 'm', 'ppc64el': 'm'}>
diff --git a/debian.master/config/config.common.ubuntu b/debian.master/config/config.common.ubuntu
index 505a3c7..7cb1284 100644
--- a/debian.master/config/config.common.ubuntu
+++ b/debian.master/config/config.common.ubuntu
@@ -8391,7 +8391,8 @@ CONFIG_USB_RIO500=m
 CONFIG_USB_RTL8150=m
 CONFIG_USB_RTL8152=m
 CONFIG_USB_S2255=m
-CONFIG_USB_SERIAL=m
+CONFIG_USB_SERIAL=y
+CONFIG_USB_SERIAL_CONSOLE=y
 CONFIG_USB_SERIAL_AIRCABLE=m
 CONFIG_USB_SERIAL_ARK3116=m
 CONFIG_USB_SERIAL_BELKIN=m
@@ -8439,7 +8440,7 @@ CONFIG_USB_SERIAL_OMNINET=m
 CONFIG_USB_SERIAL_OPTICON=m
 CONFIG_USB_SERIAL_OPTION=m
 CONFIG_USB_SERIAL_OTI6858=m
-CONFIG_USB_SERIAL_PL2303=m
+CONFIG_USB_SERIAL_PL2303=y
 CONFIG_USB_SERIAL_QCAUX=m
 CONFIG_USB_SERIAL_QT2=m
 CONFIG_USB_SERIAL_QUALCOMM=m

接著開始編譯 Linux kernel (在有八個 CPU cores 的電腦上)

$ CONCURRENCY_LEVEL=8 fakeroot debian/rules clean binary-generic

最後就會在上層目錄產生 Ubuntu 所使用的 Linux kernel 的 Debian packages 了。

$ ls -1 ../*.deb
../linux-cloud-tools-4.4.0-22-generic_4.4.0-22.40_amd64.deb
../linux-headers-4.4.0-22-generic_4.4.0-22.40_amd64.deb
../linux-image-4.4.0-22-generic_4.4.0-22.40_amd64.deb
../linux-image-extra-4.4.0-22-generic_4.4.0-22.40_amd64.deb
../linux-tools-4.4.0-22-generic_4.4.0-22.40_amd64.deb

這樣就可以將這些 Debian packages 拿去安裝使用了。

最後我放了一份在 http://people.ubuntu.com/~fourdollars/usb2rs232/ 上面,也許有人剛好也需要想要測試一下效果如何。

參考資料:https://wiki.ubuntu.com/Kernel/KernelDebuggingTricks

2015年11月9日 星期一

手動快速編譯 Ubuntu 14.04 當中 Linux kernel 裡面的 i915 module

首先要下載 Linux kernel source tree

$ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-trusty.git

然後進去該目錄,並且切換到 vivid branch (這邊使用的是 Ubuntu 14.04 當中 LTS Enablement Stacks 當中的 vivid)

$ git checkout -b vivid origin/lts-backport-vivid

快速產生目標的 .config

$ cat debian.vivid/config/config.common.ubuntu debian.vivid/config/amd64/config.common.amd64 debian.vivid/config/amd64/config.flavour.generic > .config

執行一些設定腳本

$ make oldconfig && make prepare && make scripts

設定環境變數 (接下來會使用到)

$ export KDIR=$PWD

複製 Module.symvers (如果要編譯的 Linux kernel 跟系統所使用的剛好相同)

$ cp -v /lib/modules/$(uname -r)/build/Module.symvers Module.symvers

不然就需要至少編譯整個 Linux kernel 一遍才行 (-j? 可以參考 /proc/cpuinfo 的數量來決定)

$ make -j8

切換到該 module 的目錄底下,不過 Ubuntu 的 Linux kernel 目前有兩份不同的 i915 module,一份放在 drivers/gpu/drm/i915 底下,另一份放在 ubuntu/i915 底下。

$ cd drivers/gpu/drm/i915

或是

$ cd ubuntu/i915

然後開始編譯 (J=? 可以參考 /proc/cpuinfo 的數量來決定)

$ make -C $KDIR M=$PWD J=8

參考資料:Kernel/BuildYourOwnKernel - Ubuntu WikiDocumentation/kbuild/modules.txt

2015年7月21日 星期二

在 GNU/Linux 系統上使用指令來燒錄光碟的一些心得

首先是 dvd+rw-mediainfo 這個指令可以用來檢查光碟機裡面到底是放著哪一種光碟片。

$ sudo dvd+rw-mediainfo /dev/sr0
INQUIRY:                [HL-DT-ST][DVD+-RW GP60N   ][A300]
GET [CURRENT] CONFIGURATION:
 Mounted Media:         1Ah, DVD+RW
 Media ID:              RITEK/004
 Current Write Speed:   4.0x1385=5540KB/s
 Write Speed #0:        4.0x1385=5540KB/s
 Write Speed #1:        2.4x1385=3324KB/s
 Speed Descriptor#0:    00/2295103 R@8.0x1385=11080KB/s W@4.0x1385=5540KB/s
 Speed Descriptor#1:    00/2295103 R@8.0x1385=11080KB/s W@2.4x1385=3324KB/s
READ DVD STRUCTURE[#0h]:
 Media Book Type:       00h, DVD-ROM book [revision 0]
 Legacy lead-out at:    2295104*2KB=4700372992
READ DISC INFORMATION:
 Disc status:           blank
 Number of Sessions:    1
 State of Last Session: empty
 "Next" Track:          1
 Number of Tracks:      1
READ FORMAT CAPACITIES:
 unformatted:  2295104*2048=4700372992
 26h(0):  2295104*2048=4700372992
READ TRACK INFORMATION[#1]:
 Track State:           invisible incremental
 Track Start Address:   0*2KB
 Free Blocks:           2295104*2KB
 Track Size:            2295104*2KB
READ CAPACITY:          0*2048=0

看到 Mounted Media 這行寫著 DVD+RW 就是光碟片的規格了,另外是 Disc status 這行可以看到目前光碟片的內容是空白的。

另外使用 wodim 也可以看到光碟片的規格,不過更重要的是 wodim 可以看到光碟機的規格

$ sudo wodim dev=/dev/sr0 driveropts=help -checkdrive -v
TOC Type: 1 = CD-ROM
scsidev: '/dev/sr0'
devname: '/dev/sr0'
scsibus: -2 target: -2 lun: -2
Linux sg driver version: 3.5.27
Wodim version: 1.1.11
Driveropts: 'help'
SCSI buffer size: 64512
Device type    : Removable CD-ROM
Version        : 0
Response Format: 2
Capabilities   : 
Vendor_info    : 'HL-DT-ST'
Identification : 'DVD+-RW GP60N   '
Revision       : 'A300'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.
Current: 0x001A (DVD+RW)
Profile: 0x0012 (DVD-RAM) 
Profile: 0x002B (DVD+R/DL) 
Profile: 0x001B (DVD+R) 
Profile: 0x001A (DVD+RW) (current)
Profile: 0x0016 (DVD-R/DL layer jump recording) 
Profile: 0x0015 (DVD-R/DL sequential recording) 
Profile: 0x0014 (DVD-RW sequential recording) 
Profile: 0x0013 (DVD-RW restricted overwrite) 
Profile: 0x0011 (DVD-R sequential recording) 
Profile: 0x0010 (DVD-ROM) 
Profile: 0x000A (CD-RW) 
Profile: 0x0009 (CD-R) 
Profile: 0x0008 (CD-ROM) 
Profile: 0x0002 (Removable disk) 
Driver options:
burnfree Prepare writer to use BURN-Free technology
noburnfree Disable using BURN-Free technology

像是我目前使用的燒錄機有支援 burnfree 的功能,wodim 如果加上 -prcap 來使用,可以看到更詳細的細節。

$ sudo wodim -prcap dev=/dev/sr0 driveropts=help -checkdrive -v
TOC Type: 1 = CD-ROM
scsidev: '/dev/sr0'
devname: '/dev/sr0'
scsibus: -2 target: -2 lun: -2
Linux sg driver version: 3.5.27
Wodim version: 1.1.11
Driveropts: 'help'
SCSI buffer size: 64512
Device type    : Removable CD-ROM
Version        : 0
Response Format: 2
Capabilities   : 
Vendor_info    : 'HL-DT-ST'
Identification : 'DVD+-RW GP60N   '
Revision       : 'A300'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.

Drive capabilities, per MMC-3 page 2A:

  Does read CD-R media
  Does write CD-R media
  Does read CD-RW media
  Does write CD-RW media
  Does read DVD-ROM media
  Does read DVD-R media
  Does write DVD-R media
  Does read DVD-RAM media
  Does write DVD-RAM media
  Does support test writing

  Does read Mode 2 Form 1 blocks
  Does read Mode 2 Form 2 blocks
  Does read digital audio blocks
  Does restart non-streamed digital audio reads accurately
  Does support Buffer-Underrun-Free recording
  Does read multi-session CDs
  Does read fixed-packet CD media using Method 2
  Does not read CD bar code
  Does not read R-W subcode information
  Does read raw P-W subcode data from lead in
  Does return CD media catalog number
  Does return CD ISRC information
  Does support C2 error pointers
  Does not deliver composite A/V data

  Does play audio CDs
  Number of volume control levels: 255
  Does support individual volume control setting for each channel
  Does support independent mute setting for each channel
  Does not support digital output on port 1
  Does not support digital output on port 2

  Loading mechanism type: tray
  Does support ejection of CD via START/STOP command
  Does not lock media on power up via prevent jumper
  Does allow media to be locked in the drive via PREVENT/ALLOW command
  Is currently in a media-locked state
  Does not support changing side of disk
  Does not have load-empty-slot-in-changer feature
  Does not support Individual Disk Present feature

  Maximum read  speed: 11080 kB/s (CD  62x, DVD  8x)
  Current read  speed: 11080 kB/s (CD  62x, DVD  8x)
  Maximum write speed:  5540 kB/s (CD  31x, DVD  4x)
  Current write speed:  5540 kB/s (CD  31x, DVD  4x)
  Rotational control selected: CLV/PCAV
  Buffer size in KB: 768
  Copy management revision supported: 1
  Number of supported write speeds: 2
  Write speed # 0:  5540 kB/s CLV/PCAV (CD  31x, DVD  4x)
  Write speed # 1:  3324 kB/s CLV/PCAV (CD  18x, DVD  2x)

Supported CD-RW media types according to MMC-4 feature 0x37:
  Does write multi speed       CD-RW media
  Does write high  speed       CD-RW media
  Does write ultra high speed  CD-RW media
  Does not write ultra high speed+ CD-RW media

如果是從來都沒有使用過的 DVD+RW 片,可能會需要先格式化一次。

$ sudo wodim dev=/dev/sr0 -format
...
$ sudo dvd+rw-mediainfo /dev/sr0
INQUIRY:                [HL-DT-ST][DVD+-RW GP60N   ][A300]
GET [CURRENT] CONFIGURATION:
 Mounted Media:         1Ah, DVD+RW
 Media ID:              RITEK/004
 Current Write Speed:   4.0x1385=5540KB/s
 Write Speed #0:        4.0x1385=5540KB/s
 Write Speed #1:        2.4x1385=3324KB/s
 Speed Descriptor#0:    00/2295103 R@8.0x1385=11080KB/s W@4.0x1385=5540KB/s
 Speed Descriptor#1:    00/2295103 R@8.0x1385=11080KB/s W@2.4x1385=3324KB/s
READ DVD STRUCTURE[#0h]:
 Media Book Type:       00h, DVD-ROM book [revision 0]
 Legacy lead-out at:    2295104*2KB=4700372992
READ DISC INFORMATION:
 Disc status:           complete
 Number of Sessions:    1
 State of Last Session: complete
 Number of Tracks:      1
 BG Format Status:      in progress, 78.1% complete
READ FORMAT CAPACITIES:
 formatted:  2295104*2048=4700372992
 26h(0):  2295104*2048=4700372992
READ TRACK INFORMATION[#1]:
 Track State:           complete incremental
 Track Start Address:   0*2KB
 Free Blocks:           0*2KB
 Track Size:            2295104*2KB
FABRICATED TOC:
 Track#1  :             14@0
 Track#AA :             14@2295104
 Multi-session Info:    #1@0
READ CAPACITY:          2295104*2048=4700372992

DVD+RW 格式化完後 Disc status 會變成 complete。

如果使用的是已經有寫入資料的 DVD-RW 片,可能會需要先快速抹除光碟內容。

$ sudo wodim -v dev=/dev/sr0 blank=fast

如果快速抹除光碟片執行失敗,也許可以試試看強迫完整抹除光碟內容。

$ sudo wodim -v dev=/dev/sr0 blank=all -force

DVD-RW 抹除後會長像下面這樣。

$ sudo dvd+rw-mediainfo /dev/sr0
INQUIRY:                [HL-DT-ST][DVD+-RW GP60N   ][A300]
GET [CURRENT] CONFIGURATION:
 Mounted Media:         14h, DVD-RW Sequential
 Media ID:              RITEKW04    
 Current Write Speed:   4.0x1385=5540KB/s
 Write Speed #0:        4.0x1385=5540KB/s
 Write Speed #1:        2.0x1385=2770KB/s
 Speed Descriptor#0:    00/2298495 R@8.0x1385=11080KB/s W@4.0x1385=5540KB/s
 Speed Descriptor#1:    00/2298495 R@8.0x1385=11080KB/s W@2.0x1385=2770KB/s
READ DVD STRUCTURE[#10h]:
 Media Book Type:       00h, DVD-ROM book [revision 0]
 Legacy lead-out at:    2298496*2KB=4707319808
READ DVD STRUCTURE[#0h]:
 Media Book Type:       33h, DVD-RW book [revision 3]
 Last border-out at:    8390653*2KB=17184057344
READ DISC INFORMATION:
 Disc status:           blank
 Number of Sessions:    1
 State of Last Session: empty
 "Next" Track:          1
 Number of Tracks:      1
READ FORMAT CAPACITIES:
 unformatted:  2297888*2048=4706074624
 00h(800):  2297888*2048=4706074624
 10h(10):  2297888*2048=4706074624
 15h(10):  2297888*2048=4706074624
READ TRACK INFORMATION[#1]:
 Track State:           blank
 Track Start Address:   0*2KB
 Next Writable Address: 0*2KB
 Free Blocks:           2297888*2KB
 Track Size:            2297888*2KB
READ CAPACITY:          0*2048=0

有時候可能會想要指定最低倍速來燒錄光碟片,因為光碟機或光碟片的品質問題,會導致全速燒錄時的失敗,最低倍速的燒錄會相對保險一些。

$ sudo wodim -v -eject dev=/dev/sr0 speed=2 driveropts=burnfree Windows10_InsiderPreview_x64_ZH-TW_10162.iso

加上 -eject 是希望燒錄完成後將光碟片拖盤退出(如果光碟機真的有拖盤的話),加上 driveropts=burnfree 是因為光碟機有這個功能。

使用 DVD+RW 跟 DVD-RW 的不同點在於 DVD+RW 只要格式化一次,之後就可以重覆地直接將 ISO 寫進去,不需要像 DVD-RW 那樣,每次都要先抹除內容,然後才可以將 ISO 寫進去。

2015年3月23日 星期一

為 Bay Trail 低功耗小電腦安裝 Ubuntu 14.04.2 所做的一些最佳化

首先是實體記憶體只有 1~2 GB

所以安裝 zram-config 跟修改 /etc/default/grub 當中的 GRUB_CMDLINE_LINUX 加上 zswap.enabled=1

sudo apt-get install zram-config
sudo service zram-config start
sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="zswap.enabled=1"/' /etc/default/grub
Zram 是壓縮實體記憶體當中的資料的技術,而 Zswap 則是壓縮 Swap 分割區當中的資料的技術,兩者都會稍微增加 CPU 使用量。

另外也可以使用更有效率的 lz4 壓縮格式,請參考 http://www.plurk.com/p/kumpgn/etc/init/zram-config.conf 的設定。

然後是透過 VAAPI 來使用硬體解碼器

首先可以安裝 VAAPI 相關的軟體套件。

sudo apt-get install i965-va-driver gstreamer1.0-vaapi vainfo

然後就可以透過 vainfo 指令看到有支援哪些硬體加速編碼跟解碼

$ vainfo
libva info: VA-API version 0.35.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_35
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.35 (libva 1.3.0)
vainfo: Driver version: Intel i965 driver - 1.3.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD

然後安裝 VLC 媒體播放器後,再從偏好設定中開啟功能。

sudo apt-get install --yes vlc

讓 Chromium 支援 VAAPI

然後因為到目前為止 (2015/03/23) Google Chrome/Chromium 並沒有支援一般 Linux 系統上的 VAAPI,所以如果想要使用必須安裝 ppa:saiarcot895/chromium-beta 所提供的 Chromium 才會有。

另外可能還需要更改 Chromium 的啟動參數,為了減少 Chromium 的記憶體使用量,我還參考了 Process Models - The Chromium Projects 上面的模式,使用了 --process-per-site。

sudo add-apt-repository --yes ppa:saiarcot895/chromium-beta
sudo apt-get update
sudo apt-get install --yes chromium-browser
sudo sed -i 's/CHROMIUM_FLAGS=""/CHROMIUM_FLAGS="--ignore-gpu-blacklist --process-per-site"/' /etc/chromium-browser/default

另外還要在 Chromium 上安裝 Adblock for Youtube™h264ify,安裝 Adblock for Youtube™ 是因為 Youtube™ 影片內嵌的廣告會影響到播放品質,在這個低功耗的電腦上面特別明顯,而安裝 h264ify 則是因為 Youtube™ 預設的串流編碼是 VP9,而我用的這個電腦上面並沒有支援 VP9 的硬體加速解碼,所以安裝 h264ify 強制讓 Youtube™ 串流編碼變成 H264。

另外就是 Ubuntu Unity 桌面預設的 Totem 媒體播放器目前還沒有支援 VAAPI,不然安裝 gstreamer1.0-vaapi 可以派上用場了,不過也許可以參考 http://gitorious.org/vaapi/gstreamer-vaapi 當中的 README 使用 gst-launch-1.0 來感受一下。

Usage
-----

  VA elements are automatically plugged into GStreamer pipelines. So,
  using playbin (or playbin2 with GStreamer 0.10) should work as is.
  However, here are a few alternate pipelines that could be manually
  constructed.

  * Play an H.264 video with an MP4 container in fullscreen mode
  $ gst-launch-1.0 -v filesrc location=/path/to/video.mp4 ! \
      qtdemux ! vaapidecode ! vaapisink fullscreen=true

  * Play a raw MPEG-2 interlaced stream
  $ gst-launch-1.0 -v filesrc location=/path/to/mpeg2.bits ! \
      mpegvideoparse ! vaapidecode ! vaapipostproc ! vaapisink

  * Convert from one pixel format to another, while also downscaling
  $ gst-launch-1.0 -v filesrc location=/path/to/raw_video.yuv ! \
      videoparse format=yuy2 width=1280 height=720 ! \
      vaapipostproc format=nv12 height=480 ! vaapisink

  * Encode a 1080p stream in raw I420 format into H.264
  $ gst-launch-1.0 -v filesrc location=/path/to/raw_video.yuv ! \
      videoparse format=i420 width=1920 height=1080 framerate=30/1 ! \
      vaapiencode_h264 rate-control=cbr tune=high-compression ! \
      qtmux ! filesink location=/path/to/encoded_video.mp4

Mozilla Firefox 目前好像也沒有支援 VAAPI,也許有人可以幫忙補充一下進度。

未來的 PowerVR 對於 VP8 的硬體加速解碼支援

目前只看到了兩則報導,分別是去年十月的 Intel Publishes DRM Driver For PowerVR Video Decoder! VP8 Decoding! 跟今年一月的 Intel Is Still Working On The VED DRM Driver For PowerVR,但是還沒有看到那些 commits 進到 mainline kernel 裡面,另外 Youtube™ 上面的預設串流編碼是 VP9,不曉得 VP8 的硬解支援能不能夠幫助到 VP9,目前看起來未來會多一兩個檔案名稱內有 ipvr 的 kernel module 。

最後另外順便收集了一下 Dell New XPS 13 在 vivid 上面的 vainfo 感覺還不錯。

libva info: VA-API version 0.37.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_37
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.37 (libva 1.5.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Broadwell - 1.5.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264MultiviewHigh      : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
      VAProfileH264StereoHigh         : VAEntrypointVLD
      VAProfileH264StereoHigh         : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
      VAProfileH264StereoHigh         : VAEntrypointVLD
      VAProfileH264StereoHigh         : VAEntrypointEncSlice

2014年7月15日 星期二

在 Ubuntu 上面安裝 mainline kernels

所謂的 mainline kernels 就是在 The Linux Kernel Archives 上面由 Linus Torvalds 本人釋出的版本, 而 Ubuntu 本來有一個 Ubuntu Kernel PPA 專門用來編譯這些 mainline kernels, 只是後來不曉得為何就不再使用 PPA 改用手動編譯的方式,可能是因為 Linux kernel 的釋出方式有了許多變化,除了原本的 stable 跟 mainline 還另加入了 longterm 的支援, 而 Ubuntu 的 Kernel team 本來就有準備一個 http://kernel.ubuntu.com/~kernel-ppa/mainline/ 上面備份了所有的 mainline kernels, 所以就繼續沿用這樣的名稱,但其實這上面還包括了 stable 跟 longterm 後來所有的版本。

總之 http://kernel.ubuntu.com/~kernel-ppa/mainline/ 上面放的是沒有 Ubuntu 額外加料的原始 kernel 版本,只是都編譯成了 Debian package, 所以想要使用的人可以直接下載來安裝就可以使用了,而這些 kernel 如果在安裝使用上會有什麼問題,當然也不會在 Ubuntu 的支援之中,這些 kernel 的存在只是用來測試的,藉由安裝不同的版本來找出問題是在哪兩個版本之間發生的,或是在哪兩個版本之間解決的,進而幫助開發者縮小問題發生的地方,來找出相關合適的修補檔。

但是這樣不斷地手動下載安裝,也是很麻煩的,所以我寫了一個小工具來幫忙,它就叫做 mainline-kernels.sh,下載後像下面這樣執行就可以看到使用說明:

$ ./mainline-kernels.sh --help
Usage ./mainline-kernels.sh:
    -h|--help       The manual of this script
    -f|--from NUM   Lower bound of kernel version
    -t|--to   NUM   Upper bound of kernel version
    -l|--list       List available kernel versions
    -r|--remove     Remove mainline kernels

可以先使用 ./mainline-kernels.sh --list 來找出現在有哪些 kernel 可以使用。

$ ./mainline-kernels.sh --list
2.6.15               2.6.24.7             2.6.24                       2.6.25               2.6.26               2.6.27.47-intrepid
2.6.27.58-intrepid   2.6.27.59-intrepid   2.6.27.60-intrepid           2.6.27.61-intrepid   2.6.27.62-intrepid   2.6.27
2.6.28.10            2.6.28               2.6.29.6                     2.6.29               2.6.30.10            2.6.30
...
3.15~rc3-utopic      3.15~rc4-utopic      3.15~rc5-utopic              3.15~rc6-utopic      3.15~rc7-utopic      3.15~rc8-utopic
3.15-utopic          3.15.1-utopic        3.15.2-utopic                3.15.3-utopic        3.15.4-utopic        3.15.5-utopic
3.16~rc1-utopic      3.16~rc2-utopic      3.16~rc3-utopic              3.16~rc4-utopic      3.16~rc5-utopic

然後直接安裝想要的 Linux kernel

$ ./mainline-kernels.sh 3.16~rc4-utopic 3.16~rc5-utopic

或是指定一個範圍來安裝

./mainline-kernels.sh --from 3.15~ --to 3.16

或是什麼都不指定直接執行,之後再慢慢從選單上面挑選。

./mainline-kernels.sh

最後再將安裝的 Linux kernel 移除掉。

./mainline-kernels.sh --remove

要提醒的一點是,這邊的版本號碼是遵循 Debian version 的規則,所以波浪符號有特別的意義,可以參考我以前的文章

最後分享一下 Ubuntu to Mainline kernel version mapping,結束這一回合。

2013年12月2日 星期一

VirtualBox Guest 裡面共用資料夾的自動掛載

VirtualBox 有提供一個方便的功能,能將 Host 的某個資料夾自動掛載到 Guest 裡面使用,只是自動掛載的權限不是預設的使用者。

sylee@vbox:~$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
vbox on /media/sf_vbox type vboxsf (gid=999,rw)
sylee@vbox:~$ id
uid=1000(sylee) gid=1000(sylee) groups=1000(sylee),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),111(lpadmin),112(sambashare)

這時候只要參考以前寫過的『如何解決在 Ubuntu 上面安裝 VirtualBox 後缺少 vboxusers 群組權限的問題』,將預設的使用者加入到 vboxsf 這個群組裡面,再重新登入後,就可以自由地使用 /media/sf_vbox 底下的檔案了。

sylee@vbox:~$ sudo usermod -a -G vboxsf sylee

隨意拿了 linux-generic-lts-quantal_3.5.0.44.50_amd64.deb linux-signed-generic-lts-quantal_3.5.0.44.50_amd64.deb linux-signed-image-generic-lts-quantal_3.5.0.44.50_amd64.deb linux-image-3.5.0-44-generic_3.5.0-44.67~precise1_amd64.deb linux-signed-image-3.5.0-44-generic_3.5.0-44.67~precise1_amd64.deb 來測試。

使用 vboxsf 來複製檔案。

real    0m0.661s
user    0m0.004s
sys     0m0.284s

使用 sshfs 來複製檔案。

real    0m2.276s
user    0m0.000s
sys     0m0.103s

sshfs 掰~

2013年8月7日 星期三

使用 GDB 追縱執行中程式裡面的變數值

首先是要安裝 debug symbols 的套件來使用。

Debian 可以參考 HowToGetABacktrace - Debian Wiki
Ubuntu 可以參考 DebuggingProgramCrash - Ubuntu Wiki

例如目標是 Ubuntu 12.04 中的 Xorg 裡面的 positionSprite() 函式在執行時傳入的變數值,所以先用

$ ps aux | grep X
root      1044  0.4  1.0 127440 21524 tty7     Ss+  18:44   0:06 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -background none
u         2633  0.0  0.0  13616   928 pts/2    S+   19:11   0:00 grep --color=auto X
來找出 Xorg 的 PID

然後執行以下指令:

$ sudo gdb /usr/bin/Xorg 1044                                                                                                                                                                         
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /usr/bin/Xorg...Reading symbols from /usr/lib/debug/usr/bin/Xorg...done.
done.
Attaching to program: /usr/bin/Xorg, process 1044
Reading symbols from /lib/x86_64-linux-gnu/libudev.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libudev.so.0
... [省略]
(gdb) set height 0
(gdb) break positionSprite
Breakpoint 1 at 0x7fedc71d1140: file ../../dix/getevents.c, line 940.
(gdb) c
Continuing.

Breakpoint 1, positionSprite (dev=0x7fedc94105d0, mode=0, mask=0x7fff3c6e6780, devx=0x7fff3c6e6770, devy=0x7fff3c6e6778, screenx=0x7fff3c6e6760, screeny=0x7fff3c6e6768) at ../../dix/getevents.c:940
940     ../../dix/getevents.c: 沒有此一檔案或目錄.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>print *devx
>print *devy
>print *screenx
>print *screeny
>continue
>end
(gdb) c
Continuing.

接下來移動滑鼠就可以看到以下的訊息。

Breakpoint 1, positionSprite (dev=0x7fedc94105d0, mode=0, mask=0x7fff3c6e6780, devx=0x7fff3c6e6770, devy=0x7fff3c6e6778, screenx=0x7fff3c6e6760, screeny=0x7fff3c6e6768) at ../../dix/getevents.c:940
940     in ../../dix/getevents.c
$45 = 1023.4510981145139
$46 = 757.60130195816362
$47 = 1366.6023460649326
$48 = 758.58904811456273

Breakpoint 1, positionSprite (dev=0x7fedc94105d0, mode=0, mask=0x7fff3c6e6780, devx=0x7fff3c6e6770, devy=0x7fff3c6e6778, screenx=0x7fff3c6e6760, screeny=0x7fff3c6e6768) at ../../dix/getevents.c:940
940     in ../../dix/getevents.c
$49 = 1022.651098102593
$50 = 757.60130195816362
$51 = 1365.5341153549775
$52 = 758.58904811456273

可以將設定好的 breakpoints 的動作儲存成一個腳本檔

(gdb) save breakpoints break.cmd
Saved to file 'break.cmd'.

腳本的內容是:

set height 0
break positionSprite
  commands
    print *devx
    print *devy
    print *screenx
    print *screeny
    cont
  end

只是第一行的 set height 0 是手動加上去的,目的是不要訊息過長就停下來。

下次再使用 GDB 時就可以執行 source 載入使用。

(gdb) source break.cmd 
Breakpoint 1 at 0x7fedc71d1140: file ../../dix/getevents.c, line 940.
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00007fedc71d1140 in positionSprite at ../../dix/getevents.c:940
        print *devx
        print *devy
        print *screenx
        print *screeny
        cont

只是前面有一個找不到原始碼的小問題,可以執行以下指令來下載原始碼:

$ apt-get source xserver-xorg-core-lts-quantal
或是:
$ pull-lp-source xorg-server-lts-quantal precise

然後再執行:

$ sudo gdb /usr/bin/Xorg 1044 -d xorg-server-lts-quantal-1.13.0

最後 GDB 有其它的 Frontend 可以使用,像是 cgdb 以及 ddd 在這裡就不多提了。

2013年7月31日 星期三

Linux 電源供應的系統資訊

在筆記型電腦或是使用藍牙裝置時,系統上面都會有電源供應的資訊。

只要在 /sys/devices 底下找尋 power_supply 的目錄就可以找到。

如下所示:

u@u:/sys/devices$ find -name power_supply | while read path; do ls -l $(dirname $path); done
total 0
lrwxrwxrwx 1 root root    0 Jul 31 17:42 driver -> ../../../../../../../../../../bus/hid/drivers/apple
drwxr-xr-x 3 root root    0 Jul 31 17:38 hidraw
-r--r--r-- 1 root root 4096 Jul 31 17:42 modalias
drwxr-xr-x 2 root root    0 Jul 31 17:39 power
drwxr-xr-x 3 root root    0 Jul 31 17:39 power_supply
-r--r--r-- 1 root root 4096 Jul 31 17:42 report_descriptor
lrwxrwxrwx 1 root root    0 Jul 31 17:38 subsystem -> ../../../../../../../../../../bus/hid
-rw-r--r-- 1 root root 4096 Jul 31 17:38 uevent
total 0
lrwxrwxrwx 1 root root    0 Jul 31 17:42 driver -> ../../../../../../../../../../bus/hid/drivers/magicmouse
drwxr-xr-x 3 root root    0 Jul 31 17:39 hidraw
-r--r--r-- 1 root root 4096 Jul 31 17:42 modalias
drwxr-xr-x 2 root root    0 Jul 31 17:39 power
drwxr-xr-x 3 root root    0 Jul 31 17:39 power_supply
-r--r--r-- 1 root root 4096 Jul 31 17:42 report_descriptor
lrwxrwxrwx 1 root root    0 Jul 31 17:39 subsystem -> ../../../../../../../../../../bus/hid
-rw-r--r-- 1 root root 4096 Jul 31 17:39 uevent
total 0
lrwxrwxrwx 1 root root    0 Jul 31 17:42 driver -> ../../../../../../bus/acpi/drivers/battery
-r--r--r-- 1 root root 4096 Jul 31 17:42 hid
-r--r--r-- 1 root root 4096 Jul 31 17:42 modalias
-r--r--r-- 1 root root 4096 Jul 31 17:42 path
drwxr-xr-x 2 root root    0 Jul 31 17:39 power
drwxr-xr-x 3 root root    0 Jul 31 17:36 power_supply
lrwxrwxrwx 1 root root    0 Jul 31 17:36 subsystem -> ../../../../../../bus/acpi
-rw-r--r-- 1 root root 4096 Jul 31 17:36 uevent
total 0
lrwxrwxrwx 1 root root    0 Jul 31 17:42 driver -> ../../../../../../bus/acpi/drivers/ac
-r--r--r-- 1 root root 4096 Jul 31 17:42 hid
-r--r--r-- 1 root root 4096 Jul 31 17:42 modalias
-r--r--r-- 1 root root 4096 Jul 31 17:42 path
drwxr-xr-x 2 root root    0 Jul 31 17:39 power
drwxr-xr-x 3 root root    0 Jul 31 17:36 power_supply
lrwxrwxrwx 1 root root    0 Jul 31 17:36 subsystem -> ../../../../../../bus/acpi
-rw-r--r-- 1 root root 4096 Jul 31 17:36 uevent

所以可以從 driver 這個 symbolic link 看出每個電源供應是屬於哪些裝置。

另外也可以使用指令來監測 udev 裡面關於 power_supply 的訊息。

如下所示:

u@u:~$ udevadm monitor --subsystem-match=power_supply                                                                                                                                                      
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[65.358427] change   /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/bluetooth/hci0/hci0:13/0005:05AC:030D.0002/power_supply/hid-AB:CD:EF:12:34:56-battery (power_supply)
UDEV  [65.398449] change   /devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1:1.0/bluetooth/hci0/hci0:13/0005:05AC:030D.0002/power_supply/hid-AB:CD:EF:12:34:56-battery (power_supply)
KERNEL[81.032204] change   /devices/LNXSYSTM:00/device:00/PNP0A08:00/device:0c/PNP0C0A:00/power_supply/BAT1 (power_supply)
UDEV  [81.033615] change   /devices/LNXSYSTM:00/device:00/PNP0A08:00/device:0c/PNP0C0A:00/power_supply/BAT1 (power_supply)

最後就是 Freedesktop 有一個 UPower 專案,專門用來提供底層電源資訊的介面給桌面應用程式來使用。

如果是在 GNOME 桌面環境底下就是 gnome-settings-daemon 與 gnome-power-manager 透過 DBus 來使用 UPower 以提供圖形介面給桌面使用者使用。

2013年5月13日 星期一

自製 Ubuntu 13.04/12.10/12.04.2 與 Debian 7.0 測試硬體安裝使用的 USB 隨身碟

為了同時可以在 Legacy BIOS 與 UEFI BIOS 上使用的,首先使用 Ubuntu 12.04.2 以上內建的 usb-creator-gtk 工具來產生一個 Ubuntu 13.04 desktop amd64 的 USB 隨身碟來用。

$ usb-creator-gtk -n -i ubuntu-13.04-desktop-amd64.iso

接下來的動作,只要使用 Ubuntu 13.04 的 Live System (amd64) 就可以了,不用安裝到硬碟上面。

進入 Ubuntu 13.04 Live System (amd64) 之後,執行以下指令。

ubuntu@ubuntu:~$ sudo apt-get install grub-pc-bin grub-efi-amd64-bin                                                                                                                                       
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
grub-pc-bin 已經是最新版本了。
下列【新】套件將會被安裝:
  efibootmgr grub-efi-amd64-bin
升級 0 個,新安裝 2 個,移除 0 個,有 0 個未被升級。
需要下載 0 B/581 kB 的套件檔。
此操作完成之後,會多佔用 2,316 kB 的磁碟空間。
選取了原先未選的套件 efibootmgr。
(讀取資料庫 ... 目前共安裝了 161462 個檔案和目錄。)
解開 efibootmgr(從 .../efibootmgr_0.5.4-4ubuntu1_amd64.deb)...
選取了原先未選的套件 grub-efi-amd64-bin。
解開 grub-efi-amd64-bin(從 .../grub-efi-amd64-bin_2.00-13ubuntu3_amd64.deb)...
執行 man-db 的觸發程式 ...
設定 efibootmgr (0.5.4-4ubuntu1) ...
設定 grub-efi-amd64-bin (2.00-13ubuntu3) ...

將另外一隻 USB 隨身碟插入 USB 埠,執行以下指令。

ubuntu@ubuntu:~$ sudo grub-install --removable --target=i386-pc --root-directory=/media/ubuntu/UsbStick/ /dev/sdc
Installation finished. No error reported.
ubuntu@ubuntu:~$ sudo grub-install --removable --target=x86_64-efi --root-directory=/media/ubuntu/UsbStick/ /dev/sdc
/usr/sbin/grub-probe: error: failed to get canonical path of /cow.
Installation finished. No error reported.

請將以上的 /dev/sdc 與 /media/ubuntu/UsbStick/ 代換成符合實際使用環境上的字串。

接下來將 grub.cfg 放到 /media/ubuntu/UsbStick/boot/grub/ 底下。

最後再將相對應的 ISO 檔案都放到 /media/ubuntu/UsbStick/iso/ 底下就可以了。

之後只要針對 grub.cfg 的內容做調整加入需要的選項即可。

這樣一來就可以在安裝前先測試看看硬體的相容性,再來決定要不要安裝到硬碟裡面。

P.S. Ubuntu 上面有些無線網路的驅動程式是要安裝到硬碟裡面重新啟動才會正常運作的。

2012年12月24日 星期一

Quick - an installation helper for GNU/Linux.

我自己平時都是使用 Debian/Ubuntu 裡面的 APT 來安裝軟體套件,就連自己寫了一些小軟體也是會放到 PPA 上面,然後再透過 APT 下載回來安裝,但是並不是所有的軟體都有 Open Source 或是有人有準備好 PPA 可以直接透過 APT 來安裝。

於是乎,我花了兩三天的時間製作了這個簡單的工具用來管理這些額外的軟體。

Quick - an installation helper for GNU/Linux.

使用方式就是執行下面這段指令來安裝:

$ wget http://bit.ly/quick-installer -O - | bash -

安裝完成之後要先登出,再重新登入系統。

接下來執行以下指令來安裝更新套件列表:

$ quick update

然後再執行以下指令來安裝軟體套件:

$ quick install sublime-text

安裝後,想要移除掉就執行:

$ quick remove sublime-text

其它使用方式執行以下指令來看說明。

$ quick

2011年7月24日 星期日

關於 uptime 的一些小事

在 GNU/Linux 系統底下如果想要知道電腦開機後使用了多久的時間,可以直接打指令:
$ uptime
 22:35:06 up  6:26,  4 users,  load average: 0.00, 0.03, 0.05
或是利用 /proc/uptime 來取得資料:
$ cat /proc/uptime 
23282.04 41316.79
但是如果想要寫 C 程式來取得資料呢?
我找到一個在 <time.h> 裡面的函式 clock_gettime()
程式碼如下:
#include <stdio.h>
#include <time.h>

int main(int argc, char* argv[])
{
    struct timespec ts;
    if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
        printf("%ld.%ld\n", ts.tv_sec, ts.tv_nsec);
    }
    return 0;                                      
}
在編譯的時候要加上 -lrt 才能通過編譯
$ gcc -Wall -g -lrt uptime.c -o uptime
執行的結果
$ ./uptime 
23637.821285555
因為我想要在 XWindow 底下根據當下的開機時間,製造出新的 XKeyEvent 出來,而所有的 XEvent 都是使用毫秒的時間格式 (ex. 23637821),所以才去找出這個的函式來用。
詳細的使用說明可以看 manpage
$ man clock_gettime

2011年1月31日 星期一

一個好用的 irssi plugin - irssi-libnotify

irssi 是一個在終端機文字模式下面連 IRC 的工具
通常 irssi 的使用方式是搭配 screen 或是 tmux
然後找一台一直開著 BSD/Linux 主機在上面掛著
不過也有的人用久了即使是在本機上面使用也是開 irssi
然後就會開始想著有沒有辦法在別人丟你訊息的時候能夠在桌面上跳出通知
irssi-libnotify 就是這樣的工具
在 GNU/Linux 上面使用要另外搭配 notify-send 這個指令
如果使在 Ubuntu 上面就是直接安裝 libnotify-bin 這個套件

首先把 notify.pl 裝進 .irssi/scripts/ 底下
$ mkdir -p ~/.irssi/scripts/
$ wget http://irssi-libnotify.googlecode.com/svn/trunk/notify.pl -O ~/.irssi/scripts/notify.pl

使用方法是在 irssi 啟動後輸入
/load perl
/script load notify

這樣之後當別人丟訊息的時候就會收到桌面通知了~ :)

P.S. 目前有中文亂碼的問題

2010年6月26日 星期六

BetaRadio v1.0 網路廣播點播器 正式釋出

BetaRadio 因為 hichannel 網頁不斷地改版,最後碰到了 libmms 這個函式庫的一個 bug 所以專案就一直呈現死掉的狀態;不過最近終於有時間能夠找出 libmms 的 bug 並且修正,所以才能夠再次地讓這個純 C 語言寫出來的網路廣播點播器復活。

Source code tarball 可以在 http://code.google.com/p/betaradio/downloads/list 下載
相依一個特別的函式庫 json-cat 可以在 http://github.com/fourdollars/json-cat/downloads 下載 Source code tarball

另外就是特別為 Ubuntu 10.04 使用者準備好一個 PPA 可以馬上裝起來就可以使用了。

GUI 安裝方式 [系統]->[管理]->[軟體來源] 裡面的 [其它軟體] 點擊 [加入] 後輸入
ppa:fourdollars/lucid
然後關閉 [軟體來源] 選擇 [重新載入] 
再打開 [系統]->[管理]->[Synaptic套件管理程式] 搜尋 betaradio 就可以找到來安裝了

或是可以使用命令列輸入來安裝
$ sudo apt-add-repository ppa:fourdollars/lucid
$ sudo apt-get update
$ sudo apt-get install betaradio
安裝完就可以在 [應用程式]->[影音] 裡面看到 "BetaRadio 點播器" 點一下就可以使用了~ :)

2010年5月5日 星期三

自製 Ubuntu 10.04 Desktop/Server/Alternate/DVD ISO i386/amd64 安裝用 USB 隨身碟

首先要準備安裝用的 ISO 檔案
ubuntu-10.04-alternate-amd64.iso
ubuntu-10.04-alternate-i386.iso
ubuntu-10.04-desktop-amd64.iso
ubuntu-10.04-desktop-i386.iso
ubuntu-10.04-dvd-amd64.iso
ubuntu-10.04-dvd-i386.iso
ubuntu-10.04-server-amd64.iso
ubuntu-10.04-server-i386.iso
然後準備一隻容量至少 1GB 的 USB 隨身碟;如果要使用 DVD ISO 來製作的話,USB 隨身碟要準備容量至少 8GB 以上;如果想要製作多重開機的話,就準備容量越大越好的 USB 隨身碟,大到足夠塞進所有想要放進去的 ISO 檔案。

Ubuntu 10.04 Alternate/Server 安裝用 USB 隨身碟製作方法
$ wget http://archive.ubuntu.com/ubuntu/dists/lucid/main/installer-i386/current/images/hd-media/boot.img.gz
$ sudo dd if=/dev/zero of=/dev/sdc count=512
$ sudo su -c "zcat boot.img.gz > /dev/sdc"
等待約五分鐘完成後,再執行以下步驟就完成了。

$ sudo mount /dev/sdc /mnt
$ sudo cp -av ubuntu-10.04-alternate-i386.iso /mnt
$ sudo umount /mnt
以上粗體字的部份需要根據需求調整,例如 sdc -> sdb 或 alternate -> server 或 i386 -> amd64

Ubuntu 10.04 Desktop/DVD 安裝用 USB 隨身碟製作方法

先使用 fdisk 或是 gparted 將隨身碟分割好再進行以下步驟

$ sudo mkfs.vfat /dev/sdc1
$ sudo mount /dev/sdc1 /mnt
$ sudo grub-install --no-floppy --root-directory=/mnt /dev/sdc
然後再新增一個檔案 /mnt/boot/grub/grub.cfg 內容如下

menuentry "Ubuntu 10.04 Desktop i386" {
  loopback loop /iso/ubuntu-10.04-desktop-i386.iso
  linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/ubuntu-10.04-desktop-i386.iso noeject noprompt --
  initrd (loop)/casper/initrd.lz
}
記得要把 ISO 檔案複製進 USB 隨身碟

$ sudo mkdir /mnt/iso
$ sudo cp -av ubuntu-10.04-desktop-i386.iso /mnt/iso
$ sudo umount /mnt
以上粗體字的部份需要根據需求調整,例如 sdc -> sdb 或 desktop -> dvd 或 i386 -> amd64

Desktop/DVD 的製作比較有彈性,只要在 grub.cfg 裡面增加 menuentry 就可以了,所以可以輕易地製作出多重 ISO 開機的 USB 隨身碟。

P.S. DVD 的部份因為筆者本身沒有 8GB 以上的 USB 隨身碟,所以沒有驗證過,不過應該是可以可行的。

2010年4月23日 星期五

使用 GnuPG 驗證 Ubuntu 10.04 LTS RC 安裝光碟 ISO 檔

首先到台灣的 Mirror Site 上面下載相關的檔案回來
$ wget http://tw.releases.ubuntu.com/10.04/SHA1SUMS
$ wget http://tw.releases.ubuntu.com/10.04/SHA1SUMS.gpg
$ wget http://tw.releases.ubuntu.com/10.04/ubuntu-10.04-rc-desktop-i386.iso
利用 SHA1SUMS.gpg 來檢查 SHA1SUMS 是否為 Ubuntu 官方釋出的檔案 (有可能是經過偽造的)
$ gpg --verify SHA1SUMS.gpg SHA1SUMS
gpg: 由 2010年04月22日 (週四) 21時22分58秒 CST 建立的簽章, 使用 DSA 金鑰 ID FBB75451
gpg: 無法檢查簽章: 找不到公鑰
在 Ubuntu 系統上一開始檢查一定會找不到,不過可以透過 apt-key list 找到公鑰
$ sudo apt-key list
/etc/apt/trusted.gpg
--------------------
pub   1024D/437D05B5 2004-09-12
uid                  Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>
sub   2048g/79164387 2004-09-12

pub   1024D/FBB75451 2004-12-30
uid                  Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>
那麼就可以使用 apt-key export 取出公鑰
$ sudo apt-key export FBB75451 > cdimage.gpg
接下來在匯入 GnuPG 的金鑰鑰匙圈裡
$ gpg --import cdimage.gpg
gpg: 金鑰 FBB75451: 公鑰 "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>" 已匯入
gpg: 處理總量: 1
gpg:               已匯入: 1
gpg: 3 個勉強信任以及 1 個完全信任是 classic 信任模型的最小需求
gpg: 深度: 0  有效:   3  已簽署:  18  信任: 0-, 0q, 0n, 0m, 0f, 3u
gpg: 深度: 1  有效:  18  已簽署:  12  信任: 5-, 0q, 0n, 13m, 0f, 0u
gpg: 深度: 2  有效:   2  已簽署:   2  信任: 2-, 0q, 0n, 0m, 0f, 0u
gpg: 下次信任資料庫檢查將於 2012-07-13 進行
這時候再重新執行前面第一行指令
$ gpg --verify SHA1SUMS.gpg SHA1SUMS
gpg: 由 2010年04月22日 (週四) 21時22分58秒 CST 建立的簽章, 使用 DSA 金鑰 ID FBB75451
gpg: 完好的簽章來自於 "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>"
gpg: 警告: 這把金鑰並非以受信任的簽章所認證!
gpg:          沒有證據指出這個簽章屬於這個持有者.
主鑰指紋: C598 6B4F 1257 FFA8 6632  CBA7 4618 1433 FBB7 5451
出現這個警告的原因是因為還沒有將 FBB75451 這把公鑰加進自己的信任小圈圈裡面
不過不要緊,假設我們能夠信任 Ubuntu 系統裡面本來就有的公鑰 (如果不能信任的話,那就不應該繼續使用你的 Ubuntu 系統了 :P)
所以現在可以相信 SHA1SUMS 這個檔案真的是 Ubuntu 官方釋放出來的
於是就可以使用指令 sha1sum 來檢查 ubuntu-10.04-rc-desktop-i386.iso 這個檔案的完整性了
$ grep ubuntu-10.04-rc-desktop-i386.iso SHA1SUMS
66227f4fb31a25a22614666cd4ab538cc8f60956 *ubuntu-10.04-rc-desktop-i386.iso
$ sha1sum ubuntu-10.04-rc-desktop-i386.iso
66227f4fb31a25a22614666cd4ab538cc8f60956  ubuntu-10.04-rc-desktop-i386.iso
嗯~ 沒錯我下載的 ISO 真的是 Ubuntu 官方釋出的版本~ :D

參考資料:http://wiki.debian.org.tw/index.php/GnuPG

2010年4月20日 星期二

Linux 系統上面的免費防毒軟體 avast! Linux Home Edition

官方網頁在 http://www.avast.com/linux-home-edition
在 Download 底下就可以下載到安裝的套件包了
每次使用前要先到 http://www.avast.com/registration-free-antivirus.php 上面申請 license key
如果遇到 crash 的問題可以試試看
  • $ sudo sysctl -w kernel.shmmax=128000000

也許可以解決問題

參考資料:
http://forum.avast.com/index.php?topic=57775.0