

$ tar jxvf linux-2.6.19.1.tar.bz2 $ cd linux-2.6.19.1 $ patch -p1 < ../uml-2_6_19_1-compilation.patch $ cp ../uml-dot-config .config $ make menuconfig ARCH=um $ make linux ARCH=um注意到包含 "make" 的那兩行都有 "ARCH=um" 的 build variable,這是建構 UML 一定要加上的,無論是 kernel source 或 external kernel module,都需在 make 時加上,至於原因,看官花點時間看 Linux Kernel 的 Makefile 就可見其端倪。不過,就算不小心忘了加上,請立即執行以下操作:
$ make mrproper經過冗長的編譯過程後,會發現有個新檔案被建立,即 "linux",但別急著執行,因為我們需要合用的 rootfs,原本這是苦差事,但 Debian/Ubuntu 有個強大的工具 [debootstrap] 可輕易生成具備 Debian/Ubuntu base 的 rootfs,以下是套件簡介:
#!/bin/sh
BASE_DIR=`pwd`
# --- Modified as you need ---
TARGET_DIR=$BASE_DIR/ext2fs
ETC_SAMPLE=etc_sample.tar.bz2
ROOTFS_FILE=ubuntu-root
# Create rootfs (400Mb)
echo "Creating root file system..."
rm -f $ROOTFS_FILE
dd if=/dev/zero of=$ROOTFS_FILE bs=1024K count=400
if [ ! -f $ROOTFS_FILE ]; then
echo "Error: creation of image file fails."
exit
fi
yes y | mkfs.ext2 $ROOTFS_FILE
mkdir -p $TARGET_DIR
mount -o loop $ROOTFS_FILE $TARGET_DIR
# Make use of Debian's debootstrap tool to construct Ubuntu Dapper (6.10) base
echo "Invoking debootstrap..."
debootstrap --arch i386 dapper \
$TARGET_DIR \
http://archive.ubuntulinux.org/ubuntu
# Extract sample configure files
if [ -f $ETC_SAMPLE ]; then
cd $TARGET_DIR
tar jcvf $ETC_SAMPLE
cd $BASE_DIR
fi
# mknod for ubd0 (specific to UML)
if [ -d $TARGET_DIR/dev ]; then
cd $TARGET_DIR/dev
mknod --mode=660 ubd0 b 98 0
chown root:disk ubd0
cd $BASE_DIR
else
echo "Error: debootstrap fails."
exit
fi
# Finish
sync
umount ext2fs
echo "Done"
echo "Please assign the rootfs: " $ROOTFS_FILE
沒有意外的話,以 root 權限執行以上 script 後,[debootstrap] 會幫我們建構具備 Ubuntu Dapper (6.10) base 的 rootfs,其容量為 400 Mb。注意 [debootstrap] 下載 Debian package 是透過 wget,如果在防火牆的環境中,請將相關設定準備好。輸出的 "ubuntu-root" 檔案即是 UML 所需的 rootfs,是的,就是一個檔案,損毀的話就再重跑以上流程,無論 UML 內部發生什麼事情,宿主 Linux 仍沒有大影響。./linux ubd0=`pwd`/ubuntu-rootubd 也就是 UML Block Device 之意,對 UML 相當重要,將透過該 device 存取到 rootfs,我們應該會見到類似以下輸出:
Checking that ptrace can change system call numbers...OK Checking syscall emulation patch for ptrace...OK Checking advanced syscall emulation patch for ptrace...OK Checking for tmpfs mount on /dev/shm...OK Checking PROT_EXEC mmap in /dev/shm/...OK Checking for the skas3 patch in the host: - /proc/mm...not found - PTRACE_FAULTINFO...not found - PTRACE_LDT...not found UML running in SKAS0 mode Checking that ptrace can change system call numbers...OK Checking syscall emulation patch for ptrace...OK Checking advanced syscall emulation patch for ptrace...OK [42949372.960000] Linux version 2.6.19.1 (jserv@venux) (gcc version 4.1.2 20070106 (prerelease) (Ubuntu 4.1.1-21ubuntu7)) #4 Wed Jan 10 20:53:03 CST 2007 [42949372.960000] Built 1 zonelists. Total pages: 8128 [42949372.960000] Kernel command line: ubd0=/opt/src/ubuntu-root root=98:0 [42949372.960000] PID hash table entries: 128 (order: 7, 512 bytes) [42949372.960000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes) [42949372.960000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes) [42949372.960000] Memory: 30100k available [42949373.230000] Mount-cache hash table entries: 512 ... 省略 ...預設 root 是不需要密碼,我們試著登入並結束系統:
Ubuntu 6.06 LTS uml tty0 uml login: root [42949456.230000] line_ioctl: tty0: unknown ioctl: 0x5603 Last login: Wed Jan 10 16:47:59 2007 on tty0 Linux uml 2.6.19.1 #4 Wed Jan 10 20:53:03 CST 2007 i686 GNU/Linux root@uml:~# halt Broadcast message from root@uml (tty0) (Wed Jan 10 16:48:40 2007): The system is going down for system halt NOW! * INIT: Switching to runlevel: 0 * INIT: Sending processes the TERM signal hwclock is unable to get I/O port access: the iopl(3) call failed. * Stopping kernel log... [ ok ] * Stopping system log... [ ok ] * Terminating any remaining processes... [ ok ] * Unmounting remote filesystems... [ ok ] * Deconfiguring network interfaces... [ ok ] * Unmounting local filesystems... [ ok ] * Deactivating swap... [ ok ] * Will now halt [42949503.180000] System halted.粗體字是我們鍵入的部份,當有 ioctl 抱怨錯誤訊息,請忽略,因為 UML 並未完全實做該功能,這不影響我們的進行。這短暫的過程我們見到 UML 虛擬機器的啟動與終結,佛語常說,一切萬物,自有緣起緣滅之時,且讓我們來探究 UML 的因果與深入設計,進而體驗 Linux Kernel 的美妙。
兩張圖重複了,第二張圖應該換成 uml_part_2.png
由 yaocl 發表於 January 11, 2007 09:28 AMcreate-uml-rootfs 有一點小 typo。
*** create-uml-rootfs 2007-01-15 11:40:29.000000000 +0800
--- create-uml-rootfs.orig 2007-01-11 13:00:02.000000000 +0800
***************
*** 28,35 ****
# Extract sample configure files
if [ -f $ETC_SAMPLE ]; then
cd $TARGET_DIR
! tar jxvf $BASE_DIR/$ETC_SAMPLE
! cd $BASE_DIR
fi
# mknod for ubd0 (specific to UML)
--- 28,35 ----
# Extract sample configure files
if [ -f $ETC_SAMPLE ]; then
cd $TARGET_DIR
! tar jxvf $ETC_SAMPLE
! cd $BAE_DIR
fi
# mknod for ubd0 (specific to UML)
arch/i386/lib/semaphore.S:34: Error: unknown pseudo-op: `.cfi_startproc'
make kernel error . My linux is Redhat9. Why?
由 wenhsuan 發表於 January 26, 2007 03:40 PMTo wenhsuan,
Please do "make menuconfig ARCH=um", and disable the option "Compile the kernel with frame unwind information" in "Kernel hacking" section.
Thanks for your feedback.
由 jserv 發表於 January 27, 2007 05:33 PMthanks, I do make successful as you said.
由 wenhsuan 發表於 January 30, 2007 12:21 PMYour introduction of UML linux is very good. I will give a try.
By the way,
many IC EDA tools only can run in RedHat 8.
can I use UML method to treat REDHAT 8 in CentOS4.4?
由 Hugo 發表於 February 1, 2007 02:46 PM