文档库 最新最全的文档下载
当前位置:文档库 › 精通initramfs构建step by step

精通initramfs构建step by step

精通initramfs构建step by step
精通initramfs构建step by step

精通initramfs构建step by step

(一)hello world

编写一个最简单的initramfs

(二)initramfs的前世今生

前面讲initramfs的概念时,提到了rootfs,那么rootfs又是什么,它与initramfs又有些什么瓜葛呢?

(三)busybox

我们开始利用initramfs做些有意思的工作了。

(四)mini linux

busybox系统做好了,我们就以它为基础在initramfs上构建一个可运行的mini Linux系统吧。(五)initrd

目前为止,我们的initramfs都由内核编译生成的,并链接到内核中。其实我们也可以用cpio 命令生成单独的initramfs,与内核编译脱钩,在内核运行时以initrd的形式加载到内核,以增加灵活性。

(六)switch_root

除了基于initramfs的系统(如第四节的mini linux),通常initramfs都是为安装最终的根文件系统做准备工作,它的最后一步需要安装最终的根文件系统,然后切换到新根文件系统上去。

(七)modules

initramfs 的最重要的功能就是包含大量的硬盘驱动和文件系统驱动,而不需要把所有的驱动程序编译进内核,减少内核大小。initramfs负责在安装实际根文件系统前根据具体的文件系统设备情况加载合适的驱动到内核中,使系统能够正常安装实际的根文件系统。如何在initramfs中增加驱动程序模块呢?

(八)coldplug

如果要做一个支持各种硬件配置的initramfs,要借助著名的udev来自动根据内核侦测到硬件类型来加载相应的驱动程序,也就是系统的coldplug。在initramfs中如何使用udev做coldplug呢?

(九)内核编译时构建initramfs补遗

前一节中,initramfs构建中最困难的识别并自动加载硬件设备的驱动模块的问题已经解决了,我们稍稍停顿一下,回头再看看在内核编译时构建initramfs的另外两种方式。

(十)uclibc

前面编译busybox时,都是连接到了glibc库。但是glibc库比较大,而且busybox不能静态连接(有资料讲可以通过修改busybox源码来静态连接glibc),在initramfs容量受限或需要静态连接的情况下,使用uclibc库可能是个很好的选择。

(十一)klibc

截至到目前,我们都是基于busybox来构建initramfs。还有一种广泛使用的initramfs构建方式是使用klibc软件包,包括一个小巧的C库和常用命令和工具。Debian的initramfs构建工具就综合应用了busybox、udev、klibc。

(十二)大结局-测试一下

到现在为止,我们已经掌握了initramfs的构建方法,该到大结局了。在大结局里,读者可应用前面step中介绍的方法,尝试分析一下Debian的initramfs,看看是否已精通了initramfs 的构建方法。

一、initramfs是什么

在 2.6版本的linux内核中,都包含一个压缩过的cpio格式的打包文件。当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs中是否包含有init文件,如果有则执行它,作为PID为1的第一个进程。这个init进程负责启动系统后续的工作,包括定位、挂载“真正的”根文件系统设备(如果有的话)。如果内核没有在rootfs中找到init文件,则内核会按以前版本的方式定位、挂载根分区,然后执行 /sbin/init程序完成系统的后续初始化工作。

这个压缩过的cpio格式的打包文件就是initramfs。编译2.6版本的 linux内核时,编译系统总会创建initramfs,然后把它与编译好的内核连接在一起。内核源代码树中的usr目录就是专门用于构建内核中的 initramfs的,其中的initramfs_data.cpio.gz文件就是initramfs。缺省情况下,initramfs是空的,X86 架构下的文件大小是134个字节。

二、构建第一个initramfs:hello world

从C语言开始,学习计算机编程语言的第一个程序几乎都是hello world,因此我们也构建一个最简单的hello world式的initramfs,以说明initramfs的基本构建方法。

initramfs的灵魂是init文件(或者叫程序,因为它会被内核第一个执行),我们先写一个简单的init程序,它会在内核的console中打印出经典的hello world信息。

hello.c:

#include

#include

int main(int argc,char argv[])

{

printf("hello world, from initramfs.\n");

sleep(9999999);

return 0;

}

其中的sleep()函数语句是为了避免执行时内核很快打出panic的信息,并非功能上的需要。

接着把hello.c编译成静态连接程序:

gcc -o hello_static -static -s hello.c

命令行中的-s参数表示编译后的程序不包含调试定位信息,目的是减少编译出来的程序文件的大小。

再创建一个initramfs的构建源文件目录image,把hello_static程序拷入这个目录,并改名为init。

在image目录下,创建一个dev/console的设备文件,否init程序无法在内核console中输出信息:

mknod -m 600 dev/console c 5 1

注意,执行这个命令需要有root权限。

好了,现在可以设置内核配置参数,进行initramfs的构建了:

在general setup配置目录下的initramfs sources配置项下输入image的路径名,比如我的路径就是/home/wyk/initramfs-test/image。因为我们的init程序是ELF格式的,所以内核需要支持ELF的可执行文件,否则启动这个init程序会失败。在内核的 Executable file formats配置目录下,选择 kernel support for ELF binaries,则可使内核支持ELF格式的可执行文件。其他内核配置参数根据实际需要设置即可,不过,为了减少内核编译时间,可参考这篇文章

https://www.wendangku.net/doc/553269978.html,/blog-htm-do-showone-uid-60710-type-b log-itemid-293122.html设置一个最简单的内核配置。

内核配置参数设置完成后,按常规的内核编译方法进行编译,initramfs就自动连接到编译好的内核映像文件中了。

三、试验环境搭建

试验initramfs需要经常重启系统,所以使用CPU模拟器是不错的选择。我们可以选用qemu,它支持直接启动linux内核,无需在模拟器中安装OS。从方便使用的角度考虑,我们采用qemu launcher设置qemu的各项参数,它的安装可参考

https://www.wendangku.net/doc/553269978.html,/blog-htm-do-showone-uid-60710-type-b log-itemid-612280.html。

在qemu launcher的linux配置标签中,打勾直接启动linux,然后在下面的文本框中填上刚才编译好的内核映像文件的路径名。因为qemu的运行还需要设置硬盘映像文件,所以还需要在左边的配置标签中新建一个硬盘映像文件,但实际上我们并不使用硬盘。

配置好qemu的参数后,点击launcher按钮,内核就开始在qemu中运行了。内核输出一堆内核运行信息后,最后打出了

hello world, from initramfs.

哈哈,我们构建的initramfs已经能够正常工作了!

四、什么是rootfs和ramfs

所有的2.6版本linux内核都有一个特殊的文件系统rootfs,是内核启动的初始始根文件系统,initramfs的文件会复制到rootfs。如果把initramfs比作种子,那么rootfs就是它生长的土壤。大部分linux系统正常运行后都会安装另外的文件系统,然后忽略rootfs。

rootfs是ramfs文件系统的一个特殊实例。ramfs是一种非常简单的文件系统,是基于内存的文件系统。ramfs文件系统没有容量大小的限制,它可以根据需要动态增加容量。

ramfs 直接利用了内核的磁盘高速缓存机制。所有的文件的读写数据都会在内存中做高速缓存(cache),当系统再次使用文件数据时,可以直接从内存中读写,以提供系统的I/O性能。高速缓存中的写入数据会在适当的时候回写到对应的文件系统设备(如磁盘等)中,这时它的状态就标识为clean,这样系统在必要时可以释放掉这些内存。ramfs没有对应文件系统设备,所以它的数据永远都不会回写回去,也就不会标识为clean,因此系统也永远不会释放ramfs所占用的内存。

因为ramfs直接使用了内核已有的磁盘高速缓存机制,所以它的实现代码非常小。也由于这个原因,ramfs特性不能通过内核配置参数删除,它是内核的天然特性。

五、ramfs不是ramdisk

ramdisk 是在一块内存区域中创建的块设备,用于存放文件系统。ramdisk的容量是固定的,不能象ramfs一样动态增长。ramdisk需要内核的文件系统驱动程序(如ext2)来操作其上的数据,而ramfs则是内核的天然特性,无需额外的驱动程序。ramdisk也象其他文件系统设备一样,需要在块设备和内存中的磁盘高速缓存之间复制数据,而这种数据复制实际不必要的。

