というわけで本日の作業はカーネルを 2.0.25 にして、いよいよ modules を使ってみる。
参考にするのは Kerneld.euc だ。modules については私なんぞが説明するより、 最近の Linux 関係の雑誌、書籍で紹介されているのでそちらを参考にしてく ださい。そのほうが絶対に正確です。:-)
それでも簡単でいいから教えろって?
ではホントに簡単に。カーネルをコンパイルするとき、様々なモノを組み込む かどうか尋かれますよね。そして自分の環境に必要だと思えば y で組み込む し、必要ないと思えば n で組み込まない。
でも、中には普段はほとんど必要なくって、たまぁに使うなんてものもあるん じゃないですか?
私の場合、例えば umsdos のサポートなんかそうですね。こういうの は「モジュール」にしてしまい、必要なときロードして、必要なくなったらア ンロードできると効率が良い。だってロードしてなければ、それだけメモリー もくわないんですから。
modules というのは、つまりそういうのを可能にしてくれるものなん です。んで、普通は必要になったら自分で「モジュール」をロードし、必要な くなったら、やはり自分で「モジュール」をアンロードするんですが、これを 自動的にしてくれるのが kerneld なんです。
では早速とりかかりましょうか。まずは modules-2.0.0.tar.gz から なのサ!
cipher:~# ls -l modules-2.0.0.tar.gz -r--r--r-- 1 root root 115459 Nov 10 02:33 modules-2.0.0.tar.gz cipher:~# tar xfz modules-2.0.0.tar.gz cipher:~# cd modules-2.0.0 cipher:~# ls COPYING README depmod insmod rc.hints Makefile Version.h genksyms kerneld展開した後は、いきなり make だい。
cipher:~# make make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/insmod' gcc -O6 -pipe -fomit-frame-pointer -Wall -c insmod.c -o insmod.o gcc -O6 -pipe -fomit-frame-pointer -Wall -c load_aout.c -o load_aout.o gcc -O6 -pipe -fomit-frame-pointer -Wall -c load_elf.c -o load_elf.o gcc -O6 -pipe -fomit-frame-pointer -Wall -c error.c -o error.o gcc -s insmod.o load_aout.o load_elf.o error.o -o insmod cat lsmod.sh >lsmod chmod a+x lsmod for i in rmmod ksyms; do ln -sf insmod $i; done make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/insmod' make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/genksyms' gcc -c -O2 symlex.c gcc -O2 -Wall makecrc32.c -o makecrc32 ./makecrc32 > crc32.tab gcc -O2 -Wall -c parsesym.c -o parsesym.o gcc -O2 -Wall -o genksyms symlex.o parsesym.o make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/genksyms' make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/depmod' g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c main.c -o main.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c depmod.c -o depmod.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c modprobe.c -o modprobe.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c error.c -o error.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c module.c -o module.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c symbol.c -o symbol.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c alloctxt.c -o alloctxt.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c str.c -o str.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c config.c -o config.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c fgets.c -o fgets.o g++ -O -I. -DPUBLIC= -DPROTECTED= -DPRIVATE= -Wall -c load_obj.c -o load_obj.o cc -s -o modprobe main.o depmod.o modprobe.o error.o module.o symbol.o alloctxt.o str.o config.o fgets.o load_obj.o ln -fs modprobe depmod make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/depmod' make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/kerneld' cc -O6 -pipe -fomit-frame-pointer -Wall -DDEBUG -DNO_GDBM -c kerneld.c -o kerneld.o cc -s kerneld.o -o kerneld make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/kerneld' cipher:~# ls COPYING README depmod insmod rc.hints Makefile Version.h genksyms kerneldんでもってインストールしちゃう。
cipher:~# make install make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/insmod' + install -s -c insmod /sbin + install -s -c lsmod /sbin + cd /sbin + ln -sf insmod rmmod + ln -sf insmod ksyms Have you read the README? Things might have changed... + install -m 644 -c insmod.1 /usr/man/man1 + install -m 644 -c ksyms.1 /usr/man/man1 + install -m 644 -c lsmod.1 /usr/man/man1 + install -m 644 -c rmmod.1 /usr/man/man1 + install -m 644 -c modules.2 /usr/man/man2 make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/insmod' make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/genksyms' install -c -s genksyms /sbin install -m 644 genksyms.8 /usr/man/man8 make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/genksyms' make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/depmod' install --strip -m 755 -o bin -g bin modprobe /sbin/modprobe ln -fs /sbin/modprobe /sbin/depmod + install -c depmod.1 /usr/man/man1 ln -f /usr/man/man1/depmod.1 /usr/man/man1/modprobe.1 make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/depmod' make[1]: Entering directory `/home/tools/Linux/modules-2.0.0/kerneld' + install -m 0700 -o root -s -c kerneld /sbin Do 'make install-scripts' in the kerneld directory to get a default /sbin/request-route install -c kerneld.8 /usr/man/man8 make[1]: Leaving directory `/home/tools/Linux/modules-2.0.0/kerneld' You might want to adapt your /etc/rc.*' as well (manually) cipher:~# ls -lt /sbin/ | head -9 total 1750 -rwxr-xr-x 1 root root 20800 Nov 10 11:04 genksyms -rwxr-xr-x 1 bin bin 29108 Nov 10 11:04 modprobe lrwxrwxrwx 1 root root 14 Nov 10 11:04 depmod -> /sbin/modprobe -rwx------ 1 root root 10512 Nov 10 11:04 kerneld -rwxr-xr-x 1 root root 118 Nov 10 11:04 lsmod -rwxr-xr-x 1 root root 23760 Nov 10 11:04 insmod lrwxrwxrwx 1 root root 6 Nov 10 11:04 rmmod -> insmod lrwxrwxrwx 1 root root 6 Nov 10 11:04 ksyms -> insmodさて、ここで /etc/rc.d/rc.S にちょっと書き加えよう。
cipher:~# cd /etc/rc.d/ cipher:~# ls -l rc.S -rwxr-xr-x 1 root root 3854 Sep 12 00:35 rc.S cipher:~# cp -a rc.S rc.S_old cipher:~# ls -l rc.S* -rwxr-xr-x 1 root root 3854 Sep 12 00:35 rc.S -rwxr-xr-x 1 root root 3854 Sep 12 00:35 rc.S_old cipher:~# vi rc.S cipher:~# ls -l rc.S* -rwxr-xr-x 1 root root 5061 Nov 10 11:18 rc.S -rwxr-xr-x 1 root root 3854 Sep 12 00:35 rc.S_old cipher:~# diff -u rc.S_old rc.S --- rc.S_old Thu Sep 12 00:35:31 1996 +++ rc.S Sun Nov 10 11:18:21 1996 @@ -13,6 +13,15 @@ # Start update. /sbin/update & +# +# add (96/11/10) Y.Yokota +# Now, start kerneld as soon as possible, so that any disk +# driver modules can be loaded "automagically" +if [ -x /sbin/kerneld ] +then + /sbin/kerneld +fi + # Test to see if the root partition is read-only, like it ought to be. READWRITE=no if echo -n >> "Testing filesystem status"; then @@ -91,6 +100,51 @@ # remove /etc/mtab* so that mount will create it with a root entry /bin/rm -f /etc/mtab* /etc/nologin /var/run/utmp + +# +# add (96/11/10) Y.Yokota +# The code from here, down to "#=========" can be put in a separate script +# +# Create a generic link to the modules for the current kernel +# +# You can have generic symbolic links in /lib/modules/boot +# if you create links to: "../current/subsystem/module.o" +# +ln -snf /lib/modules/`uname -r` /lib/modules/current +# If you have an old "ln", replace the above line with: +# rm -f /lib/modules/current +# ln -sf /lib/modules/`uname -r` /lib/modules/current + +if [ \! -r /lib/modules/current/modules.dep ] +then + echo "Creating module dependencies" + /sbin/depmod -a +fi + +# +# Load the boot modules +# +if [ -x /sbin/kerneld ] +then + if find /lib/modules/boot -type f -o type l > /dev/null 2>&1 + then + echo "Loading boot-time modules" + /sbin/modprobe -a -t boot \* + fi +else + echo "Loading modules" + /sbin/modprobe -a \* +fi + +# +# If you have any extra kerneld-type daemons, start them here +# +if [ -x /sbin/kdsound ] +then + echo "Starting sound daemon" + /sbin/kdsound & +fi +#========= # mount file systems in fstab (and create an entry for /) # but not NFS because TCP/IP is not yet configured cipher:~#これは modules-2.0.0.tar.gz の中に入っていた rc.hints を 参考に加えています。 さぁ次はカーネル 2.0.25 の構築だ。最初はパッチをあてなくちゃね。
cipher:~# ls -l patch-2.0.25.gz -r--r--r-- 1 root root 14000 Nov 9 15:43 patch-2.0.25.gz cipher:~# gzip -dc patch-2.0.25.gz |(cd /usr/src/; patch -p0 -s)続いてディレクトリの名前を変更しときましょ。
cipher:~# cd /usr/src/ cipher:~# ls -ld linux* lrwxrwxrwx 1 root root 12 Oct 30 19:24 linux -> linux-2.0.24 drwxr-xr-x 15 root root 1024 Nov 10 11:31 linux-2.0.24 cipher:~# mv linux-2.0.24 linux-2.0.25 cipher:~# ln -fs linux-2.0.25 linux cipher:~# ls -ld linux* lrwxrwxrwx 1 root root 12 Nov 10 11:32 linux -> linux-2.0.25 drwxr-xr-x 15 root root 1024 Nov 10 11:31 linux-2.0.25さて make config をかけなきゃ。今までと同じで私はログを残したい 一心で make config を選択してしちゃってます。あと kernel をどのように構築するかも基本的には今迄通りです。もちろん RAMDISK もサポートにいれます。しかしそのうちのいくつかをモジュー ルにします。
構築自体は make mrproper をして一度徹底的なクリーンをしてから make config の後、make dep;make clean をして、いつものよ うに私は make zdisk を実行して一度 floopy に新しい kernel を入れた。その後に make modules と make modules_install を実行してモジュールをインストールしました。
そしてできたよ、できましたよ。私の新しい cipher が、
cipher:~# uname -a Linux cipher 2.0.25 #1 Sun Nov 10 11:56:39 JST 1996 i586 cipher:~# cat /proc/version Linux version 2.0.25 (root@cipher) (gcc version 2.7.2.1) #1 Sun Nov 10 11:56:39 JST 1996さて、では lilo に追加しましょ。
cipher:~# mv /usr/src/linux/arch/i386/boot/zImage /vmlinuz_2.0.25 cipher:~# chmod 400 /vmlinuz_2.0.25 cipher:~# vi /etc/lilo.conf cipher:~# lilo -v LILO version 19, Copyright 1992-1996 Werner Almesberger Reading boot sector from /dev/hda Merging with /boot/boot.b Boot other: /dev/hda1, on /dev/hda, loader /boot/chain.b Added dos * Boot image: /vmlinuz_2.0.25 Added linux Boot image: /vmlinuz_2.0.0 Added linux_2 /boot/boot.0300 exists - no backup copy made. Writing boot sector.上記のラベル linux が今入れた 2.0.25 で linux_2 は 2.0.0 です。一応残しているんです。f(^^;
ちなみに以下が私の /etc/lilo.conf です。
# LILO configuration created by QuickInst 0.17 Fri Nov 1 23:19:45 JST 1996 # # Start LILO global section boot = /dev/hda compact delay = 50 # optional, for systems that boot very quickly vga = normal # force sane state # ramdisk = 0 # paranoia setting, but old options # End LILO global section # ###### # DOS bootable partition config begins other = /dev/hda1 label = dos table = /dev/hda # DOS bootable partition config ends ###### # Linux 2.0.25 bootable partition config begins image = /vmlinuz_2.0.25 root = /dev/hdb2 label = linux read-only # Non-UMSDOS filesystems should be mounted read-only for checking ###### # Linux 2.0.0 bootable partition config begins image = /vmlinuz_2.0.0 root = /dev/hdb2 label = linux_2 read-only # Non-UMSDOS filesystems should be mounted read-only for checking # Linux bootable partition config ends ######最後に modules がちゃんと組み込まれているか確認しよう。
cipher:~# ps -aux |grep kernel root 10 0.0 0.6 796 212 ? S Nov 20 0:00 /sbin/kerneld root 2368 0.0 0.8 852 280 p3 R 23:13 0:00 grep kernel cipher:~# /sbin/lsmod Module: #pages: Used by: psaux 1 1 (autoclean) nfs 13 5 (autoclean) cipher:~# ls /dos anykey dblspace.bin hikaru32 msdos.bak sega autoexec.bat ddpmm io.sys msdos.sys setuplog.txt autoexec.old detlog.txt jrd_inst.ini msinput suhdlog.dat autoexec.tws dosime.sys linux netscape system.1st bootlog.prv drvspace.bin mach64 oemlog.txt temp bootlog.txt etc master~1 progra~1 trumpet command.com exchange mmapp recycled windows config.sys fips msdos.--- scandisk.log window~1.bmk cipher:~# /sbin/lsmod Module: #pages: Used by: umsdos 6 1 (autoclean) msdos 2 [umsdos] 1 (autoclean) fat 6 [umsdos msdos] 1 (autoclean) psaux 1 1 (autoclean) nfs 13 5 (autoclean)
今日はルンルンのスィッチオフ。