Below I give some simple command to run a ubuntu:16.04 lxd container. LXD container is fast, very efficient, very low-footprint virtual machine. I recommend people who didn’t need low-level system control (such as disk, loopback device) give it a try. I think this kind of lightweight virtual machine would benefit people who study machine learning or similar scientific computing.

# check current status of lxd. If you install lxd the first time, it should containing no virtual machines.
lxc list

# if my-ubuntu virtual machine not exist yet.
lxc launch ubuntu:16.04 my-ubuntu
# if my-ubuntu virtual machine already exist.
lxc start my-ubuntu

# check status of my-ubuntu virtual machine
lxc list

# login to root account
lxc exec first -- /bin/bash
# or login to ubuntu account
lxc exec first -- /bin/su - ubuntu

# stop the virtual machine
lxc stop my-ubuntu

# you can even copy virtual machine
lxc copy my-ubuntu my-ubuntu2
# or rename it
lxc mv my-ubuntu stanley-ubuntu
lxc mv stanley-ubuntu my-ubuntu

# delete my-ubuntu virtual machine
lxc delete my-ubuntu

# check my-ubuntu is deleted
lxc list

Varies images is provided by Canonical in http://images.linuxcontainers.org/

Note that lxd has some limitaions. Such as you can’t - setup loopback device - mount fuse file system - have bridged network. - load/remove kernel module … (But if you choose to run a priviledged lxd virtual machine, some limitations might not exist anymore. But I haven’t dig into it currently.)

Note that this article introduces how to build Debian/Ubuntu LiveCD iso image from scratch. With this method, you have great flexibility to customize the LiveCD.

However, if you only want to customize the LiveCD a little bit. Such as adding some packages for installation, or changing the preseed configuration, you can refer to DebianCustomCD, Simple-CDD and LiveCDCustomization

Debian Jessie

# within Debian jessie
git clone git://anonscm.debian.org/git/debian-live/live-build.git
cd live-build
git checkout debian/4.0.5-1
dpkg-buildpackage -b -uc -us
cd ..
sudo dpkg -i live-build_4.0.5-1_all.deb

sudo apt-get install -y live-images
cp -r /usr/share/live/images/standard .
cd standard/
lb config --source false # optional, would be faster if not build source
sudo lb build
# here we got live-image-amd64.hybrid.iso, about 417MB
# refer to http://cdimage.debian.org/mirror/cdimage/archive/8.6.0-live/amd64/iso-hybrid/debian-live-8.6.0-amd64-standard.iso.log for more information

Ubuntu Xenial 16.04

Automatically build with ubuntu-defaults-builder

sudo apt install -y ubuntu-defaults-builder
sudo apt install -y syslinux-utils
ubuntu-defaults-template myconfig
cd myconfig/
dpkg-buildpackage
cd ../
ubuntu-defaults-image --package myconfig_0.1_all.deb --components main,restricted,universe,multiverse

# here we got binary.hybrid.iso and livecd.ubuntu.iso

build with ubuntu-cdimage

TODO:

Manually build with live-build (Not working right now, might need hooks to allow booting)

# First, set up the build tools and workspace.
# The scripts require that you work in /build

sudo apt-get install -y genisoimage syslinux-utils # tools for generate ISO image
sudo apt-get install -y memtest86+ syslinux syslinux-themes-ubuntu-xenial gfxboot-theme-ubuntu

sudo -i
apt-get install -y livecd-rootfs
mkdir -p /build/chroot
cd /build
cp -a /usr/share/livecd-rootfs/live-build/auto .

# All the hard work is done with live-build (lb command)
# and we have to configure it with environment variables

export SUITE=xenial
export ARCH=amd64
export PROJECT=ubuntu
export MIRROR=http://archive.ubuntu.com/ubuntu/
export BINARYFORMAT=iso-hybrid
export LB_SYSLINUX_THEME=ubuntu-xenial

# Now we can have live-build set up the workspace

lb config --initramfs-compression=gzip 

# And finally, start the build

lb build

Ref: [1] https://code.launchpad.net/~semiosis/livecd-rootfs/fix-for-1565985/+merge/298305/comments/768010 [2] Ubuntu live filesystem builds moved to live-build [3] LocalizedCDImageTools - Ubuntu Wiki [4] ISO with l10 preloaded for LoCo + UEFI [5] UbuntuStudio/Seeds - Ubuntu Wiki [6] Building large-scale Ubuntu derivatives using seeds - Google Docs [7] ReleaseTeam/CDImageSetup - Ubuntu Wiki

I highly recommened pudb, which is a full-screen, console-based visual debugger for Python. The user-interface is nicely designed for python developers.

Here is an example debugging a simple python script: Introduction to the PuDB Python Debugging Tool