六、从ramfs派生的文件系统tmpfs

ramfs 的一个缺点是它可能不停的动态增长直到耗尽系统的全部内存,所以只有root或授权用户允许使用ramfs。为了解决这个问题,从ramfs派生出了tmpfs文件系统,增加了容量大小的限制,而且允许把数据写入交换分区。由于增加了这两个特性,所以tmpfs允许普通用户使用。

关于tmpfs文件系统更多的信息,可以看内核源码中的Documentation/filesystems/tmpfs.txt 文档。

综上所述,initramfs是一种ramfs文件系统,在内核启动完成后把它复制到rootfs中,作为内核初始的根文件系统,它的任务是挂载系统真正的根文件系统。这就是initramfs的前世今生。

七、什么是busybox

busybox号称是嵌入式Linux中的瑞士军刀——小巧、功能齐全。它把许多常用的Linux命令都集成到一个单一的可执行程序中,只用这一个可执行程序(即busybox)加上Linux 内核就可以构建一个基本的Linux系统。busybox程序非常小巧,包含全部命令可执行文件大小也只有750多K。busybox是完全模块化的,可以很容易地在编译时增加、删除其中包含的命令。

由于busybox的这些特点,它广泛应用于LiveCD、应急修复盘、安装盘等系统中。我们也是以它为基础,构建initramfs。

八、busybox的配置、编译和安装

(1)去https://www.wendangku.net/doc/553269978.html,去下载最新的源码,解压展开。

(2)用

make menuconfig

命令启动配置界面配置,配置busybox的特性、选择要包含在busybox的命令(busybox称为applet);

也可以用

make defconfig

命令做缺省配置,包含全部的applet。

另外两个配置命令是

make allyesconfig——最大配置

make allnoconfig——最小配置

它们和make defconfig命令都可以用来作为自定义配置的初始配置,然后再用make menuconfing命令做定制化配置。

为了简单,我们用make defconfig做缺省配置。

(3)用

make

命令编译busybox软件。

(4)用

make CONFIG_PREFIX=<安装目录> install

命令安装。如果在命令行中省略CONFIG_PREFIX变量的赋值,则会安装缺省值./_install 目录下。CONFIG_PREFIX可以在make menuconfig的配置界面中修改。

我们用make CONFIG_PREFIX=~/initramfs-test/image 命令把busybox安装到initramfs的构建目录中。

(5)缺省配置下,busybox动态链接到glibc,所以要把它用到的动态库复制到initramfs的构建目录中。用ldd命令查看busybox用到了哪些动态库文件及相应的文件路径,然后把它们复制到相应的目录下即可。

我们编译的busybox需要向image/lib目录下复制

ld-linux.so.2

libc.so.6

libcrypt.so.1

libm.so.6

动态库文件。

九、在image下创建必要的目录和设备文件

(1)在imgae目录下创建

proc ,sys ,etc ,mnt

四个目录

(2)hello world 已经创建了console 设备文件,我们再用

mknod -m 600 dev/null c 1 3

命令创建另一个基本的设备文件。

十、试验一下

busybox的构建和准备工作做完了,我们试验一下吧:

在image目录下以root用户权限——

(1)用

mount -vt proc proc =proc

mount -vt sysfs sysfs =sys

命令安装内核虚拟文件系统

(2)用

mount -v -o bind /dev dev

命令绑定/dev的设备文件到image/dev

(3)用

chroot . /bin/sh

命令进入busybox的环境。出现shell的命令提示符,可以试着输入几个命令,看看执行结果。例如,输入fdisk -l 命令看看是否能显示硬盘的分区。

十一、自动生成/dev下的设备文件

上节用chroot方法试验busybox时,为了简单,是用“绑定”的方式把主机的/dev中的设备文件映射到image目录下的dev目录。在initramfs上,这种方法显然不能使用。

生成系统的设备文件,现在通常都是用udev动态生成,而initramfs为了做到通用,动态生成的要求是必须的。在busybox中有一个mdev命令,就是用来动态生成设备文件,填充到/dev目录的。

在系统启动时,用

mdev -s

命令可以根据内核的sysfs文件系统在/dev目录中自动生成相应的设备文件。命令执行前,需要先挂载内核的proc和sysfs虚拟文件系统。

十二、初始身手

解决了自动生成设备文件的问题后,我们可以试着做一个最简单的可运行的linux系统了:(1)在image目录下写一个最简单的init脚本。

#!/bin/sh

mount -t proc proc /proc

mount -t sysfs sysfs /sys

mdev -s

/bin/sh

(2)为init脚本设置可执行权限,否则内核不会去执行它。

chmod +x init

(3)有些busybox配置中,mdev命令需要读取/etc/mdev.conf文件,为了避免出错信息,我们创建一个空文件。mdev.conf文件是用来控制mdev生成的设备文件的读写权限的,在这里我们不需要对设备文件设置特别的权限,就使用mdev缺省的660的权限设置。有关mdev的设备文件权限的控制详细信息,可参考busybox源码树docs目录下的mdev.txt文件。

touch etc/mdev.conf

(4)在内核源码目录下,执行

make

命令,重新编译内核,生成新的initramfs。

好了,在QEMU模拟环境下启动这个新的内核,系统初始化后,会进入SHELL环境。在这个SHELL环境下,试验一些常用命令,看看是否可以正常运行。

十三、can't access tty

上一步创建的简单linux系统在进入SHELL环境时,会打出下面这一句出错信息:

/bin/sh: can't access tty; job controll off

虽然不影响使用,但终究不够完美。

产生这个错误的原因是我们的SHELL是直接运行在内核的console上的,而console是不能提供控制终端(terminal)功能的,所以必须把SHELL运行在tty设备上,才能消除这个错误。解决问题的办法是使用正规init机制,在执行SHELL前打开tty设备。

另外,这个简单系统的reboot、halt等命令是不起作用的,也必须通过init方式解决。

十四、busybox的缺省init模式

busybox支持init功能,当系统没有/etc/inittab文件时,它有一套缺省的模式,按下面配置执行:

::sysinit:/etc/init.d/rcS

::askfirst:/bin/sh

::ctrlaltdel:/sbin/reboot

::shutdown:/sbin/swapoff -a

::shutdown:/bin/umount -a -r

::restart:/sbin/init

如果busybox检测到/dev/console不是串口控制台,init还要执行下面的动作:

tty2::askfirst:/bin/sh

tty3::askfirst:/bin/sh

tty4::askfirst:/bin/sh

我们试试这种模式是否可以解决我们的问题。

(1)写/etc/init.d/rcS脚本

这个脚本实际是要执行系统的初始化操作。我们把前面的init脚本改造一下,将最后的/bin/sh 命令删除,然后移到etc/init.d目录下,改名为rcS。

(2)initramfs不需要linuxrc,而且如果没有init文件,内核就不认为它是一个有效的initramfs,因而不安装它,导致内核panic。于是,我们在image目录下,把busybox安装的linuxrc改名为init:

mv linuxrc init

(3)重新编译内核,生成新的initramfs

(4)用QEMU试验一下新编译的内核。系统启动后,会打出一句话“please press Enter to active this console”——感觉还不错。但是按下回车键后,系统依然会打出错误信息“-/bin/sh:

can't access tty; job controll off ”。用tty命令看看当前的终端设备文件名:

# tty

/dev/console

它还是console,不是tty设备,所以问题没有解决。不过,reboot和halt命令倒是可以正常工作了。

经过验证,busybox的缺省init模式无法满足我们的要求,我们还是要写inittab,定制自己的init初始化流程。

十五、busybox的inittab文件格式说明

要写自己的inittab,需要理解busybox的inittab文件格式。

busybox的inittab文件与通常的inittab不同,它没有runlevel的概念,语句功能上也有限制。inittab语句的标准格式是

:::

各字段的含义如下

:

id字段与通常的inittab中的含义不同,它代表的是这个语句中process执行所在的tty设备,内容就是/dev目录中tty设备的文件名。由于是运行process的tty设备的文件名,所以也不能象通常的inittab那样要求每条语句id的值唯一。

:

busybox不支持runlevel,所以此字段完全被忽略。

:

为下列这些值之一:

sysinit, respawn, askfirst, wait,once, restart, ctrlaltdel, shutdown

