实验
报告
软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载
课程名称: 操作系统分析及实验 实验类型: 综合型/
设计
领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计
性
实验项目名称: 实验 2 编译 Linux 内核
学生姓名: 专业: 软件
工程
路基工程安全技术交底工程项目施工成本控制工程量增项单年度零星工程技术标正投影法基本原理
学号:
电子邮件地址: 手机:
实验日期: 2011 年 11 月 29 日
一、实验目的
学习重新编译 Linux 内核,理解、掌握 Linux 内核和发行版本的区别。
二、 实验内容
在 Linux操作系统环境下重新编译内核。实验主要内容:
查找并且下载一份内核源代码
配置内核
编译内核和模块
配置启动文件
三、主要仪器设备(必填)
CPU Intel Core2 Duo T6500 @ 2.10Ghz
内存 2.00GB
显卡 NVIDIA GeForce 130M
虚拟机 Vmware 8.10,分配内存 768MB
操作系统:虚拟机内 Ubuntu 11.10,原内核版本 3.0.0.12
四、操作方法和实验步骤
1.查找并且下载一份内核源代码
在 Linux 的官方网站:www.kernel.org ,下载内核版本,本次下载的是 3.1.4 的稳定版
2.准备好编译环境
如图输入命令,安装配置编译内核的必要环境:
3. 部署内核源代码
将下载好的源代码压缩包放在主
目录
工贸企业有限空间作业目录特种设备作业人员作业种类与目录特种设备作业人员目录1类医疗器械目录高值医用耗材参考目录
下,并拷贝到/usr/src 目录下
然后用 tar 命令将压缩包解压缩在/usr/src 目录下:
sudo tar xvf linux-3.1.4.tar.bz2
然后进入/usr/src/linux-3.1.4 目录:
4.配置内核
在配置内核前,先用 make mrproper 来清理一遍:
执行命令 make menuconfig,进入文本配置界面:
对必要的选项进行配置,配置完成后保存退出
5.编译内核和模块
执行 make 命令,进行编译:
Make 完毕后,再执行 sudo make modules_install:
然后把 bzImage 和 System.map 移动到 /boot 文件夹下,但这里有个问题,在
/usr/src/linux-3.1.4/arch/i386/boot 目录下并没有 System.map 文件,于是只好用了
make_install
Make install 成功:
5.应用 grub 配置启动文件
打开 grub.cfg(ubuntu11.10 里并没有 grub.conf 文件),发现启动项已经被修改
重新启动后进入系统,运行 uname –r,发现现在的内核版本已经变成了 3.1.4:
五、实验结果和分析
grub.cfg 文件内容如下:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
set have_grubenv=true
load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi
function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}
function recordfail {
set recordfail=1
if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
}
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=auto
load_video
insmod gfxterm
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
set locale_dir=($root)/boot/grub/locale
set lang=zh_CN
insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ]; then
set timeout=-1
else
set timeout=10
fi
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30; then
clear
fi
### END /etc/grub.d/05_debian_theme ###
### BEGIN /etc/grub.d/10_linux ###
if [ ${recordfail} != 1 ]; then
if [ -e ${prefix}/gfxblacklist.txt ]; then
if hwmatch ${prefix}/gfxblacklist.txt 3; then
if [ ${match} = 0 ]; then
set linux_gfx_mode=keep
else
set linux_gfx_mode=text
fi
else
set linux_gfx_mode=text
fi
else
set linux_gfx_mode=keep
fi
else
set linux_gfx_mode=text
fi
export linux_gfx_mode
if [ "$linux_gfx_mode" != "text" ]; then load_video; fi
menuentry 'Ubuntu, with Linux 3.1.4' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
linux /boot/vmlinuz-3.1.4 root=UUID=e424829c-2eb5-4a82-84f7-2ce7014d77ff ro
quiet splash vt.handoff=7
initrd /boot/initrd.img-3.1.4
}
menuentry 'Ubuntu, with Linux 3.1.4 (recovery mode)' --class ubuntu --class gnu-linux --class gnu
--class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
echo 'Loading Linux 3.1.4 ...'
linux /boot/vmlinuz-3.1.4 root=UUID=e424829c-2eb5-4a82-84f7-2ce7014d77ff ro
recovery nomodeset
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-3.1.4
}
submenu "Previous Linux versions" {
menuentry 'Ubuntu, with Linux 3.0.0-12-generic' --class ubuntu --class gnu-linux --class gnu
--class os {
recordfail
set gfxpayload=$linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
linux /boot/vmlinuz-3.0.0-12-generic
root=UUID=e424829c-2eb5-4a82-84f7-2ce7014d77ff ro quiet splash vt.handoff=7
initrd /boot/initrd.img-3.0.0-12-generic
}
menuentry 'Ubuntu, with Linux 3.0.0-12-generic (recovery mode)' --class ubuntu --class gnu-linux
--class gnu --class os {
recordfail
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
echo 'Loading Linux 3.0.0-12-generic ...'
linux /boot/vmlinuz-3.0.0-12-generic
root=UUID=e424829c-2eb5-4a82-84f7-2ce7014d77ff ro recovery nomodeset
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-3.0.0-12-generic
}
}
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###
### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
linux16 /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
insmod part_msdos
insmod ext2
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root e424829c-2eb5-4a82-84f7-2ce7014d77ff
linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###
### BEGIN /etc/grub.d/30_os-prober ###
if [ "x${timeout}" != "x-1" ]; then
if keystatus; then
if keystatus --shift; then
set timeout=-1
else
set timeout=0
fi
else
if sleep --interruptible 3 ; then
set timeout=0
fi
fi
fi
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/41_custom ###
if [ -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
六、讨论、心得
1. 实验思考
回答:
initrd.img-3.1.4——initrd 是“initial ramdisk”的缩写,用来引导硬件到 vmlinuz,
可以加载硬件驱动模块,使得硬件可以用模块的方式被支持。这样子,内核就可
以只编译最基本的硬件驱动,而其他介质的驱动(USB、IDE、SCSI……)就由
initrd 用模块的方式加载,内核就不会变得臃肿不堪。
System.map-3.1.4——System.map 是 linux 内核的一个符号表,用来存储内核的各
种变量名、函数名和其对应的内核地址。内核本身并不使用 System.map,但一
些程序和驱动可能会用到,没有它,这些程序和驱动就有可能报错。
可以分别尝试删除其中一个文件,当删除了对应版本的 System.map-3.1.4(/boot
目录下和/usr/src/linux-3.1.4 目录下)时,klogd 的输出有可能不正确;
当删除了 initrd 文件时,很有可能无法挂载根文件系统,导致进不了系统。
2. 遇到的问题和解决方法
1.刚开始执行 make 时报错,后来发现是没有权限的缘故,要用 sudo make;
2. 在/usr/src/linux-3.1.4/arch/i386/boot 目录下仅仅发现了 bzImage(刚开始连复制这个也报
错,因为我忘了 linux 对大小写敏感,再后来发现这个文件只是一个 link),没有发现
System.map,于是只好冒险用了 make install,查看执行命令后的输出情况,大概是执行了
/usr/src/linux-3.1.4/arch/x86/boot 目录下的 install.sh 文件,等执行完毕后到/boot 目录下一看,
initrd.img-3.1.4 和 System.map-3.1.4 已经在那里了,grub.cfg 也已经被修改。
后来搜索文件夹时发现,bzImage 其实在/usr/src/linux-3.1.4/arch/x86/boot 目录下,System.map
其实在/usr/src/linux-3.1.4 目录下。
3. 心得体会
1. 初次实践了 linux 的内核编译过程,掌握了编译内核的方法;发现在配置过程中,许多
内容可以不必编译进内核中,但为了少出问题也可以不修改配置。整个 make 大概历时
3 个小时,非常漫长,估计与用虚拟机也有关系;
2. 解决了内核编译中出现的一些问题,提高了动手能力,例如 bzImage 和 System.map 的
真正位置,/usr/src/linux-3.1.4/arch/i386/boot 目录下的 bzImage 只是个 link,实际的文件
存在于/usr/src/linux-3.1.4/arch/x86 /boot 中,拷贝这个 link 是没用的。
3. 加深了对 linux 引导启动机制的了解。