Also, another great tutorial is from Jordi Gutiérrez Hermoso. Montreal, QC, September 14, 2015 - Jordi Gutiérrez Hermoso presents PuDB, a full-screen, console-based visual debugger for Python. An interesting comment from the speaker: > Everyone should use a debugger > … > > But If pdb is the only debugger you’ve every seen, I won’t blame you not using a debugger > > … > because the debugger is ugly, not because the source code is ugly

To install pudb on Debian/Ubuntu, you can use apt-get to install the package

# for python 2
sudo apt-get -y python-pudb
# for python 3
sudo apt-get -y python3-pudb

# pudb is even better when debugging with ipython
# so that's install ipython
sudo apt-get install ipython

最近換了一台工作機,但我發現在 Ubuntu 14.04.3 上,有時候會休眠失敗。 在失敗的時候,機器有 suspend 成功,但是過2秒後機器就會自動醒來。查看了 /var/log/kern.log, /var/log/syslog, /var/log/pm-suspend.log 沒有太異常的訊息。後來上網查了一下,這可能是有 BIOS 有問題或 device 不正常運作。

在 /proc/acpi/wakeup 中,列出了數種 wakeup event, 以下面的表來說,代表了機器開放了 EHC1, EHC2, PWRB, LID0 這幾種 wakeup event

RP06      S4    *disabled
PXSX      S4    *disabled
RP07      S4    *disabled
PXSX      S4    *disabled
EHC1      S0    *enabled   pci:0000:00:1d.0
EHC2      S4    *enabled  pci:0000:00:1a.0
PWRB      S4    *enabled   platform:PNP0C0C:00
LID0      S4    *enabled   platform:PNP0C0D:00

試著開關 wakeup trigger 來找出問題

# ignore XHC device wakeup event
echo "XHC" > /proc/acpi/wakeup
# try suspend, still failed

# ignore EHC1 device wakeup event
echo "EHC1" > /proc/acpi/wakeup
# try suspend, still failed

# ignore EHC1 device wakeup event
echo "EHC2" > /proc/acpi/wakeup
# try suspend. Bingo!! It suspend successfully!

發現只要關閉 EHC2 wakeup trigger, 機器就能正常 suspend。可以放罝一個 upstart script,讓每次開機時,都自動關閉 EHC2 wakeup trigger

# /etc/init/disable-EHC2.conf
start on started dbus
stop on stopping dbus

script
   sudo -u root sh -c "echo 'EHC2' > /proc/acpi/wakeup"
end script

Ref: - Ubuntu 14.04 wake up immediately after suspend - Ask Ubuntu - UnderstandingSuspend - Ubuntu Wiki - Power management/Suspend and hibernate - ArchWiki - acpitool(1) - Linux man page - Best practice to debug Linux* suspend/hibernate issues | 01.org

Addressing global exploration effectively is only one of the significant challenges between what is well known now and what needs to be addressed for what I would consider a real AI.

Ref: AlphaGo is not the solution to AI

今天發現可以透過 Canonical Ltd. 的 linuxcontainer image 快速的在 NAS 上建立一個 chroot 環境。我的機器 cpu 是 armhf ,下面示範建立 Ubuntu 15.04 Vivid 的 chroot 環境。

步驟1:下載 Image,解開後進入 rootfs,並修改 nameserver

wget http://images.linuxcontainers.org/images/ubuntu/vivid/armhf/default/20151008_03:49/rootfs.tar.xz
mkdir rootfs
tar xvf rootfs.tar.xz -C rootfs
cd rootfs
echo "nameserver 8.8.8.8" > etc/resolv.conf

步驟2:mount 需要的 sysfs

mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
mount -t devpts pts dev/pts/

步驟3:chroot

chroot . su -l

backports driver
2015-09-17

git clone git://git.kernel.org/pub/scm/linux/kernel/git/backports/backports.git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
cd backports/
./gentree.py --clean --git-revision next-20150525 ../linux-next/ release

cd release/
make menuconfig
make

手上有一支 UPMOST DVB193 數位電視棒,最近測試了它是不是能在 Ubuntu 14.04 下運作。原本以為需要自己編譯 driver,不過把數位電視棒插入筆電, lsusb 後發現其實 driver 已被 Kernel 收錄成為 built-in driver。 Driver 的訊息如下

filename:       /lib/modules/3.19.0-28-generic/kernel/drivers/media/tuners/it913x.ko
license:        GPL
author:         Antti Palosaari <crope@iki.fi>
description:    ITE IT913X silicon tuner driver
srcversion:     3A631200871E9FCB4913859
alias:          i2c:it913x
depends:        
intree:         Y
vermagic:       3.19.0-28-generic SMP mod_unload modversions 
signer:         Magrathea: Glacier signing key
sig_key:        29:4D:C0:12:70:6F:48:B7:CD:DF:63:74:E2:D7:9F:E1:B0:60:92:69
sig_hashalgo:   sha512

Firmware 也已經被收進 Ubuntu 的 linux-firmware

$ dpkg -L linux-firmware| grep it9135
/lib/firmware/dvb-usb-it9135-02.fw
/lib/firmware/dvb-usb-it9135-01.fw