其含义与通常的inittab的定义相同。特别提一下askfirst,它的含义与respawn相同,只是在运行process前,会打出一句话“please press Enter to active this console”,然后等用户在终端上敲入回车键后才运行process。

指定要运行的process的命令行。

十六、写mini linux的inittab

理解了busybox的inittab格式,我们就可以写mini linux的inittab:

::sysinit:/etc/init.d/rcS

tty1::askfirst:/bin/sh

tty2::askfirst:/bin/sh

tty3::askfirst:/bin/sh

tty4::askfirst:/bin/sh

tty5::askfirst:/bin/sh

tty6::askfirst:/bin/sh

::restart:/sbin/init

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

把这个文件放到image的etc目录下。为了执行reboot命令时避免提示找不到/etc/fstab文件,我们再在etc目录下创建一个空文件:

touch fstab

做好了这些,就可以重新编译内核,生成新的initramfs了。在QEMU试验环境下验证新生成的mini linux,系统运行正常,而且象通常的linux系统一样,用ALT+F1~F6键可以在6个终端间切换。

由于mini linux系统不需要登录,所以用askfirst的方式来模拟登录,用户敲回车键后,init 进程才会启动shell。

十七、配置内核支持initrd

到目前为止,我们的initramfs都由内核编译系统生成的,并链接到内核中。其实我们也可以用cpio命令生成单独的initramfs,与内核编译脱钩,在内核运行时以initrd的形式加载到内核,以增加灵活性。

首先配置内核使用单独的initrd:在Device Driver / Block device / 配置目录下,选择RAM filesystem and RAMdisk ( initramfs/initrd ) support 配置项;再到General Setup 配置目录项下,将initramfs source file(s) 配置项原有的内容清空。然后把内核源码树的usr目录下已由内核编译生成的initramfs文件initramfs_data.cpio.gz拷贝到~/initramfs-test 目录下,我们先直接用这个文件试验一下initrd 方式的initramfs的效果。最后,执行make命令重新编译内核后,在QEMU试验环境中,把initrd配置框(linux配置框的下面)的内容写为~/initramfs-test/initramfs_data.cpio.gz,指定initrd的文件路径。

好了,试验一下新的initrd方式的initramfs吧,效果跟先前的完全一样。

十八、用cpio命令生成initramfs

cpio 命令有三种操作模式:copy-out、copy-in、copy-pass,生成initramfs用的是它的

copy-out模式,即把文件打包的操作模式。cpio的copy-out操作模式使用-o 命令行选项指定。缺省情况下,cpio从标准输入读取输入数据,向标准输出写入输出数据。使用-I 选项可以指定文件名代替标准输入,使用-O 选项可以指定文件名代替标准输出,而-F 选项指定的文件名则根据cpio操作模式的不同可代替标准输入或标准输出。

把~/initramfs-test/image目录下的文件打包成initramfs,执行下面的命令:

find . | cpio -o -H newc | gzip > ../image.cpio.gz

命令执行完毕后,在~/initramfs-test目录下就会生成文件名为imgae.cpio.gz的initramfs。

上面cpio命令的-H 选项指定打包文件的具体格式,要生成initramfs,只能用newc 格式,如果使用其他格式,内核会打出这样的出错信息:Unpacking initramfs...<0> kernel panic - not syncing: no cpio magic

在QEMU试验环境下试验一下新的initrd方式的initramfs,效果跟先前的完全一样。

十九、cpio命令的其他用法

如果我们要解开一个cpio格式的打包文件,则要使用cpio命令的copy-in操作模式。cpio 的copy-out操作模式使用-i 命令行选项指定。例如,我们想把前一步从内核源码树usr 目录下拷贝的initramfs_data.cpio.gz 展开到~/initramfs-test/initramfs_data目录下,则使用下列命令:

mkdir ~/initramfs-test/initramfs_data

cd ~/initramfs-test/initramfs_data

cpio -i -F ../initramfs_data.cpio.gz --no-absolute-filename

命令执行完毕后,initramfs_data目录下出现多个目录和文件,用diff命令比较initramfs_data 与image目录,两者的完全一样。

上面cpio命令的--no-absolute-filename 选项的作用是展开文件时,去掉文件路径最前面的"/",把绝对路径名变为相对路径名。内核编译时生成的initramfs使用了绝对路径名,所以这个选项必须使用,否则initramfs内文件展开到"/"目录去了,如果你是root用户或有"/"目录的写权限,那么展开的文件就有可能覆盖同名的文件(在文件修改时间新于原有文件),那就糟糕了!

展开文件前,你可能会想先看看打包文件里都有哪些文件,这时就要用-t 选项了。例如,我们想看看内核编译时生成的initramfs_data.cpio.gz中都有哪些文件,我们就可以用下面的命令:

zcat initramfs_data.cpio.gz | cpio -t

在标准输出中打出文件名列表。

使用-v 选项可以在cpio命令执行时输出详细信息:在打包或展开文件时,输出已处理的文件名;与-t 选项连用时,则显示文件的详细信息,类似ls -l 的输出内容。-V 选项则用打点的方式,显示cpio命令的执行进度信息,一个点代表处理一个文件。

二十、switch_root 命令

除了基于initramfs的系统(如第四节的mini linux),通常initramfs都是为安装最终的根文件系统做准备工作,它的最后一步需要安装最终的根文件系统,然后切换到新根文件系统上去。以往的基于ramdisk 的initrd 使用pivot_root命令切换到新的根文件系统,然后卸载ramdisk。但是initramfs是rootfs,而rootfs既不能pivot_root,也不能umount。为了从initramfs 中切换到新根文件系统,需要作如下处理:

(1)删除rootfs的全部内容,释放空间

find -xdev / -exec rm '{}' ';'

(2)安装新的根文件系统,并切换

cd /newmount; mount --move . /; chroot .

(3)把stdin/stdout/stderr 附加到新的/dev/console,然后执行新文件系统的init程序

上述步骤比较麻烦,而且要解决一个重要的问题:第一步删除rootfs的所有内容也删除了所有的命令,那么后续如何再使用这些命令完成其他步骤?busybox的解决方案是,提供了switch_root命令,完成全部的处理过程,使用起来非常方便。

switch_root命令的格式是:

switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]

其中NEW_ROOT是实际的根文件系统的挂载目录,执行switch_root命令前需要挂载到系统中;NEW_INIT是实际根文件系统的init程序的路径,一般是/sbin/init;-c /dev/console是可选参数,用于重定向实际的根文件系统的设备文件,一般情况我们不会使用;而ARGUMENTS_TO_INIT则是传递给实际的根文件系统的init程序的参数,也是可选的。

需要特别注意的是:switch_root命令必须由PID=1的进程调用,也就是必须由initramfs的init程序直接调用,不能由init派生的其他进程调用,否则会出错,提示:

switch_root: not rootfs

也是同样的原因,init脚本调用switch_root命令必须用exec命令调用,否则也会出错,提示:

switch_root: not rootfs

二十一、实践:用initramfs安装CLFS根文件系统

现在实践一下switch_root命令,用它切换一个CLFS的根文件系统硬盘分区。我的CLFS 安装在/dev/sda8硬盘分区,我们就以此为例说明。

我们还是在以前的image目录中构建

(1)改写init脚本

#!/bin/sh

mount -t proc proc /proc

mount -t sysfs sysfs /sys

mdev -s

mount /dev/sda8 /mnt(注意:为了简单,我们直接把CLFS分区写死在init脚本中了)exec switch_root /mnt /sbin/init

(2)生成新的initrd

按上一节“精通initramfs构建step by step (五):initrd”描述的cpio命令生成新的initrd。(3)把新的initrd拷贝到CLFS分区的/boot目录下,改名为clfs-initrd

(4)在GRUB的menu.lst配置文件中增加一个启动项

#test for initramfs of CLFS

title test for initramfs of CLFS (on /dev/sda8)

root (hd0,7)

kernel /boot/clfskernel-2.6.17.13 (注意:并没有向内核传递root参数信息)

initrd /boot/clfs-initrd

全部做完后,重启机器,选择test for initramfs of CLFS 启动项,机器顺利进入了CLFS系

统,我们构建的initramfs用switch_root命令完成了CLFS实际根文件系统的安装和切换。

二十二、内核模块支持

到目前为止,我们在构建initramfs时还没有涉及内核模块的支持,所用到的硬件驱动程序都是直接编译到内核中。现在我们就看看如何使initramfs支持内核模块。

