1、下载内核版本:
linux-3.4.9.tar.bz2
2、解压编译,注意在配置的时候menuconfig或者xconfig等的时候不要去修改UML的关于cpu设置的配置
linux #make mrproper
linux #make mrproper ARCH=um
linux #make menuconfig ARCH=um
linux #make linux ARCH=um
linux #make modules ARCH=um
linux #make modules_install ARCH=um
OK了,生成我们需要的内核了,而且支持调试了。
直接启动会有问题的,提示找不到root文件系统。这样我们用人家现成的。
去这里下载,一个文件系统,我的系统是RHEL 6.3,没有关系就下一个Centos的文件系统就可以了:
http://user-mode-linux.sourceforge.net/
这个网址里面有配置好的内核版本和编译好的文件系统。
可以去kernel.org下载源代码形式的内核版本呢,这里http://uml.devloop.org.uk/kernels.html他给出了一个config文件(记得选择一直的内核版本和config文件),复制过去,你直接到内核根目录
下面去:
make linux ARCH=um
图方便就直接下载二进制的内核版本就是了,但是我不使用人家的现成的,因为那样无法修改内核代码,只能trace流程:
http://uml.devloop.org.uk/kernels.html
文件系统呢,下载就是100m左右,解压后是1.6g左右。如果下载了文件系统,就不要像上面一样编译了,可以直接解压使用的。
http://fs.devloop.org.uk/
我下载的文件系统是CentOS6.x-x86-root_fs.bz2,解压,重命名为:root_fs即可
文件系统下载完了,就可以直接启动内核了:
[root@localhost linux-3.4.9]# ./vmlinux ubda=root_fs mem=256m
或者:
[root@localhost linux-3.4.9]# ./linux ubda=root_fs mem=256m
他会一直运行,知道提示输入用户名和密码,用户名初始为root,没有密码。
但是,这样也有问题,进入系统后,会一直提示:
modprobe: FATAL: Could not load /lib/modules/3.5.1/modules.dep: No such file or directory
modprobe: FATAL: Could not load /lib/modules/3.5.1/modules.dep: No such file or directory
modprobe: FATAL: Could not load /lib/modules/3.5.1/modules.dep: No such file or directory
这是因为我们从网上下载的现成的文件系统的lib的/lib/modules/路径下面没有我们刚才编译的内核的modules,所以需要把开始操作:linux #make modules_install ARCH=um 生成的文件夹拷贝到文件
系统映像里面去,路径就是host主机的/lib/modules/3.5.1。但是我不这么做,因为网上下载的文件太小,我觉得不够用,所以我自己做一个文件映像:
路径:/azuo
操作1,创建文件系统:
[root@localhost azuo]# dd if=/dev/zero of=disk.img bs=1000M count=10
操作2,格式化为ext3格式:
mkfs.ext3 disk.img
操作3,重命名:
mv disk.img root_fs
操作4,创建挂载文件夹,/azuo/mnt_fs
mkdir /azuo/mnt_fs
操作5,挂载root_fs到/azuo/mnt_fs:
cd /azuo;
mount -o loop root_fs mnt_fs
操作6:
下载网上的已经做好的映像文件到路径/um_linux/,重命名为root_fs;
[root@localhost linux-3.5.1]# cd /um_linux/
[root@localhost um_linux]# dir
config install.sh kernel32-3.5.1 linux-3.5.1 linux-3.5.1.tar.bz2 root_fs
操作7,把这个root_fs挂载到/mnt:
mount -o loop root_fs /mnt
操作8,把挂载后的/mnt下面的所有东西都拷贝到/azuo/mnt_fs下去
[root@localhost um_linux]# cd /mnt
[root@localhost mnt]# dir
bin boot cgroup dev etc home lib lost+found media mnt opt
proc root sbin selinux srv sys tmp usr var
[root@localhost mnt]# cp -r * /azuo/mnt_fs/
操作9,把宿主机host上面linux #make modules_install ARCH=um 生成的文件夹拷贝到/azuo/mnt_fs下去
[root@localhost modules]# cp -r /lib/modules/3.5.1 /azuo/mnt_fs/lib/modules/
操作10,卸载挂载的文件夹:
[root@localhost azuo]# umount mnt_fs/
[root@localhost azuo]# umount /mnt
然后我们试试看看这个文件系统好使不,到编译好的um格式的linux内核路径下去操作:
[root@localhost azuo]# cd /um_linux/linux-3.5.1
[root@localhost linux-3.5.1]#
[root@localhost linux-3.5.1]# dir
arch CREDITS drivers include Kbuild lib Makefile
modules.order README samples sound usr vmlinux.o
block crypto firmware init Kconfig linux mm
Module.symvers REPORTING-BUGS scripts System.map virt
COPYING Documentation fs ipc kernel MAINTAINERS modules.builtin net
root_fs security tools vmlinux
[root@localhost linux-3.5.1]# ./linux ubda=/azuo/root_fs mem=256m
实际效果如下,相当好使:
------------------------------
[root@localhost linux-3.5.1]# ./linux ubda=/azuo/root_fs mem=256m
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...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: No such file or directory
- PTRACE_FAULTINFO...not found
- PTRACE_LDT...not found
UML running in SKAS0 mode
Adding 12857344 bytes to physical memory to account for exec-shield gap
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 3.5.1 (root@localhost.localdomain) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 Fri Aug 17 08:52:02 CST 2012
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 68138
Kernel command line: ubda=/azuo/root_fs mem=256m root=98:0
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
allocated 549400 bytes of page_cgroup
please try 'cgroup_disable=memory' option if you don't want memory cgroups
Memory: 254248k available
NR_IRQS:15
Calibrating delay loop... 984.67 BogoMIPS (lpj=4923392)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
Initializing cgroup subsys cpuacct
Initializing cgroup subsys memory
Initializing cgroup subsys devices
Initializing cgroup subsys freezer
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
devtmpfs: initialized
Using 2.6 host AIO
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
Switching to clocksource itimer
NET: Registered protocol family 2
IP route cache hash table entries: 4096 (order: 2, 16384 bytes)
TCP established hash table entries: 16384 (order: 5, 131072 bytes)
TCP bind hash table entries: 16384 (order: 6, 327680 bytes)
TCP: Hash tables configured (established 16384 bind 16384)
TCP: reno registered
UDP hash table entries: 256 (order: 1, 12288 bytes)
UDP-Lite hash table entries: 256 (order: 1, 12288 bytes)
NET: Registered protocol family 1
mconsole (version 2) initialized on /root/.uml/m30WOZ/mconsole
Checking host MADV_REMOVE support...OK
Host TLS support detected
Detected host type: i386 (GDT indexes 6 to 9)
Initializing RT-Tester: OK
VFS: Disk quotas dquot_6.5.2
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
fuse init (API version 7.19)
msgmni has been set to 496
io scheduler noop registered
io scheduler deadline registered (default)
start plist test
end plist test
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
kjournald starting. Commit interval 5 seconds
EXT3-fs (ubda): mounted filesystem with ordered data mode
VFS: Mounted root (ext3 filesystem) readonly on device 98:0.
devtmpfs: mounted
cat: /proc/cmdline: No such file or directory
Welcome to CentOS
Starting udev: udev: starting version 147
udevd (306): /proc/306/oom_adj is deprecated, please use /proc/306/oom_score_adj instead.
line_ioctl: tty0: unknown ioctl: 0x541e
[ OK ]
Setting hostname localhost.localdomain: [ OK ]
Setting up Logical Volume Management: No volume groups found
[ OK ]
Checking filesystems
Checking all file systems.
[ OK ]
Remounting root filesystem in read-write mode: EXT3-fs (ubda): using internal journal
[ OK ]
Mounting local filesystems: [ OK ]
/etc/rc.d/rc.sysinit: line 596: plymouth: command not found
Enabling /etc/fstab swaps: [ OK ]
/etc/rc.d/rc.sysinit: line 661: plymouth: command not found
Entering non-interactive startup
FATAL: Module ipv6 not found.
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
[FAILED]
FATAL: Module ipv6 not found.
Mounting other filesystems: [ OK ]
Retrigger failed udev events[ OK ]
cat: /proc/sys/crypto/fips_enabled: No such file or directory
/etc/rc3.d/S55sshd: line 50: [: too many arguments
Starting sshd: [ OK ]
CentOS release 6.2 (Final)
Kernel 3.5.1 on an i686
localhost login:
CentOS release 6.2 (Final)
Kernel 3.5.1 on an i686
localhost login: root
Last login: Thu Aug 16 20:44:48 on tty0
[root@localhost ~]#
------------------------------
下面用gdb调试内核:
linux #gdb ./linux
(gdb) handle SIGSEGV pass nostop noprint
(gdb) handle SIGUSR1 pass nostop noprint
(gdb) b main
(gdb) run ubd0=root_fs mem=256m
记住上面的两个handle一定要输入的,要不系统会一直卡在启动的地方提示segment fault。
上面启动的都是自己编译的生成文件。下载的直接启动./kernel32-3.5.1(前提是kernel32-3.5.1是下载的文件)
注意:
补充1、我上面从官网下面下载的是centos 6.2的版本,但是2012 6 18日官网更新到了centos 6.3版本,这个版本根本起不来,只能配置官网编译好的内核使用,自己编译的是不行的。
只能自己拷贝自己主机host根目录下面的lib bin sbin过去到自己做的那个文件系统下面去就是了。
[root@zhoutianzuo mnt]# cp -r /lib /azuo/mnt
[root@zhoutianzuo mnt]# cp -r /bin /azuo/mnt
[root@zhoutianzuo mnt]# cp -r /sbin /azuo/mnt
[root@zhoutianzuo mnt]# cp -r /boot /azuo/mnt
[root@zhoutianzuo mnt]# cp -r /etc /azuo/mnt
[root@zhoutianzuo mnt]# cp -r /sys /azuo/mnt
[root@zhoutianzuo mnt]# cp -r /dev /azuo/mnt
[root@zhoutianzuo mnt]# mkdir /azuo/mnt/usr
[root@zhoutianzuo mnt]# cp -r /usr/bin /azuo/mnt/usr
[root@zhoutianzuo mnt]# cp -r /usr/sbin /azuo/mnt/usr
[root@zhoutianzuo mnt]# cp -r /usr/lib /azuo/mnt/usr
[root@zhoutianzuo mnt]# cp -r /usr/etc /azuo/mnt/usr
如果可以还是请使用官网发行是文件系统,拷贝到自己的文件系统,然后,把modules部分拷贝过去。
补充2、今天2012-8-19尝试了使用Centos 5.8,这个上面编译不了内核3.5.2这个版本,所以我尝试了2.6.35.13这个版本,但是这个版本要注意,一定要在编译的内核里面开启EXT4功能的支持。然后使用官网下载的文件系统版本,因为官网的文件系统是ext4格式的。
分享到:
相关推荐
gdb + UML调试linux内核,自己总结的,非常实用,有需要的采纳,根文件系统可以到我的资源下载!
gdb+UML调试linux内核步骤,里面记录了我在使用gdbt调试linux内核源码的详细步骤。
linux内核调试分析指南 linux内核调试分析指南--上篇 本文档已经转到下面的网址,位于zh-kernel.org的文档停止更新,请访问新网址 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级调试 ***第一...
文档介绍了概述,一、构建UML内核调试环境,1.构建UML内核树,1)下载一份内核源码包,2)解压之后cd到源码根目录下,3)配置内核并编译,4)编译内核模块,2.准备运行UML的根文件系统和交换文件系统
使用qemu模拟器学习linux内核编译内核,制作rootfs,配置qemu参数,主要用于使用gdb学习,分析调试Linux内核,uboot 如何使用 sudo apt-get install gdb-arm-none-eabi gcc-arm-linux-gnueabi ./scripts/download.sh...
师兄自己制作的根文件系统,非常好用,可以配上我的 gdb+UML调试文档一起使用,谢谢采纳!
用UML进行分析设计.ppt...
startuml linux x64, 无限期使用,UML 画图工具
用UML进行大规模软件框架设计
UML利用 UML 进行实体关系建模.doc
uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例uml实例
uml uml uml uml
内容包括: Jude 安装教学篇 介绍 jude 的安装和下载 Jude 初步介绍篇 介绍 jude 的初基本功能 Jude 绘图介绍篇 如何用 jude 来绘制 uml 图
UML课件 UML课件 UML课件 UML课件 UML课件
UML课件UML课件UML课件UML课件UML课件
EAEAEAEAEAEA UMLEA UMLEA UML
超市 uml超市 uml超市 uml超市 uml超市 uml超市 uml超市 uml
使用UML进行项目开发.pdf,很不错的。
包含了大二时的Java,UML,Linux操作系统,数据结构,操作系统,的实验报告和源代码,内容很多,也很有价值,仅供大家参考
如何运用UML进行面向对象分析与设计.doc