所以接下來只要處理好看數位電視的軟體就可以。以 apt-get 安裝好 vlc ,再用 vlc 開啟 channels.conf

channels.conf

中視數位台:533000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:1001:1002:100
中視新聞台:533000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:1011:1012:101
中視綜藝台:533000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:1021:1022:102
中視 HD 台:533000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:1031:1032:103
公共電視 PTS:545000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:2011:2012:201
公視 2 台 PTS2:545000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:2021:2022:202
客家電視 HTV:545000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:2031:2032:203
民視綜合台:557000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:3001:3002:300
民視交通台:557000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:3011:3012:301
民視新聞台:557000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:3021:3022:302
民視資料廣播:557000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:0:0:303
民視 HD 台:557000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:3041:3042:304
公視 HD:569000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:2001:2002:200
台灣電視台:581000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4001:4002:400
台視財經台:581000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4011:4012:401
台視綜合台:581000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4021:4022:402
台視 HD 台:581000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4031:4032:403
華視 CTS:593000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:5011:5012:501
華視教育台:593000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:5021:5022:502
華視新聞資訊台:593000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:5031:5032:503
華視 HD:593000000:INVERSION_AUTO:BANDWIDTH_6_MHZ:FEC_2_3:FEC_2_3:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:5041:5042:504

就可以收看了。過程相當順利。

如果未來台灣有新增或更新頻道,想要自己產生頻道列表,那可以這樣做:

sudo apt-get install -y dvb-apps
sudo apt-get install vlc
scan /usr/share/dvb/dvb-legacy/dvb-t/tw-All >channels.conf

這個 channels.conf ,就可以用 vlc 打開收看。

Update for Debian 9.0 Stretch

Debian 預設並沒有安裝 it9135 的 firmware,必須開啟 non-free repository ,並安裝 firmware-misc-free

# enable non-free repository, then
sudo apt install -y firmware-misc-non-free

Ref: - Ubuntu 12.04 使用大通USB電視棒AD-525 - http://git.linuxtv.org/cgit.cgi/dtv-scan-tables.git - github.com/oliv3r/dtv-scan-tables Digital TV scan tables

有時在機器上會遇到 system hang 的狀況,特別是在 enable 新硬體時。遇到這種情況,可以試著 blacklist 可疑的 kernel module

以 mwifiex_sdio 為例

# Do not load the 'mwifiex_sdio' module on boot.
echo > /etc/modprobe.d/debug.conf <EOF
blacklist mwifiex_sdio
EOF

再重開機即可

如果這個 module 仍會被其它 module depends 而載入,可以再進一步的 blacklist

# Do not load the 'mwifiex_sdio' module on boot.
echo > /etc/modprobe.d/debug.conf <EOF
install mwifiex_sdio /bin/false
EOF

Using files in /etc/modprobe.d/

最近在工作上遇到一個 bug,在某些狀況下執行 lshw (02.16-2ubuntu1.2) 會 segmentation fault。找了 lshw 最新的 code 編譯執行後發現沒有這個問題。於是就開始了 git bisect。最後找到是 d048d300b5daeb44887a7fc06ddeb120119cac8a 這筆修改在 src/core/scsi.cc 上面的 commit 解決了這個問題

順著這筆 commit,找到了 lshw project 的 bug report lshw segfaults, with some 16GB USB-3 sticks from Patriot 。也了解是 USB3.0 stick plugged 時會出現問題。在手上的機器上試了一下,果然是這樣沒錯。原本沒有頭緒的 random segmentation fault,現在則是有了 root cause 的 issue。

既然找到了 Solution,就開始要加 patch 進 Ubuntu source 了。為了將 patch 加到 Ubuntu 14.04 (Trusty) 目前的 lshw (02.16-2ubuntu1.2) 裡,我們還必須加上 src/core/scsi.cc 的前一個 commit b79f299319f61bc80e8d38e61631cfee7521a729

# clone upstream
git clone https://github.com/lyonel/lshw lshw-lyonel
# clone ubuntu source
bzr branch lp:ubuntu/trusty-proposed/lshw

# make patch from upstream git tree
cd lshw-lyonel/
git format-patch b79f299^..b79f299
git format-patch d048d30^..d048d30
cd ..

# import patches to ubuntu source
cd lshw/
dquilt push -a # apply existing patches
dquilt import ../lshw-lyonel/0001-use-a-different-approach-for-scanning-SCSI-generic-d.patch
dquilt import ../lshw-lyonel/0001-presumably-fix-653.patch

# edit changelog
dch -v 02.16-2ubuntu1.3 -D trusty

# local commit
debcommit

這樣就完成了,最後這一包 source 就可以拿來做 debian package 的打包,並且開始跑 Ubuntu package propose 的流程。

Ref: 1. how to add upstream git patches to an existing debian package 2. Chapter 3. Modifying the source 3. How To Survive With Many Patches or Introduction to Quilt