首先,内核配置要支持模块,并支持内核模块的自动加载功能:在内核配置菜单中的激活下面的配置项,编译进内核Load module support / Enable loadable module support / Automatic kernel loading ;

然后把需要的硬件驱动程序配置模块形式,比如把我的机器上的硬盘控制器的驱动编译成模块,则选择

Device Driver

|---->SCSI device support

|---->SCSI disk support

|----->verbose SCSI error reporting (不是必须的,但可方便问题定位)

|----->SCSI low-level drivers

|---->Serial ATA (SATA) support

|---->intel PIIX/ICH SATA support

把它们配置成模块。

最后,编译内核,并把编译好的内核模块安装到image的目录下:

make

make INSTALL_MOD_PA TH=~/initramfs-test/image modules_install

命令执行完毕后,在image/lib/modules/2.6.17.13/kernel/drivers/scsi目录下安装了4个内核模文件:scsi_mod.ko、sd_mod.ko、ata_piix.ko、libata.ko,它们就是所需的硬盘控制器的驱动程序。

好了,都准备好了,可以用cpio命令生成inintramfs了。不过,为了方便后面的试验,我们再把init脚本改成

#!/bin/sh

mount -t proc proc /proc

mount -t sysfs sysfs /sys

mdev -s

exec /bin/sh

使系统启动后进入shell环境,并且用exec调用的方式,使shell的pid为1,能够执行switch_root命令。

二十三、试验:用initramfs中的内核模块安装硬盘文件系统

用新生成的initramfs启动系统,内核并没有自动加载硬盘控制器的驱动程序,所以/dev 目录下也没有sda等硬盘设备文件。好吧,我们自己加载内核模块文件。不幸的是,busybox 的modprobe命令执行不正常,不能加载内核模块。怀疑是busybox的modprobe命令配置或编译有问题,后续再花时间定位吧,先用insmod命令依次加载。查看/lib/modules /2.6.17.13/modules.dep,弄清楚了4个模块的依赖关系,执行下面的命令加载:

insmod scsi_mod

insmod libata

insmod ata_piix

insmod sd_mod

然后再用

mdev -s

命令生成硬盘的设备文件。

好了,可以安装CLFS的硬盘分区,并把根文件系统切换到CLFS的硬盘分区:

mount /dev/sda8 /mnt

exec switch_root /mnt /sbin/init

系统正常启动到了CLFS,我们可以做到用initramfs中的硬盘控制器的驱动模块安装硬盘分区了。

二十四、mdev的hotplug模式

上面的试验中,我们在加载完驱动模块后调用了mdev -s 命令来生成硬盘的设备文件。其实,可以使用mdev的hotplug模式在加载内核时自动生成对应的设备文件:

在执行insmod命令前,用

echo /sbin/mdev > /proc/sys/kernel/hotplug

命令设置系统的hotplug程序为mdev。

后续使用insmod命令加载模块时,系统自动调用mdev生成相应的设备文件。

注意:内核必须配置支持hotplug功能,而前面提到的CLFS最简内核配置方案是没有配置hotplug支持的。

二十五、udev的coldplug模式

内核在启动时已经检测到了系统的硬件设备,并把硬件设备信息通过sysfs内核虚拟文件系统导出。sysfs文件系统由系统初始化脚本挂载到/sys上。udev扫描sysfs文件系统,根据硬件设备信息生成热插拔(hotplug)事件,udev再读取这些事件,生成对应的硬件设备文件。由于没有实际的硬件插拔动作,所以这一过程被称为coldplug。我们的initramfs就是利用这一机制,加载硬件设备的驱动程序模块。

udev完成coldplug操作,需要下面三个程序:

udevd——作为deamon,记录hotplug事件,然后排队后再发送给udev,避免事件冲突(race conditions)。

udevtrigger——扫描sysfs文件系统,生成相应的硬件设备hotplug事件。udevsettle——查看udev事件队列,等队列内事件全部处理完毕才退出。

在initramfs的init脚本中可以执行下面的语句实现coldplug功能:

mkdir -p /dev/.udev/db

udevd --daemon

mkdir -p /dev/.udev/queue

udevtrigger

udevsettle

许多文档提到的在udevd --daemon 命令前要执行

echo > /proc/sys/kernel/hotplug

命令,经验证,在我们的initramfs环境下的coldplug功能中并不需要。

二十六、试验:用udev自动加载设备驱动模块

了解了udev的coldplug的机理,我们就试验一下用udev自动加载设备驱动模块,并生成硬件设备文件。

(1)从/sbin 目录下拷贝udevd、udevtrigger、udevsettle程序到image目录下的sbin目录下,并用ldd命令找到它们所需要的动态库文件,拷贝到image目录下的lib目录下。

(2)修改init脚本,增加coldplug功能:

#!/bin/sh

mount -t proc proc /proc

mount -t sysfs sysfs /sys

mdev -s

#using udev autoload hard disk driver module

mkdir -p /dev/.udev/db

udevd --daemon

mkdir -p /dev/.udev/queue

udevtrigger

udevsettle

mount /dev/sda8 /mnt

killall udevd

exec switch_root /mnt /sbin/init

注意:在切换到真正根文件系统前,要把udevd进程杀掉,否则会和真正根文件系统中的udev脚本的执行相冲突。这就是上面killall udevd 语句的作用。

(3)编写udev规则文件

规则文件是udev的灵魂,没有规则文件,udev无法自动加载硬件设备的驱动模块。为了简单,我们直接使用CLFS中的40- modprobe.rules,把它拷贝到image目录下的etc/udev/rules.d目录。有关udev的规则文件编写,已超出了本文的范围,后续我有可能专文描述。

########################################################################

#

# Description : 40-modprobe.rules

#

# Authors : Based on Open Suse Udev Rules

# [url=mailto:kay.sievers@suse.de]kay.sievers@suse.de

#

# Adapted to : Jim Gifford

# LFS : Alexander E. Patrakov

#

# Version : 00.01

#

# Notes :

#

########################################################################

# hotplug

ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe $env{MODALIAS}"

# scsi

SUBSYSTEM=="scsi_device", ACTION=="add", SYSFS{device/type}=="0|7|14", RUN+="/sbin/modprobe sd_mod"

SUBSYSTEM=="scsi_device", ACTION=="add", SYSFS{device/type}=="1", SYSFS{device/vendor}=="On[sS]tream", RUN+="/sbin/modprobe osst"

SUBSYSTEM=="scsi_device", ACTION=="add", SYSFS{device/type}=="1", RUN+="/sbin/modprobe st"

SUBSYSTEM=="scsi_device", ACTION=="add", SYSFS{device/type}=="[45]", RUN+="/sbin/modprobe sr_mod"

SUBSYSTEM=="scsi_device", ACTION=="add", RUN+="/sbin/modprobe sg"

# floppy

KERNEL=="nvram", ACTION=="add", RUN+="load_floppy_module.sh"

注意:上面的

ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe $env{MODALIAS}"

语句是实现自动加载硬件设备驱动模块功能的关键,它根据sysfs文件系统中记录的模块aliases数据,用modprobe命令加载对应的内核模块。有关模块aliases的进一步说明,可参考CLFS手册(CLFS-1.0.0-x86)中的11.5.2.4. Module Loading一节的描述。

(4)拷贝modprobe命令

前一节提到过,busybox的modprobe 命令不能正常使用,所以我们需要拷贝/sbin 目录下的modprobe命令到image目录下的sbin目录,供udev加载内核模块使用。再用ldd命令检查一下/sbin/modprobe 命令所需的动态库文件,如果有则拷贝到image/lib目录下。(我的检查结果是,除了libc6外,不需要其他动态库,所以不需要拷贝)

好了,重新生成initramfs,启动CLFS系统,initramfs能够自动加载硬盘设备的驱动模块,系统顺利地从initramfs切换到了真正的CLFS的根文件系统。

二十七、直接把cpio打包文件编译进内核

如果我们有一个已经做好的cpio格式的initramfs,可以在内核编译时直接编译进内核。回忆一下第一节的内容,我们在内核配置参数中的initramfs sources配置项下输入构建initramfs 的目录路径。其实我们也可以直接输出现成的initramfs的文件名,这样在内核编译时,就可以把它编译进内核了。

