在fedora7上构建UML(User mode linux)(一)

    linux系统有很特别的功能,比如可以在一个linux系统上把一个内核当作一个程序来运行,这样称之为User Mode Linux,在内核开发调试过程,做实验,快速开发程序等过程中能达到快速模拟开发板环境的作用。

    在开始构建UML之前,先介绍一个主机环境:

[hid@hid-server dev]$ cat /proc/version
Linux version 2.6.21-1.3194.fc7 (kojibuilder@xenbuilder4.fedora.phx.redhat.com) (gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)) #1 SMP Wed May 23 22:35:01 EDT 2007

    首先,下载了一个linux2.6.18内核,编译未成功,刚开始编译即显示arch/um/sys-i386/user-offsets.c不通过,随即找了一些补丁,仍然未成功,遂下载较新的内核版本linux2.6.26,顺利编译产生UML的可执行文件linux,但是在启动后未加载文件系统即内核崩溃,在新闻组中查找些许时间,得知linux2.6.26.2才对gcc4.1.2支持比较好,所以最终下载了linux2.6.26.2内核,编译成功,可以运行,命令如下:

[root@hid-server linux]# make ARCH=um defconfig
[root@hid-server linux]# make ARCH=um menuconfig
[root@hid-server linux]# make ARCH=um linux

最终在内核目录下产生一个名为linux的可执行文件,此即UML程序,将其拷贝到工作目录,而后,需要构建一个文件系统,为了简单,下载了busybox-1.11.1,静态编译通过,命令如下

[root@hid-server linux]# make menuconfig     //This creates a file called ".config"
[root@hid-server linux]# make                         //This creates the "busybox" executable
[root@hid-server linux]# make install              //or make CONFIG_PREFIX=/path/from/root install

在busybox-1.11.1目录的_install目录下产生了/bin, /sbin, linuxrc三个文件,其实都是对busybox程序的链接,将其拷贝到新建的rootfs目录,同时新建其他需要的目录,修改etc目录下的文件分别为

[hid@hid-server etc]$ cat fstab
/dev/ubd0       /       ext3    defaults    0   1
proc            /proc   proc    defaults    0   0
[hid@hid-server etc]$ cat inittab
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
tty2::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
[hid@hid-server etc]$ cat profile
# /etc/profile: system-wide .profile file for the Bourne shells

echo
echo -n "Processing /etc/profile... "
# no-op
echo "Done"
echo

[hid@hid-server etc]$ cat init.d/rcS
#! /bin/sh

/bin/mount -a


echo "*********************************************************"
echo "*                                                                    *"
echo "*                            Hello,linux!                      *"
echo "*********************************************************"
制作成文件系统:

[root@hid-server um]# dd if=/dev/zero of=romfs count=1 bs=1M
[root@hid-server um]# mkfs.ext2 ./romfs
[root@hid-server um]# mount -o loop romfs /mnt
[root@hid-server um]# cp rootfs/* /mnt -rf
[root@hid-server um]# umount /mnt

然后运行

[hid@hid-server ~]$ ./linux ubda=romfs
Locating the bottom of the address space ... 0x0
Locating the top of the address space ... 0xc0000000
Core dump limits :
        soft - 0
        hard - NONE
Checking that ptrace can change system call numbers...OK
Checking syscall emulation patch for ptrace...check_sysemu got system call number -1, expected 20...check_ptrace : child exited with status 2.
Disabling SYSEMU support.
check_ptrace : child exited with exitcode 2, while expecting 1; status 0x200
missing
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: No such file or directory
- PTRACE_FAULTINFO...not found
- PTRACE_LDT...not found
UML running in SKAS0 mode
Adding 3989504 bytes to physical memory to account for exec-shield gap
Linux version 2.6.26.2 () (gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)) #1 Sun Apr 19 03:24:25 CST 2009
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 9094
Kernel command line: ubda=romfs root=98:0
PID hash table entries: 256 (order: 8, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 30232k available
Mount-cache hash table entries: 512
Checking for host processor cmov support...Yes
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
net_namespace: 192 bytes
Using 2.6 host AIO
NET: Registered protocol family 16
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
mconsole (version 2) initialized on /home/hid/.uml/PMXu3O/mconsole
Checking host MADV_REMOVE support...OK
Host TLS support detected
Detected host type: i386 (GDT indexes 6 to 9)
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
msgmni has been set to 59
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
TCP cubic registered
NET: Registered protocol family 17
Initialized stdio console driver
Console initialized on /dev/tty0
console [tty0] enabled
Initializing software serial port version 1
console [mc-1] enabled
ubda: unknown partition table
VFS: Mounted root (ext2 filesystem) readonly.
line_ioctl: tty0: unknown ioctl: 0x541e
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
init started: BusyBox v1.11.1 (2009-04-16 23:12:13 CST)
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
starting pid 193, tty '': '/etc/init.d/rcS'
*********************************************************
*                                                       *
*                      Hello,linux!                     *
*********************************************************
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
starting pid 195, tty '': '-/bin/sh'

Processing /etc/profile... Done

# xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
Can't open /dev/tty2: No such device
haxterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
process '-/bin/sh' (pid 196) exited. Scheduling for restart.
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 2, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
Can't open /dev/tty2: No such device
lt
# xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
The system is going down NOW!
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
Sending SIGTERM to all processes
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
Sending SIGKILL to all processes
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
xterm_open: $DISPLAY not set.
Failed to open console 5, err = -19
init: can't log to /dev/tty5
Requesting system halt
System halted.

[hid@hid-server ~]$

至于为什么出现问题,尚待解决,下期再续。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值