聚會時間公告: 因應COSCUP 2011, Kalug 8月份休會一次

二月 13, 2011
» 利用 cowbuilder 建立不同的debian package 編譯環境

前言

在編譯Debian Package 時, 開發者常使用 pbuilder 建立乾淨的root filesystem, 並且在其中編譯,如此才不會有相依性不完整, 或是少檔案等在原始開發環境難以發現的錯誤 (因為開發環境會安裝所需的套件)

而 cowbuilder 與 pbuilder 的不同為 cowbuilder 並不會將建立好的 root filesystem 壓縮, 因此在編譯套件時可以省下解壓縮 root filesystem的時間。

安裝相關套件

user@host# sudo apt-get install cowbuilder debootstrap devscripts

將下面內容寫入 .pbuilderrc

export CCACHE_DIR="/var/cache/ccache"
export PATH="/usr/lib/ccache:${PATH}"

EXTRAPACKAGES="${EXTRAPACKAGES} ccache pbuilder cowdancer cowbuilder devscripts gnupg patchutils vim-tiny"
BINDMOUNTS="${BINDMOUNTS} ${CCACHE_DIR}"
COMPONENTS="main restricted universe multiverse"
PDEBUILD_PBUILDER=cowbuilder

UNSTABLE_CODENAME="sid"
TESTING_CODENAME="wheezy"
STABLE_CODENAME="squeeze"
STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports"

# List of Debian suites.
DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME
"unstable" "testing" "stable")

# List of Ubuntu suites. Update these when needed.
UBUNTU_SUITES=("natty" "maverick" "lucid" "karmic" "jaunty" "hardy")

# Mirrors to use. Update these to your preferred mirror.
DEBIAN_MIRROR="ftp.tw.debian.org"
UBUNTU_MIRROR="mirrors.kernel.org"

# Optionally use the changelog of a package to determine the suite to use if
# none set.
if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; then
DIST=$(dpkg-parsechangelog | awk ‘/^Distribution: / {print $2}’)
# Use the unstable suite for certain suite values.
if $(echo "experimental UNRELEASED" | grep -q $DIST); then
DIST="$UNSTABLE_CODENAME"
fi
fi

# Optionally set a default distribution if none is used. Note that you can set
# your own default (i.e. ${DIST:="unstable"}).
: ${DIST:="$(lsb_release –short –codename)"}

# Optionally change Debian release states in $DIST to their names.
case "$DIST" in
unstable)
DIST="$UNSTABLE_CODENAME"
;;
testing)
DIST="$TESTING_CODENAME"
;;
stable)
DIST="$STABLE_CODENAME"
;;
esac

# Optionally set the architecture to the host architecture if none set. Note
# that you can set your own default (i.e. ${ARCH:="i386″}).
: ${ARCH:="$(dpkg –print-architecture)"}

NAME="$DIST"
if [ -n "${ARCH}" ]; then
NAME="$NAME-$ARCH"
DEBOOTSTRAPOPTS=("–arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
fi
#BASETGZ="/var/cache/pbuilder/$NAME-base.tgz"
# Optionally, set BASEPATH (and not BASETGZ) if using cowbuilder
BASEPATH="/var/cache/pbuilder/$NAME-base.cow/"
DISTRIBUTION="$DIST"
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
BUILDPLACE="/var/cache/pbuilder/build/"

if $(echo ${DEBIAN_SUITES[@]} | grep -q $DIST); then
# Debian configuration
MIRRORSITE="http://$DEBIAN_MIRROR/debian/"
COMPONENTS="main contrib non-free"
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "–keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
# This is for enabling backports for the Debian stable suite.
if $(echo "$STABLE_CODENAME stable" | grep -q $DIST); then
EXTRAPACKAGES="$EXTRAPACKAGES debian-backports-keyring"
OTHERMIRROR="$OTHERMIRROR | deb http://www.backports.org/debian $STABLE_BACKPORTS_SUITE $COMPONENTS"
fi
elif $(echo ${UBUNTU_SUITES[@]} | grep -q $DIST); then
# Ubuntu configuration
MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/"
COMPONENTS="main restricted universe multiverse"
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "–keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg")
else
echo "Unknown distribution: $DIST"
exit 1
fi

當 ubuntu 或 debian 有新的release時需要修改的變數

UNSTABLE_CODENAME="sid"
TESTING_CODENAME="wheezy"
STABLE_CODENAME="squeeze"
# List of Ubuntu suites. Update these when needed.
UBUNTU_SUITES=("natty" "maverick" "lucid" "karmic" "jaunty" "hardy")

設定 sudo