使用这种方法,有两点需要注意:

(1)cpio文件不能压缩。一般作为initrd的cpio文件都经过了压缩,所以编译前需要先把压缩过的文件解压。

(2)cpio文件的后缀名必须是 .cpio。内核编译通过.cpio的后缀名来识别此文件是cpio 打包文件,而其他文件后缀名则会被认为是initramfs构建的描述文件(关于描述文件,下面后详细说明)。

二十八、用描述文件构建initramfs

用内核编译工具构建initramfs的第三种方法是使用描述文件。在内核配置参数中的initramfs sources配置项下可以输入initramfs构建描述文件的文件名,内核编译工具根据描述文件完

成initramfs的构建。

描述文件的语法格式的说明如下:

# a comment

file

dir

nod

slink

pipe

sock

name of the file/dir/nod/etc in the archive

location of the file in the current filesystem

link target

mode/permissions of the file

user id (0=root)

group id (0=root)

device type (b=block, c=character)

major number of nod

minor number of nod

例子:

我们用描述文件的方式,构建第一节中的hello world的initramfs。

hello-init.desp:

dir /dev 0755 0 0

nod /dev/console 0600 0 0 c 5 1

file /init /home/wyk/initramfs-test/hello_static 0755 0 0

在内核配置项initramfs sources中指定描述文件hello-init.desp,编译内核时就会生成hello world的initramfs,运行效果与第一节用指定构建目录的方法构建的initramfs的完全相同。

注意:在内核帮助文件中,提到initramfs sources配置项可以指定多个目录或描述文件,内核会汇集这些目录或文件生成一个initramfs。但从我的试验来看,initramfs sources只接受单一的目录名或文件名,输出多个目录名或文件名(之间用空格分隔),内核编译时就会出错。也许是我的方法有误,还望读者指正。

二十九、toolchain

在initramfs中使用uclibc库,关键是构建uclibc的工具链toolchain。构建uclibc 的toolchain 有两种主要方式:(1)用buildroot工具(https://www.wendangku.net/doc/553269978.html,/)自动构建,这也是uclibc 的官方标准做法。(2)用CLFS Embedded手册的方法手工创建。目前CLFS Embedded还在开发中,可在https://www.wendangku.net/doc/553269978.html,/view/clfs-embedded/x86/中查阅。

我们简单地说明用buildroot工具构建uclbic的toolchain的步骤:

(1)获取buildroot。

推荐用svn命令从它的版本库中下载:

svn co svn://https://www.wendangku.net/doc/553269978.html,/trunk/buildroot

要求使用svn命令,需要先安装subversion软件包。下载过程中,可能会出现连接异常中断的情况,这时重新执行上述命令,继续进行下载,有可能要重复多次。

(2)配置buildroot

因为我们只是创建toolchain,所以需要做相应的配置。在buildroot的顶层目录下,执行make menuconfig

命令,在缺省配置的基础上做如下配置

Target Architecture: i386

Target Architecture Variant: i686

Package Selection for the target: 取消BusyBox的选项(缺省是选中的)

Target filesystem options: 取消ext2 root filesystem(缺省是选中的)

Toolchain --> Toolchain type: Buildroot toolchain

(3)编译

执行

make

命令,buildroot工具会自动下载所需要的源文件并自动编译,等一两个小时后,toolchain就编译好了。编译好的toolchain位于

buildroot/build_i686/staging_dir/usr/bin/

目录下。工具命令的前缀是i686-linux- 。

三十、编译Busybox静态连接uclibc库

一般而言,使用uclibc库是为了把它静态连接到busybox中。具体步骤是:

(1)把uclibc toolchain的目录添加到PA TH中。

在~/.bash_profile文件中添加:

#set PA TH so it includes uclibc toolchain if it exist

if [ -d ~/buildroot/build_i686/staging_dir/usr/bin ] ; then

PATH="${PATH}":~/buildroot/build_i686/staging_dir/usr/bin

fi

(2)配置busybox静态连接库。

在busybox的配置界面中,选择:

Build Options --> Build BusyBox as a static binary (no shared libs)

(3)编译

执行

make CROSS_COMPILE=i686-linux-

命令“交叉编译”busybox。

最后编译生成的是静态连接的可执行文件,不需要在initramfs中拷贝库文件。

三十一、用buildroot自动构建initramfs

buildroot 工具实际是一个功能强大的根文件系统构建工具,它以uclibc和busybox作为系统构建的基础,toolchain只是它构建系统的中间产品。initramfs是一种特殊的根文件系统,当然也可以用buildroot工具自动构建,下面是构建方法的简要描述:

(1)配置

在buildroot的配置界面下做如下的配置:

Package Selection for the target: 选择

Busybox

Run Busybox's own full installation

Use minimal target skeleton

Target filesystem options --> cpio the root filesystem --> comprassion method: gzip

(2)编译

执行

make

命令,进行编译。

(3)输出

构建好的cpio文件是

buildroot/binaries/rootfs.i686.cpio.gz

同一目录下还包含一个未压缩的文件:rootfs.i686.cpio

构建目录则是

buildroot/project_build_i686/uclibc/root

可以在这个目录下对原始的initramfs进行修改调整,然后自己用cpio命令打包生成新的initramfs。

(4)调整

直接用buildroot生成的root.i686.cpio.gz作为initramfs,运行时会出现

can't open /dev/tty1: No such file or directory

can't open /dev/tty2: No such file or directory

can't open /dev/tty3: No such file or directory

错误信息的循环输出,系统不能正常运行。

错误的原因是没有在initramfs的/dev目录下生成相应的设备文件。需要做如下的调整:1)在构建目录(buildroot/project_build_i686/uclibc/root)下的etc/init.d目录中新增一个初始化脚本文件S10mountfs

#!/bin/sh

mount -t proc proc /proc

mount -t sysfs sysfs /sys

mdev -s

2)更改busybox的setuid属性,否则无法执行mount命令。在构建目录(buildroot/project_build_i686/uclibc/root)下执行

chmod -s bin/busybox

命令。

这两项调整工作做完后,在构建目录(buildroot/project_build_i686/uclibc/root)下执行

find . | cpio -o -H newc |gzip > ../initramfs.cpio.gz

命令,重新生成initramfs的cpio打包文件。

(5)运行效果

运行新的initramfs,系统出现登录提示。输入用户名root,密码为空,即可进入一个mini 的linux系统。

buildroot是功能强大、配置灵活的自动化构建工具,它的详细使用和配置方法超出了本文的范围,后续可能会专文描述,此处就从略了。

三十二、编译klibc

(1)在https://www.wendangku.net/doc/553269978.html,/pub/linux/libs/klibc/下载klibc的源码,目前最新版本是1.5。

(2)解开源码,并在顶层目录建立一个符号链接linux,指向linux的内核源码。注意,内核源码必须已通过make menuconfig等命令配置好。

(3)执行

make

命令,编译klibc。编译完成后,在klibc源码目录树中的usr/dash 和usr/utils 目录中有shell 和一些常用的命令,它们分成静态链接和动态链接的2种版本,分别在static和shared目录下。为了简单,我们的initramfs就使用静态编译的版本。动态链接的程序需要使用klibc 的动态库文件,位于usr/klibc/目录下。

三十三、run-init命令

与busybox类似,klibc中也有一个切换到真实根文件系统的命令,它就是run-init命令。run-init命令的使用格式与busybox中的switch_root 命令一样,它有2个参数:第一个是已挂载了真实根文件系统的目录;第二个是真实根文件系统中的init程序路径名,一般是/sbin/init 。即

run-init /newroot /sbin/init

语句即可从initramfs切换到挂载在/newroot目录下的真实根文件系统,并执行其中的/sbin/init 初始化程序。

三十四、试一试

现在我们已经有了编译好的klibc,也了解了关键的run-init命令,那么就可以试试用klibc 来构建initramfs。我们用QEMU作为试验环境,并假设在/dev/hda8上有linux系统,根文件系统是ext3。

(1)拷贝所需的命令到image构建目录

把klibc中的usr/dash/sh、usr/utils/static目录下的mount、mknod命令拷贝到image/bin目录下。把usr/kinit/run-init/static/run-init命令拷贝到image/sbin目录下。

klibc的静态编译版本命令不需要库文件,所以不需要拷贝。

(2)创建硬盘的设备文件

为了简单,我们不使用udev的方式创建设备文件,而是直接用mknod命令创建硬盘的设备文件。对于IDE硬盘/dev/hda,它的主设备号是3,次设备号是0,是块设备类型,所以用下面的命令在image/dev目录下创建它对应的设备文件

mknod dev/hda b 3 0

/dev/hda上的分区的主设备号也是3,次设备号与分区号相同,据此可以创建/dev/hda1 ~ /dev/hda8的设备文件。

(3)创建/init脚本

#!/bin/sh

/bin/mount -t sysfs sysfs /sys

/bin/mount -t proc proc /proc

/bin/mount -t ext3 /dev/hda6 /mnt

exec /sbin/run-init /mnt /sbin/init

(4)用cpio命令构建initramfs,然后在QEMU环境下进行试验。如果不出意外,试验系统可以正确地从initramfs切换到真实的linux系统上。

三十五、测试一下

通过前十一节的内容,我们可以说已经完全掌握了initramfs构建的方法,那么现在就测试一下,拿一个实际的initramfs来分析,看我们是否能理解多少。

我们选择Debian 4.0 AMD64 版本的initramfs作为目标进行分析,它的initramfs文件是initrd.img-2.6.18-6-amd64。首先用cpio命令把initramfs文件解开,然后打开其中的init脚本文件具体分析。好了,大家利用前面各节的知识开始吧。

作为提示,在这里转载一篇文章,来自https://www.wendangku.net/doc/553269978.html,/u/12679/showart_429816.html:

initrd执行顺序

这是安装过程中的笔记,放这里希望对大家有用。错误之处请指正。

(系统为debian etch, 以安装后默认的initrd.img-2.6.18-5为例)

解开initrd文件:

例如有initrd文件/boot/initrd.img, 用file命令看到这是个gzip压缩的文件,可以用下面的命令解开查看:

代码:

mkdir /boot/myinit

cd /boot/myinit

zcat ../initrd.img | cpio -id(注:用mkinitrd命令默认产生的是cramfs格式的。如果文件格式是压缩的ramfs文件系统,可以直接mount之后查看:mount -t cramfs /boot/initrd.img /mnt/)

如果是2.6内核,因为采用的是cpio压缩,方法如下:

cp /boot/initrd-***.img initrd.img.gz

gunzip initrd.img.gz

mkdir initrd

mv initrd.img initrd

cd initrd

cpio -mdiv < initrd.img

在当前目录下就有一些目录和文件init,其中文件init是启动时加载initrd之后执行的脚本。目录结构:

/bin/: 文件有busybox, mknod, sh, uname, cat, mount, pivot_root等

--------/sbin/: 文件有modprobe, depmod, udevd, udevdtrigger

--------/lib/: 文件有:

----------------(1) 可执行文件需要的动态库

----------------(2) modules/: 内核模块

----------------(3) udev/: udev需要的可执行文件

--------/lib64/: 文件有:x86_64程序装载器

--------/etc/: 与modprobe, udev相关的配置文件

--------/conf/: 有如下的文件

----------------(1) modules: 列出了需要加载的模块

----------------(2) arch.conf: 设置变量DPKG_ARCH=amd64

----------------(3) initramfs.conf: 定义了一些变量

--------/scripts/:

----------------有如下的文件:

----------------functions: 定义了一些方便使用的函数

----------------local和nfs: mount根目录时执行的脚本,一般mount本地系统,执行local

----------------

----------------有如下的目录,其中放置各阶段执行的脚本:

----------------init_top/

----------------init_premount/

----------------init_bottom/

----------------local_top/

----------------local_premount/

----------------local_bottom/

--------/init: 启动时加载initrd之后执行的脚本

生成initrd文件:

find . |cpio -o --dereference -H newc | gzip -9 > ../initrd.img

init文件执行流程:

--------1) 创建目录/dev, /root, /sys, /proc, /tmp, /var/lock,其中/root是下面根文件系统要mount 的位置

--------2) mount系统proc和sys

--------3) 执行脚本/etc/udev/udev.conf,仅定义变量

--------4) mount udev设备:mount -t tmpfs -o size= udev /dev

--------5) 创建/dev/console, /dev/null, /dev/.initramfs

CANoe入门基础Stepbystep系列

CANoe 入门Step by step系列(一)基础应用 CANoe是Vector公司的针对汽车电子行业的总线分析工具,现在我用CANoe7.6版本进行介绍,其他版本功能基本差不多。 硬件我使用的是CAN case XL. 1,CANoe软件的安装很简单,先装驱动,再装软件。安装完成,插上USB,连接硬件,这样在控制面板中,Vector Hardware(硬件)进行查看 通过查看信息可知,CANcaseXL中的两个piggy,一个是251(高速CAN),一个是7269(LIN),另外常用的还有1054(低速CAN,或称容错CAN),因为CANcaseXL(can情况XL最大)中只能支持两路通讯,这样piggy可以自由组合 2,硬件连接正常,打开CANoe软件 File->New Configuration(新配置)可以选择新建工程的模版,我们这里选择 CAN_500kBaud.tcn,这样新建了波特率为500K CAN工程,可以File->Save Configuration (保存配置),进行保存 3,接下来就要使用CAN db++ Editor(编辑)工具对总线网络节点,消息,信号,进行定义了。 点击工具栏的这个图标,或开始菜单中找这个工具启动 启动后,File(文件)->Create Database(创建数据),选择CANTemplate.dbc(模板),选择目录及文件名,进行保存

右键Network nodes(网络节点)->New(新的),进行网络节点的定义,这里只需要填写Name(名字)即可,例如:Node_A(节点A) 然后添加Node_B(节点B),完成后如下图,这样在Network nodes(网络节点)目录下面添加出来两个节点 节点添加完成后,下一步添加CAN消息,右键Messages(信息)->New(新的),这是需要定义名称,ID(身份证件),DLC(数据链路控制)等信息,如下:

stepbystep第二册到答案解析和原文

s t e p b y s t e p第二册到答案解析和原文 公司内部档案编码:[OPPTR-OPPT28-OPPTL98-OPPNN08]

Unit 1 Part I - A 87, 80, 53, 48, 24, 17 Script: The Porter Family Mr William Porter is very old. He is 87. And Mrs Catherine Porter is 80. Mr Porter is from Wales. John Porter and Mary are brother and sister. John Porter is 53 and he is a lawyer. His wife Susan is 48, and she is an architect. James Porter and Joan Lee are cousins. James Porter is 24 and Joan Lee is 17. Part I - B 1.spending special time together. 2.specific, complain, request, praise. 3.fatigue, insecurities, foxhole, striking out , protect. 4.distant 5.all marriages, Work together o understand 6.Respect, danger, professional, physical, verbal 7.Understand, win

stepbystep第一册词汇

STEP BY STEP 第一册词汇 UNIT 1 Part1: chime vt.& vi. 敲出和谐的乐声;报时;机械地重复;合节奏 n.合奏钟声,钟乐;谐音,韵律;和谐;[航]甲板上的沟 millennium n. 一千年;千年期;千禧年;全人类未来的幸福时代 prospective adj. 预期的;未来的;可能的;有希望的gala n. 节日;庆祝 adj. 节日的;欢乐的 count down 倒数到零或规定的时间 fanfare n. 喧耀;号角齐鸣 Kiribati n. 基里巴斯(西太平洋上一共和国) Vietnam 越南 Hanoi 河内(越南首都) Bangkok 曼谷(泰国首都) Egypt 埃及 Part2: install vt.安装;安顿,安置;任命;使…正式就职observatory n. 天文台;气象台;瞭望台revive vt. 使复活,使恢复;使振奋,复原;使再生,使重新流行;唤醒,唤起 vi. 复苏,恢复;振作,恢复;再生,重新流行;再生效力 sweep vt. 打扫,清理;扫除;彻底搜索;掠过 vi. 打扫;扫过;蜿蜒;大范围伸展 n. 打扫;延伸;挥动;全胜viable adj. 切实可行的;能养活的;能自行生产发育的;有望实现的 hoist vt. 升起,提起 vi. 被举起或抬高 n. 起重机,升降机;升起;<俚>推,托,举 gravity n. 重力;万有引力,地心引力;重要性,严重性;严肃,庄重 mechanism n.[生]机制,机能,[乐]机理;(机械)结构, 机械装置[作用],(故事的)结构;[艺]手法,技巧,途径;机械作用 alumi num n. < 美> 铝 flavor n. 味;韵味;特点;香料 vt.给…调味;给…增添风趣 sponsor n. 发起者,主办者;担保者;倡议者,提案人;后援组织 vt. 赞助 Greenwich n. 格林威治(位于英国伦敦东南部,为本初子午线所经之地,原设有英国皇家格林威治天文台),格林威治镇(位于美国康涅狄格州)Miami n. 迈阿密(美国佛罗里州达东南部港市) Atlanta n. 亚特兰大(美国佐治亚州首府)Part3: hesitate vi. 犹豫,踌躇;不愿;支吾;停顿 vt.对…犹豫;不情愿 era n. 纪元,年代;历史时期,时代;重大事件lexicographer