由於sudo後環境變數並不會延用, 因此我們要設定DIST, ARCH sudo後仍然維持原值, 修改 /etc/sudoers

8 #Defaults->>>>>>env_reset
9 Defaults env_reset,env_keep="DIST ARCH"

使用方式

環境變數 DIST 代表要使用哪個serias, 例如我要建立debian unstable 的chroot

# 若要建立的chroot是debian, 需要安裝keyring
user@host# sudo apt-get install debian-archive-keyring
user@host# sudo DIST=unstable cowbuilder –create
# 產生好的chroot 為 /var/cache/pbuilder/sid-i386-base.cow

編譯 package

# 使用 pdebuild
user@host# sudo DIST=unstable pdebuild
#也可使用 git-buildpackage 編譯 package (個人推薦使用git-buildpackage管理debian package)
user@host$ sudo DIST=unstable git-buildpackage –git-upstream-tag=$ver –git-debian-branch=debian –git-
builder=pdebuilder
# 編好的套件在 /var/cache/pbuilder/sid-i386/result/

另外也可使用環境變數 ARCH 來指定要用amd64 or arm等其他架構,預設值為你電腦的架構

延伸閱讀

一月 26, 2011
» [筆記] Debconf 規格

規格可能會變動,請同時參閱原始文件

Debconf

  • Debian Linux 用來設定管理系統。
  • 不同的 debian 套件可以使用此系統分享設定值,也可以使用套件名稱存儲該套件專有的設定值
  • 不使用資料庫,只使用檔案來存放設定值,位置在 /var/cache/debconf/config.dat

Template

格式與 Debian Package control file 一樣,為 rfc-822 compliant format
使用 metadata 來描述設定選項,下為範例

Template: hostname
Type: string
Default: debian
Description: unqualified hostname for this computer
 This is the name by which this computer will be known on the network. It
 has to be a unique name in your domain.

說明:

Template: 設定選項名稱
Type: 設定值類型
Default: 預設值
Description: 短描述
長描述

Available data types

  • string 字串
  • boolean 真假值
  • select 單選,使用Choices欄位指定 用逗號與空格分開可能的值 Ex. Choices: yes, no, maybe
  • multiselect 多選, 與select相同
  • note 用於顯示使用者必須要讀的文字。無法顯示則會被存在紀錄黨內。
  • text 文字
  • password 密碼, 明碼除存
  • title 可用 SETTITLE command 設定的字串

讀取與存入設定值

回傳狀態值 0 為成功,其餘皆為錯誤

操作命令

  • SETTITLE template :
    • 設定前端介面的Titile
  • INPUT priority question:
    • 告訴前段介面要顯示該問題, 前段介面只會顯示 priority 比使用者設定高的問題.
    • 在GO命令執行前,問題不會被顯示,所以我們能在一個畫面內指定要顯示幾個問題
  • GET question
    • 取得使用者回答的設定值
  • Set question value
    • 除存使用者回答的設定值
  • Reset question
    • 將除存的設定還原成預設值
  • SUBST
    • 類似 sprintf的功用, 被替換的字通成使用 ${key} 表示
  • FGET
    • 取得問題的 flag 值, 最常用的 flag 是 seen, 當為 false 時,該問題被忽略
  • FSET
    • 設定 flag 值
  • METAGET
    • 取得 question 的欄位, 例如 Type
  • Register:
    • 建立一個新的 question
  • PURGE:
    • 清空設定

延伸閱讀

五月 3, 2010
» How to mount .img file

Forwared

If you want to modify the contents of Ubuntu live-usb for some reason.  here is the tipto describe how to do that.

General way

1. Get block size and sector offset, in here, the sector is 1, block size is 512

hychen@mluna:~/Projects/myimg/aimgs$ fdisk -l -u -C 1 binary.img
Disk binary.img: 0 MB, 0 bytes
241 heads, 26 sectors/track, 1 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x0009ee21
Device Boot      Start         End      Blocks   Id  System
binary.img1   *           1     1396735      698367+  83  Linux
Partition 1 has different physical/logical endings:
phys=(86, 240, 26) logical=(222, 218, 16)
2. bind with loop device, 512 is sector offset * block size.
user@host# losetup -o 512 /dev/loop1 binary.img

3. mount loop device to what mount point (/mnt)

user@host# mount /dev/loop1 /mnt

Lazy way

You can dowanload my script from http://people.canonical.com/~hychen/scripts/imgctrl

1. Mount

user@host$ imgctrl -m binary.img /mnt

2. Umount

user@host$ imgctrl -u binary.img

A Feedjack powered Planet
A Django site.