stepbystep3000第二册unit9.答案

Unit 9 Part I A 1. 60,000 / 8.75 2. 452 / 8.3 3. 100,000 / 8.6 4. 8.9 / 2,990 5. 1,530 6. 12, 000 / 5.8 7. 7.1 / 12,230 8. 7.5 / 22,778 9. 6.8 / 25,000 10.6.7 / 50,000 11.9.0 / 300,000 12.69,197 / 18,341 B: 1. Ice, snow, earth, rock / the side of a mountain 2. a slow-moving mudflow 3. the sudden release / waves of shaking 4. system of winds / about 30 to 50 kilometers an hour 5. 64 knows or 74 miles per hour / in the western Atlantic Ocean

10. A violent destructive whirling wind / of short duration 11. 74 mph / in the Pacific Ocean 12. A period of dryness / prevents their successful growth 13. A body of water / normally dry land 14. a wildfire or an uncontrolled fire Suicide bomber C 10.6.8 a bomb explosion in Algiers / in a market area 10.6.9 ocean storm / the Pacific coast of Mexico 10.6.10 the cause of a crash of a passenger p lane / All 143 people / Wednesday 10.6.11 Austrians / the 38 people / at ski area 10.6.12 the hijacker / released his remaining hostages and surrendered to police 10.6.13 Japanese / the nuclear reaction / has stopped 10.6.14 victims of a train accident / 189 / Thursday / 250

stepbystep3000第三册答案听力原文(供参考)

STEP BY STEP 3000 第三册答案 Unit 1 World News: International Relations Part I Warming up A Tapescripts: 1.The former American Defense Secretary William Perry has recommended a radical change of policy towards North Korea. 2.Hundreds of thousands of mother s from across the United States gathere d here in Washington Sunday to push for tougher gun control laws. 3.There's been further fighting between Macedonian forces and Ethnic Albanian guerrillas inside the Macedonian border with Kosovo. 4.A bomb dropped by the United State's navy aircraft during training in Kuwait has hit a group of military observers, killing six of them. 5.NATO is taking a number of steps to allay growing disquiet about the possible health risks from ammunitions containing depleted uranium, which it used in Kosovo and Bosnia. B1. What is the summit's statement expected to call on UN members? To make commitments to eradicate poverty, promote democracy and education, and reverse the spread of AIDS. 2. Which three countries are admitted by ASEAN on Saturday? Burma, Cambodia, and the Laos. 3. What happened on Friday about ten miles south of Pearl Harbor? A U. S. nuclear submarine tore through a Japanese fishing vessel, sinking it within minutes. How many people were on the vessel? And how many were missing? 35/9. 4. What happened in the West Bank and Gaza? Gun battles between Israeli troops and Palestinian gunmen have been raiding overnight. 5. What are the problems with the nuclear facilities and nuclear plants in Japan? Some nuclear facilities have breached many health and safety laws. More than half of the nuclear plants failed some basic tests, such as checking radiation measurements. Tapescripts: 1. With the f inal declaration on its role in the 21st century, the summit's statement is expected to call on UN members to make commitments to eradicate poverty, promote democracy and education, and reverse the spread of AIDS. More than 150 heads of state and government attended the summit, the largest gathering of world leaders in history.

英语听力入门stepbystep3000第一册标准答案及原文

Unit 1 Part I A 1. Oxford / commitment / academic record 2. oldest/ largest / reputation / research / science 3. first / Australia / 150 years / excels 4. excellence / 17.000 / location 5. largest / 1883 / situated / 26,000 6. 1636 / enrollment / 18,500/ schools 7. awards / degrees / 20,000 8. located / 135 / third B 1.2,700 languages / 7,000 dialects / regional / pronunciation 2.official / language 3.One billion / 20 percent 4.Four hundred million / first / 600 million / second / foreign 5.500,000 words / Eighty percent / other 6.Eighty percent / computers 7.African country / same 8.1,000 / Africa 9.spaceship / 1977 / 55 / message / the United States C 1 – (a) 2 – ( c) 3 – ( d) 4 – (b ) All right, class. Today we’re going to be looking at different language learning styles. You may be surprised to find that there are different ways of going about learning languages, none of which is necessarily better than the others. Researchers have identified four basic learner “types”–the communicative learner, the analytical learner, the authority-oriented learner and the concrete learner. Communicative learners like to learn by watching and listening to native speakers. At home, they like to learn by watching TV and videos. They like to learn new words by hearing them. In class, they like to learn by having conversations. Now, concrete learners like to lean by playing games, by looking at pictures and videos in class, talking in pairs, and by listening to cassettes at home and school. Now, authority-oriented learners, on the other hand, like the teacher to explain everything. They like to write everything down in their notebook, and they like to have a textbook. They like to learn new words by seeing them. And finally, we have analytical learners. These learners like to learn by studying grammar. At home, they like to learn by studying English books, and they like to study by themselves. They like to find their own mistakes. Now, of course, it’s unusual for a person to be exclusively one “type” rather than another. Most of us are mixtures of styles. What type of learner do you think you are? Part II A3 GCSE examinations students / higher education student/ second year / high school / college general exam / School Certificate sitting University Entrance Examination bachelor’s degree: 3/ 4 years master’s degree: another year or two doctorate: a further 3-7 years Well, in Britain, from the ages of five to about eleven you start off at a primary school, and then from eleven to sixteen you go on to a secondary school or a comprehensive school and at sixteen you take GCSE examinations. After this, some children take vocational courses or even start work. Others stay on at school for another two years to take A levels. And at the age of eighteen, after A levels, they might finish their education or go on to a course of higher education at a college or university, and that’s usually for three years. Well, it depends on what state you’re in but most kids in the United States start school at about six when they go to elementary school and that goes from the first grade up to the sixth grade. Some

stepbystep3000第二册unit6答案

Unit 6 Part I A 1. straight 2. apart 3. by your sides 4. Relax 1. breath 2. your arms to shoulder height /them out sideways 3. your right arm down to touch your left toes / your left arm stretched out Your knees 5. your left hand down to touch your right toes 6. up again Right everyone. Stand straight ---- feet apart --- hands by your sides. Relax. Everybody ready? Right ---- a nice deep breath --- now raise your arms to shoulder height and stretch tem out sideways. Good --- now swing your right arm down to touch your left toes --- keep your left arm stretched out. Don’t bend your knees --- your legs should be straight --- and up straight again. Now your left hand down to touch your right toes --- and up again. Everybody happy? Now let’s do this with a bit of rhythm.

stepbystep第二册到答案解析和原文

Unit 1 Part I - A 87, 80, 53, 48, 24, 17 Script: The Porter Family Mr William Porter is very old. He is 87. And Mrs Catherine Porter is 80. Mr Porter is from Wales. John Porter and Mary are brother and sister. John Porter is 53 and he is a lawyer. His wife Susan is 48, and she is an architect. James Porter and Joan Lee are cousins. James Porter is 24 and Joan Lee is 17. Part I - B 1.spending special time together. 2.specific, complain, request, praise. 3.fatigue, insecurities, foxhole, striking out , protect. 4.distant 5.all marriages, Work together o understand 6.Respect, danger, professional, physical, verbal 7.Understand, win Part I - C

40, excel, domestic argument, losing win-win, lose-lose, win, a gift, returns argue over, aren't, who, in control, fear, didn't need, ought not to , couldn't, tried to, destroy, marriage love, loved, secure, discover, garden, cultivate, the most precious, own self, bloom. obtain, our partner, loved and respected, control. Part II- A A2 1.similar social backgrounds. 2.the same race or same ethnic background. 3.the same religion. A3 Japan / % / arranged marriages 3% / between blacks and whites Many people in Western cultures choose their own wives and husbands. In many other countries, spouse are often chosen by the parents. In China and Japan before this century (20th century), upper-class marriages were arranged by the older males. In many cultures in the Middle East, Asia, and pre-industrial Europe, the man's family

stepbystep3000第三册unit3答案及原文

英语专业学生经典的听力材料 Unit 3 World News: Econo mic Developme nts Part I Warming up A 1.Whohave been meeting in Hong Kong today to discuss the outlook for the global economy Cen tral Bank gover nors from more tha n a doze n coun tries. 2.What does UNCTAD say about the worldwide total of foreign investment It grew by 40% last Year to more than 600 billio n dollars. 3.Whohas approved a cut in in come tax rates The Un ited States House of Represe ntatives. 4.Whohas announ ced job cuts after a fall in dema ndfor its products In tel What is its pla n To reduce its workforce by5,000. 5.What decisions have been made by EU, the U.S. and Canada after a case of foot-a nd-mouth disease was con firmed in France EU has imposed further restricti ons on the moveme nt of livestock. The U.S. and Can ada have issued temporary bans on the import of an imal produce from EU. Tapescript: 1.Cen tral Bank gover nors from more tha n a doze n coun tries have bee n meet ing in Hong Kong today. One subject they likely discussed is the outlook for the global economy because of the U. S. slowdown and Japan's struggli ng recovery. Ano ther topic they may have discussed is how to strengthen financial markets in emerging economies in Asia and elsewhere. 2. A United Nations' report says the worldwide total of foreign investment grew by nearly 40%last year to more than 600 billion dollars. The report by the UNConference on Trade and Development, UNCTADays most of it took place between developed countries as big companies took one another over.

stepbystep二册答案

—-可编辑修改,可打印—— 别找了你想要的都有! 精品教育资料——全册教案,,试卷,教学课件,教学设计等一站式服务——

全力满足教学需求,真实规划教学环节 最新全面教学资源,打造完美教学模式 Unit 1 Happy Family Life Speaking Topic 1春节词汇Spring Festival Words 节日名Greeting season 春节The Spring Festival 农历lunar calendar 正月lunar January; the first month by lunar calendar 除夕New Year's Eve; eve of lunar New Year 初一the beginning of New Year 元宵节The Lantern Festival 习俗Customs 过年Guo-nian; have the Spring Festival 对联poetic couplet: two successive rhyming lines in poetry 春联Spring Festival couplets 剪纸paper-cuts 年画New Year paintings 买年货special purchases for the Spring Festival ; do Spring Festival shopping 敬酒propose a toast 灯笼lantern: a portable light 烟花fireworks 爆竹firecrackers (People scare off evil spirits and ghosts with the loud pop.) 舞狮lion dance (The lion is believed to be able to dispel evil and bring good luck.)

stepbystep3000第二册unit8答案

Unit 8 Part I A: 1.G reenpeace / attitudes and behavior / environment / peace 2.W orld Wildlife Foundation / 1961 / a future / nature 3.L ive Earth / climate crisis 4.G reen School Project / schools / waste / landfill 5.C limate Change / knowledge / measures 6.F riends of the Earth / network / activist groups / urgent 7.E nvironmental Bureau / 143 / 31/ sustainable 8.F oundation / oceans, waves and beaches / 50,000 9.G reen Building Council / designed, built and operated / responsible, healthy 10.the Alliance to Save Energy / costs / greenhouse gas emissions 11.The Earth Organization /

conservation / rehabilitation /plant and animal 12.Trees, Water &People / natural resources / well-being 13.American Forests / restore and enhance / filter / remove / homes 14.The Global Amphibian Assessment / status / 5,918 / 600 / 60 15.Solar Energy Society / technologies B 1.f ood / doesn’t / packaging 2.v egetables / don’t / chemicals 3.S ave / water 4.w on’t / forever / earth or sea 5.b ottles / once / bank 6.p aper / recycled / 7.A void 8.u nleaded petrol 9.m ade from / protected 10.public transportation 11.wood / rainforests

stepbystep3000第三册unit12答案及原文

s t e p b y s t e p3000第三册u n i t12答案及 原文 本页仅作为文档封面,使用时可以删除 This document is for reference only-rar21year.March

英语专业学生经典的听力材料 Unit 12 A Travel on land water and snow fly portable wing. Fishing or hunting 15 kilometers stay still 30-horsepower motor 160 kilometers 80 450 kilometers Marketing campaign back light aircraft B A golf course named Fox Hollow, which has won an award for its relatively low impact on environment and sustainable wildlife. Golf courses and the environment have historically been at odds. It’s hard to reconcile the careful grooming and excessive water needed for greens and fairways with conservation and natural habitats. One case in point, Lakewood’s Fox Hollow Golf Course had its construction

stepbystep3000第二册听力答案及原文

Unit 1 Happy Family Life Part I Warming up / 1 Part II All you need is love? / 4 Part III First meetings / 9 Part IV A Valentine story / 12 Unit 2 Shaping and Reshaping Personality Part I Warming up / 15 Part II Self-esteem / 19 Part III How to deal with depression and anger? / 22 Part IV Short talks on listening skills / 25 Represent the Ideas Clear and Clean ?Outlining Unit 3 All Can Succeed Part I Warming up / 27 Part II The road to success / 30 Part III Good better best / 34 Part IV Language study and language appreciation / 38 Unit 4 Getting Ready for the Future Career Part I Warming up / 41 Part II Painting for pay / 46 Part III Choosing a career / 49 Part IV My pet hate / 52 Unit 5 Creative Minds Part I Warming up / 55 Part II Scientists of the millennium (I) / 60 Part III Scientists of the millennium (II) / 63 Part IV Short talks on listening skills / 66 Letting Things Go桽peed and Vocabulary Unit 6 Its Great to Be a Champion Part I Warming up / 68 Part II They are the champion! / 72 Part III Luck in the hat / 76 Part IV Language study and language appreciation / 79 Unit 7 Leisure Time Part I Warming up / 82 Part II Mozart's music still alive today / 86 Part III The man with the horn / 89 Part IV Bank Holiday DIY / 92 Unit 8 Everybody Can Help the Environment Part I Warming up / 94 Part II Campaign California Re-Leaf / 97 Part III PBS梐biodegradable plastic product / 100 Part IV Short talks on listening skills / 102 The "Inverted Pyramid" in News Reporting Unit 9 News I: Disasters Part I Warming up / 104 Part II News items / 108 Part III Torrential storms in Kenya / 111 Part IV Language study and language appreciation / 114 Unit 10 News II: Health

stepbystep3000第二册unit7第7单元答案

s t e p b y s t e p3000第二册u n i t7第7单 元答案 本页仅作为文档封面,使用时可以删除 This document is for reference only-rar21year.March

Step by Step 3000 Unit 7 Part I A 1、604,068 2、957,212 3、2,426,533 4、1,719,743 5、907,329 6、419,386 7、36,645 8、1,231,318 9、1,683,855 10,444,509 11、3,273,116 12、1,400,873 13、679,190 14、2,528,437 15、2,058,342 16、960,684 B 100 Philosophy 200 Religion 300 Social Science 400 Language 500 Science 700 Art and Recreation 800 Literature 900 History, Travel, Biography 720 Architecture 730 Sculpture 740 Drawing and Design 750 Painting 770 Photography 780 Music 790 Amusements 791 Public Entertainment 793 Indoor Entertainment 794 Games of Skill 796 Outdoor Sports and Games 797 Water Sports 799 Fishing. Hunting. Shooting C 1、March 21, 1685 January 28, 1750 2、February 23, 1685 April 14, 1759 3、January 27, 1756 December 5, 1791 4、December 17, 1770 March 26, 1827 5、January 31, 1797 November 19, 1828 6、February 3, 1809 November 4, 1847 7、March1,1810 October 17, 1849 8、October 22, 1811 July 314, 1886 9、October 25, 1825 June 3, 1899 10、May 7, 1840 December 6, 1893 Part II A 1—(b) 2—(a) 3—(e) 4—(d) 5—(c) B 1、second half 2、18th 3、17 4、7

相关文档
相关文档 最新文档