Dec 4, 2002
onlsbc1: コンパクトフラッシュ上のLinuxシステムの読み出し専用化
--- RAMディスク(その3) #4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(http://www-online.kek.jp/~inoue/para-CAMAC/
Work/SBC-RAM4.html)
高エネルギー加速器研究機構
素粒子原子核研究所
物理、オンライングループ
井上 栄二
目的
並列CAMACで使用するSBC上のLinuxシステムを、コンパクトフラッシュ上に
構築した。 コンパクトフラッシュ上に、現在構築してあるLinuxシステムは
通常のシステムと同じで、システムはコンパクトフラッシュに対して読み
書きを行っている。 ここで注意すべきことは、コンパクトフラッシュには
構造上書き込み回数に限界があるという点である。 したがって、コンパク
トフラッシュ上のシステムは、読み出し専用として構築するのが望ましい。
読み出し専用化システムの構築作業をするために、256MBのコンパクトフ
ラッシュ上Linuxシステムを構築した。 このコンパクトフラッシュを使っ
て読み出し専用化システムを構築する。(その3)
(1). 方針
(2). ルートファイルシステムの整備
(3). RAMディスク化の検討
(4). /etc/rc.d/rc.sysinit の調査
(5). /etc/rc.d/rc.sysinit の修正
(6). ブートテスト
--------------------------------------------------------------------
(1). 方針
コンパクトフラッシュは書き込み回数に限界があるので読み出し専用として使用
するのが望ましい。 ここでは、コンパクトフラッシュを読み出し専用化する
ために、/var、/tmp、/etcなどのRAMディスク化について検討する。 テストでは
256MBのコンパクトフラッシュを使う。 /etc/rc.d下のスクリプト、rc.sysinit
を修正してRAMディスク化の処理を行う。
(2). ルートファイルシステムの整備
(2-1). コンパクトフラッシュ上のファイル構成
システムインストール直後の、現在の /ディレクトリ構成は次のとおり。
[root@onlsbc1 mnt1]# df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 7360792 2217668 4769212 32% /
/dev/hda5 10475668 160168 9783352 2% /home
/dev/hda6 9685276 32828 9160460 1% /home2
/dev/hda7 10080488 32828 9535592 1% /home3
none 152332 0 152332 0% /dev/shm
/dev/hdc1 241949 219552 9905 96% /mnt1
[root@onlsbc1 mnt1]# pwd
/mnt1
[root@onlsbc1 mnt1]# ls -l
合計 115
drwxr-xr-x 2 root root 2048 11月 13 19:37 bin
drwxr-xr-x 3 root root 1024 11月 13 19:40 boot
drwxr-xr-x 18 root root 82944 11月 15 15:42 dev
drwxr-xr-x 31 root root 3072 11月 15 15:42 etc
drwxr-xr-x 4 root root 1024 11月 13 19:47 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 6 root root 3072 11月 13 19:42 lib
drwx------ 2 root root 12288 11月 13 19:12 lost+found
drwxr-xr-x 3 root root 1024 11月 13 11:15 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
drwxr-xr-x 2 root root 1024 11月 13 19:12 proc
drwxr-x--- 2 root root 1024 11月 13 14:15 root
drwxr-xr-x 2 root root 3072 11月 13 19:41 sbin
drwxrwxrwt 3 root root 1024 11月 15 15:11 tmp
drwxr-xr-x 15 root root 1024 11月 13 19:34 usr
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[root@onlsbc1 mnt1]#
(2-2). コンパクトフラッシュ上のファイル構成の変更
/etc/rc.d/rc.sysinitファイルの中で、RAMディスク構築の作業を行うので、
initrd実行後には /etc下のディレクトリ構造は存在していなければならない。
図2の構成に変更する。
[root@onlsbc1 mnt1]# pwd
/mnt1
[root@onlsbc1 mnt1]# ls -l
合計 115
drwxr-xr-x 2 root root 2048 11月 13 19:37 bin
drwxr-xr-x 3 root root 1024 11月 13 19:40 boot
drwxr-xr-x 18 root root 82944 11月 15 15:42 dev
drwxr-xr-x 31 root root 3072 11月 15 15:42 etc
drwxr-xr-x 4 root root 1024 11月 13 19:47 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 6 root root 3072 11月 13 19:42 lib
drwx------ 2 root root 12288 11月 13 19:12 lost+found
drwxr-xr-x 3 root root 1024 11月 13 11:15 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
drwxr-xr-x 2 root root 1024 11月 13 19:12 proc
drwxr-x--- 2 root root 1024 11月 13 14:15 root
drwxr-xr-x 2 root root 3072 11月 13 19:41 sbin
drwxrwxrwt 3 root root 1024 11月 15 15:11 tmp
drwxr-xr-x 15 root root 1024 11月 13 19:34 usr
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[root@onlsbc1 mnt1]#
[root@onlsbc1 mnt1]# mkdir ramfs
[root@onlsbc1 mnt1]# mv etc ramfs
[root@onlsbc1 mnt1]# mv tmp ramfs
[root@onlsbc1 mnt1]# mv var ramfs
[root@onlsbc1 mnt1]#
/etc、/tmp、/var から ramfs の下にそれぞれシンボリックリンクを張る。
[root@onlsbc1 mnt1]# ln -s ramfs/etc etc
[root@onlsbc1 mnt1]# ln -s ramfs/tmp tmp
[root@onlsbc1 mnt1]# ln -s ramfs/var var
[root@onlsbc1 mnt1]#
[root@onlsbc1 mnt1]# ls -l
合計 111
drwxr-xr-x 2 root root 2048 11月 13 19:37 bin
drwxr-xr-x 3 root root 1024 11月 13 19:40 boot
drwxr-xr-x 18 root root 82944 11月 15 15:42 dev
lrwxrwxrwx 1 root root 9 11月 20 14:16 etc -> ramfs/etc
drwxr-xr-x 4 root root 1024 11月 13 19:47 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 6 root root 3072 11月 13 19:42 lib
drwx------ 2 root root 12288 11月 13 19:12 lost+found
drwxr-xr-x 3 root root 1024 11月 13 11:15 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
drwxr-xr-x 2 root root 1024 11月 13 19:12 proc
drwxr-xr-x 5 root root 1024 11月 20 14:15 ramfs
drwxr-x--- 2 root root 1024 11月 13 14:15 root
drwxr-xr-x 2 root root 3072 11月 13 19:41 sbin
lrwxrwxrwx 1 root root 9 11月 20 14:16 tmp -> ramfs/tmp
drwxr-xr-x 15 root root 1024 11月 13 19:34 usr
lrwxrwxrwx 1 root root 9 11月 20 14:16 var -> ramfs/var
[root@onlsbc1 mnt1]# ls -l ramfs
合計 5
drwxr-xr-x 31 root root 3072 11月 15 15:42 etc
drwxrwxrwt 3 root root 1024 11月 15 15:11 tmp
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[root@onlsbc1 mnt1]#
。
(2-3). /mnt1/ramfs/etc の下のシンボリックリンクのチェック
ルートファイルシステムの構成を変更した際にシンボリックリンクが壊れた
可能性がある。 シンボリックリンクを調べる。
[root@onlsbc1 etc]# pwd
/mnt1/etc
[root@onlsbc1 etc]# ls -l grub.conf
lrwxrwxrwx 1 root root 22 11月 13 19:47 grub.conf -> ../boot/gr
ub/grub.conf
[root@onlsbc1 etc]#
/etc/grub.conf のシンボリックリンクが切れてしまった。 下のディレクトリ
もチェックしたが、シンボリックリンクが切れたのは grub.confだけであった。
張りなおす。
[root@onlsbc1 etc]# mv grub.conf grub.conf-old
[root@onlsbc1 etc]# ln -s ../../boot/grub/grub.conf grub.conf
[root@onlsbc1 etc]# ls -l grub*
lrwxrwxrwx 1 root root 25 11月 20 14:45 grub.conf -> ../../boot
/grub/grub.conf
lrwxrwxrwx 1 root root 22 11月 13 19:47 grub.conf-old -> ../boo
t/grub/grub.conf
[root@onlsbc1 etc]# ls -lL grub.conf
-rw------- 1 root root 570 11月 13 19:47 grub.conf
[root@onlsbc1 etc]#
(2-3-1). /mnt1/ramfs/etc/httpd の下のシンボリックリンクのチェック
[root@onlsbc1 httpd]# pwd
/mnt1/etc/httpd
[root@onlsbc1 httpd]# ls -l
合計 1
drwxr-xr-x 2 root root 1024 11月 13 19:42 conf
lrwxrwxrwx 1 root root 19 11月 13 19:42 logs -> ../../var/log/h
ttpd
lrwxrwxrwx 1 root root 21 11月 13 19:42 modules -> ../..//usr/l
ib/apache
[root@onlsbc1 httpd]#
/mnt1/ramfs/etc/httpd/modules のシンボリックリンクが切れてしまった。
張りなおす。
[root@onlsbc1 httpd]# pwd
/mnt1/etc/httpd
[root@onlsbc1 httpd]# mv modules modules-old
[root@onlsbc1 httpd]# ln -s ../../../usr/lib/apache modules
[root@onlsbc1 httpd]#
(2-3-2). /mnt1/ramfs/etc/sysconfig/network-scripts の下のシンボリックリンク
のチェック
/mnt1/ramfs/etc/sysconfig/network-scripts のシンボリックリンクが切れて
しまった。 張りなおす。
[root@onlsbc1 network-scripts]# pwd
/mnt1/etc/sysconfig/network-scripts
[root@onlsbc1 network-scripts]# ls -l ifdown
lrwxrwxrwx 1 root root 20 11月 13 19:37 ifdown -> ../../../sbin
/ifdown
[root@onlsbc1 network-scripts]#
[root@onlsbc1 network-scripts]# mv ifdown ifdown-old
[root@onlsbc1 network-scripts]# ln -s ../../../../sbin/ifdown ifdown
[root@onlsbc1 network-scripts]# ls -lL ifdown
-rwxr-xr-x 1 root root 3136 4月 20 2002 ifdown
[root@onlsbc1 network-scripts]#
[root@onlsbc1 network-scripts]# ls -l ifup
lrwxrwxrwx 1 root root 18 11月 13 19:37 ifup -> ../../../sbin/i
fup
[root@onlsbc1 network-scripts]# mv ifup ifup-old
[root@onlsbc1 network-scripts]# ln -s ../../../../sbin/ifup ifup
[root@onlsbc1 network-scripts]# ls -lL ifup
-rwxr-xr-x 1 root root 7133 4月 20 2002 ifup
[root@onlsbc1 network-scripts]#
(2-4). /mnt1/ramfs/tmp の下のシンボリックリンクのチェック
[root@onlsbc1 mnt1]# pwd
/mnt1
[root@onlsbc1 mnt1]# ls -laLR tmp
tmp:
合計 3
drwxrwxrwt 3 root root 1024 11月 15 15:11 .
drwxr-xr-x 5 root root 1024 11月 20 14:15 ..
drwxrwxrwx 2 bin bin 1024 11月 15 15:42 .iroha_unix
srwxrwxr-x 1 inoue inoue 0 11月 15 15:07 .kon1
tmp/.iroha_unix:
合計 2
drwxrwxrwx 2 bin bin 1024 11月 15 15:42 .
drwxrwxrwt 3 root root 1024 11月 15 15:11 ..
[root@onlsbc1 mnt1]#
/mnt1/ramfs/tmp/.kon1ファイルは削除する。
[root@onlsbc1 mnt1]# rm -f tmp/.kon1
[root@onlsbc1 mnt1]# ls -laRL tmp
tmp:
合計 3
drwxrwxrwt 3 root root 1024 11月 21 11:09 .
drwxr-xr-x 5 root root 1024 11月 20 14:15 ..
drwxrwxrwx 2 bin bin 1024 11月 15 15:42 .iroha_unix
tmp/.iroha_unix:
合計 2
drwxrwxrwx 2 bin bin 1024 11月 15 15:42 .
drwxrwxrwt 3 root root 1024 11月 21 11:09 ..
[root@onlsbc1 mnt1]#
(2-5). /mnt1/ramfs/var の下のシンボリックリンクのチェック
/mnt1/ramfs/var の下をチェックしたところシンボリックリンクが切れている
ものはなかった。
(3). RAMディスク化の検討
(3-1). RAMディスク化のための操作手順
RAMディスク化のためのコマンドは /mnt1/etc/rc.d/rc.sysinitファイルの中に
追記する。 ここで行う操作は、
(1). RAMディスクを初期化する。
(2). /mnt1/ramfs下のファイルをRAMディスクにコピーする。
(3). RAMディスクを /ramfsにマウントする。
である。
(3-2). カーネルパラメータについてのチェック
RAMディスク用に確保すべきサイズを調べる。
[root@onlsbc1 ramfs]# pwd
/mnt1/ramfs
[root@onlsbc1 ramfs]# ls -l
合計 5
drwxr-xr-x 31 root root 3072 11月 20 14:45 etc
drwxrwxrwt 3 root root 1024 11月 21 11:09 tmp
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[root@onlsbc1 ramfs]# du -k
121 ./etc/sysconfig/network-scripts
1 ./etc/sysconfig/console
:
261 ./var/www
22753 ./var
24881 .
[root@onlsbc1 ramfs]#
ramfs下の etc、tmp、varを収めるRAMディスクのサイズは約25MB必要である。
しかし、カーネルが作成できるRAMディスクの最大サイズは、標準では4MBで
ある。 Red Hat Linux ディストリビューションで採用されているカーネル
組み込み型のドライバの場合は、カーネル起動時に "ramdisk_size=32" の
ようにオプションを渡せば、最大サイズを変更できる。 この例では32MBの
最大サイズに変更したことになる。
チェック:
256MBのコンパクトフラッシュ上のLinuxシステムを、"ramdisk_size=32"の
オプションで起動し直して、実際に使用できるRAMディスクのサイズを確かめて
みる。 /boot/grub/grub.conf を以下のように、RAMディスクの拡張オプション
を付加した項目を追加する。
(3-2-1). /mnt1/boot/grub/grub.confファイルの修正
[root@onlsbc1 grub]# pwd
/mnt1/boot/grub
[root@onlsbc1 grub]# ls
device.map ffs_stage1_5 menu.lst splash.xpm.gz vstafs_stage1_5
e2fs_stage1_5 grub.conf minix_stage1_5 stage1 xfs_stage1_5
fat_stage1_5 jfs_stage1_5 reiserfs_stage1_5 stage2
[root@onlsbc1 grub]# vi grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/hdc1
# initrd /boot/initrd-version.img
#boot=/dev/hdc
default=0
timeout=10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-3)
root (hd0,0)
kernel /boot/vmlinuz-2.4.18-3 ro root=/dev/hdc1
initrd /boot/initrd-2.4.18-3.img
title 32MB RAM Disk, Red Hat Linux (2.4.18-3)
root (hd0,0)
kernel /boot/vmlinuz-2.4.18-3 ro root=/dev/hdc1 ramdisk_size=32768
initrd /boot/initrd-2.4.18-3.img
~
"grub.conf" 22L, 740C written
[root@onlsbc1 grub]#
システムをリブートする。
[root@onlsbc1 grub]# reboot
Broadcast message from root (pts/1) (Tue Nov 26 16:35:32 2002):
The system is going down for reboot NOW!
[root@onlsbc1 grub]#
256MB のコンパクトフラッシュ上のLinuxシステムが立ち上がった。
[inoue@onlpara .ssh]$ ssh onlsbc1
The authenticity of host 'onlsbc1 (130.87.153.3)' can't be established.
RSA key fingerprint is 0b:79:9e:79:ac:c3:9e:10:c6:98:cc:7c:46:3e:96:3e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'onlsbc1,130.87.153.3' (RSA) to the list of known hos
ts.
inoue@onlsbc1's password:
Last login: Tue Nov 26 16:54:17 2002
[inoue@onlsbc1 inoue]$ ls -l
合計 0
[inoue@onlsbc1 inoue]$ df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 241949 219611 9846 96% /
none 152332 0 152332 0% /dev/shm
[inoue@onlsbc1 inoue]$
(3-2-2). RAMディスクを作成する
[root@onlsbc1 inoue]# /sbin/mke2fs /dev/ram0 32768
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
8192 inodes, 32768 blocks
1638 blocks (5.00%) reserved for the super user
First data block=1
4 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@onlsbc1 inoue]#
ok. 32MB のRAMディスクを作ることができた。
(3-2-3). RAMディスクを一旦、/mnt にマウントして必要なファイルを書き込む
[root@onlsbc1 inoue]# ls -l /mnt
合計 1
drwxr-xr-x 2 root root 1024 11月 13 11:15 floppy
[root@onlsbc1 inoue]#
[root@onlsbc1 inoue]# mount -n -o rw /dev/ram0 /mnt
[root@onlsbc1 inoue]# df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 241949 219611 9846 96% /
none 152332 0 152332 0% /dev/shm
[root@onlsbc1 inoue]#
[root@onlsbc1 inoue]# ls -l /mnt
合計 12
drwx------ 2 root root 12288 11月 26 16:57 lost+found
[root@onlsbc1 inoue]#
/ramfs 下のファイルを RAMディスクにコピーする。
[root@onlsbc1 /]# pwd
/
[root@onlsbc1 /]# ls -l
合計 110
drwxr-xr-x 2 root root 2048 11月 13 19:37 bin
drwxr-xr-x 3 root root 1024 11月 13 19:40 boot
drwxr-xr-x 18 root root 82944 11月 26 16:53 dev
lrwxrwxrwx 1 root root 9 11月 20 14:16 etc -> ramfs/etc
drwxr-xr-x 4 root root 1024 11月 13 19:47 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 6 root root 3072 11月 13 19:42 lib
drwx------ 2 root root 12288 11月 13 19:12 lost+found
drwxr-xr-x 3 root root 1024 11月 27 09:57 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
dr-xr-xr-x 44 root root 0 11月 27 01:51 proc
drwxr-xr-x 5 root root 1024 11月 20 14:15 ramfs
drwxr-x--- 2 root root 1024 11月 13 14:15 root
drwxr-xr-x 2 root root 3072 11月 13 19:41 sbin
lrwxrwxrwx 1 root root 9 11月 20 14:16 tmp -> ramfs/tmp
drwxr-xr-x 15 root root 1024 11月 13 19:34 usr
lrwxrwxrwx 1 root root 9 11月 20 14:16 var -> ramfs/var
[root@onlsbc1 /]#
[root@onlsbc1 /]# cp -pdr ramfs/etc /mnt
[root@onlsbc1 /]# cp -pdr ramfs/tmp /mnt
cp: cannot open `ramfs/tmp/.iroha_unix/IROHA' for reading: そのようなデバイスや
アドレスはありません
cp: cannot open `ramfs/tmp/.kon1' for reading: そのようなデバイスやアドレスはあ
りません
[root@onlsbc1 /]# cp -pdr ramfs/var /mnt
[root@onlsbc1 /]#
[root@onlsbc1 /]# ls -l /mnt
合計 17
drwxr-xr-x 31 root root 3072 11月 26 16:52 etc
drwx------ 2 root root 12288 11月 26 16:57 lost+found
drwxrwxrwt 3 root root 1024 11月 27 04:02 tmp
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[root@onlsbc1 /]#
[root@onlsbc1 /]# cd /mnt
[root@onlsbc1 mnt]# du -k
12 ./lost+found
121 ./etc/sysconfig/network-scripts
:
261 ./var/www
22820 ./var
24960 .
[root@onlsbc1 mnt]#
/mntにマウントしてあるRAMディスクに、約25MBのファイルを書き込んだ。
(3-2-4). /mntをアンマウントして、/ramfs にマウントし直す
[root@onlsbc1 /]# pwd
/
[root@onlsbc1 /]# umount /mnt
[root@onlsbc1 /]# mount -n -o rw /dev/ram0 /ramfs
[root@onlsbc1 /]# ls -l
合計 110
drwxr-xr-x 2 root root 2048 11月 13 19:37 bin
drwxr-xr-x 3 root root 1024 11月 13 19:40 boot
drwxr-xr-x 18 root root 82944 11月 26 16:53 dev
lrwxrwxrwx 1 root root 9 11月 20 14:16 etc -> ramfs/etc
drwxr-xr-x 4 root root 1024 11月 13 19:47 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 6 root root 3072 11月 13 19:42 lib
drwx------ 2 root root 12288 11月 13 19:12 lost+found
drwxr-xr-x 3 root root 1024 11月 13 11:15 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
dr-xr-xr-x 44 root root 0 11月 27 01:51 proc
drwxr-xr-x 6 root root 1024 11月 27 10:01 ramfs
drwxr-x--- 2 root root 1024 11月 13 14:15 root
drwxr-xr-x 2 root root 3072 11月 13 19:41 sbin
lrwxrwxrwx 1 root root 9 11月 20 14:16 tmp -> ramfs/tmp
drwxr-xr-x 15 root root 1024 11月 13 19:34 usr
lrwxrwxrwx 1 root root 9 11月 20 14:16 var -> ramfs/var
[root@onlsbc1 /]# df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 241949 219622 9835 96% /
none 152332 0 152332 0% /dev/shm
[root@onlsbc1 /]# ls -l /mnt
合計 1
drwxr-xr-x 2 root root 1024 11月 13 11:15 floppy
[root@onlsbc1 /]# ls -l ramfs
合計 17
drwxr-xr-x 31 root root 3072 11月 26 16:52 etc
drwx------ 2 root root 12288 11月 26 16:57 lost+found
drwxrwxrwt 3 root root 1024 11月 27 04:02 tmp
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[root@onlsbc1 /]#
ok. これで /ramfs の下はRAMディスクに置き換わった。
[root@onlsbc1 /]# pwd
/
[root@onlsbc1 /]# ls -lLR tmp
tmp:
合計 0
[root@onlsbc1 /]# touch /tmp/test
[root@onlsbc1 /]# ls -lLR /tmp
/tmp:
合計 0
-rw-r--r-- 1 root root 0 11月 27 10:14 test
[root@onlsbc1 /]# umount /ramfs
[root@onlsbc1 /]# ls -lLR /tmp
/tmp:
合計 0
[root@onlsbc1 /]#
ok. コンパクトフラッシュには書き込みは行われていない。
上記でやったことをブート時のスクリプトに追記すれば、/etc、/tmp、/var の
RAMディスク化は達成できる。
(4). /mnt1/etc/rc.d/rc.sysinit の調査
/mnt1/etc/rc.d/rc.sysinitファイルの内容をチェックする。
[root@onlsbc1 rc.d]# df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 241949 219622 9835 96% /
none 152332 0 152332 0% /dev/shm
[root@onlsbc1 rc.d]# pwd
/etc/rc.d
[root@onlsbc1 rc.d]# ls
init.d rc.local rc0.d rc2.d rc4.d rc6.d
rc rc.sysinit rc1.d rc3.d rc5.d
[root@onlsbc1 rc.d]#
[inoue@onlsbc1 rc.d]$ vi rc.sysinit
#!/bin/bash
#
# /etc/rc.sysinit - run once at boot time
:
# Rerun ourselves through initlog
:
# If we're using devfs, start devfsd now - we need the old device names
:
# Set the path
:
# Read in config data.
:
# Source functions
:
# Print a banner. ;)
:
# Fix console loglevel
:
# Mount /proc (done here so volume labels can work with fsck)
:
# Unmount the initrd, if necessary
:
# Configure kernel parameters
:
# Set the system clock.
:
# Load keymap
:
# Load system font
:
# Start up swapping.
:
# Set the hostname.
:
# Initialize USB controller and HID devices
:
# Possibly update quotas if fsck was run on /.
:
# check for arguments passed from kernel
:
# set up pnp
:
# Remount the root filesystem read-write.
:
# LVM initialization
:
# Clear mtab
:
# Remove stale backups
:
# Enter root, /proc and (potentially) /proc/bus/usb and devfs into mtab.
:
# The root filesystem is now read-write, so we can now log via syslog() directly
:
# Our modutils don't support it anymore, so we might as well remove
# the preferred link.
:
# tweak isapnp settings if needed.
:
# Load sound modules iff they need persistent DMA buffers
:
# Load modules (for backward compatibility with VARs)
:
# Add raid devices
:
# LVM initialization, take 2 (it could be on top of RAID)
:
# Check filesystems
:
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
:
# check remaining quotas other than root
:
# Configure machine if necessary.
:
# Clean out /etc.
:
# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
:
# Clean up /var
# I'd use find, but /usr may not be mounted.
:
# Reset pam_console permissions
:
# Clean up utmp/wtmp
:
# Delete X locks
:
# Delete VNC & X locks
:
# Delete Postgres sockets
:
# Now turn on swap in case we swap to files.
:
# Initialize the serial ports.
:
# If a SCSI tape has been detected, load the st module unconditionally
# since many SCSI tapes don't deal well with st being loaded and unloaded
:
# Load usb storage here, to match most other things
:
# If they asked for ide-scsi, load it
:
# Turn off DMA on CD-ROMs. It more often than not causes problems.
:
# Turn on harddisk optimization
# There is only one file /etc/sysconfig/harddisks for all disks
# after installing the hdparm-RPM. If you need different hdparm parameters
# for each of your disks, copy /etc/sysconfig/harddisks to
# /etc/sysconfig/harddiskhda (hdb, hdc...) and modify it.
# Each disk which has no special parameters will use the defaults.
# Each non-disk which has no special parameters will be ignored.
:
# Generate a header that defines the boot kernel.
:
# Adjust symlinks as necessary in /boot to keep system services from
# spewing messages about mismatched System maps and so on.
:
# The special Red Hat kernel library symlink must point to the right library
# We need to deal with cases where there is no library, and we need to
# deal with any version numbers that show up.
:
# Now that we have all of our basic modules loaded and the kernel going,
# let's dump the syslog ring somewhere so we can find it later
:
# Also keep kernel symbols around in case we need them for debugging
:
# create the crash indicator flag to warn on crashes, offer fsck with timeout
:
[inoue@onlsbc1 rc.d]$
(5). /mnt1/etc/rc.d/rc.sysinit の修正
(5-1). RAMディスク化のための変更
rc.sysinitファイルの記述の中の以下の部分に、RAMディスク化のためのコマン
ドを追記する。
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
:
<--- この部分にRAMディスク化のためのコマンドを追記
:
# check remaining quotas other than root
[root@onlsbc1 rc.d]# pwd
/etc/rc.d
[root@onlsbc1 rc.d]# ls -l
合計 36
drwxr-xr-x 2 root root 1024 11月 13 19:42 init.d
-rwxr-xr-x 1 root root 3108 9月 22 2001 rc
-rwxr-xr-x 1 root root 220 7月 11 2001 rc.local
-rwxr-xr-x 1 root root 22379 4月 19 2002 rc.sysinit
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc0.d
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc1.d
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc2.d
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc3.d
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc4.d
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc5.d
drwxr-xr-x 2 root root 1024 11月 13 19:42 rc6.d
[root@onlsbc1 rc.d]#
[root@onlsbc1 rc.d]# vi rc.sysinit
:
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
action $"Mounting local filesystems: " mount -a -t nonfs,smbfs,ncpfs -O no_netde
v
# <-- by E.Inoue : from here
/sbin/mke2fs -q /dev/ram0 32768
mount -n -o rw /dev/ram0 /mnt
cp -pdr ramfs/etc /mnt
cp -pdr ramfs/tmp /mnt
cp -pdr ramfs/var /mnt
umount /mnt
mount -n -o rw /dev/ram0 /ramfs
# --> to here
# check remaining quotas other than root
if [ X"$_RUN_QUOTACHECK" = X1 -a -x /sbin/quotacheck ]; then
:
"rc.sysinit" 791L, 22598C written
[root@onlsbc1 rc.d]# ls -l rc.sysinit
-rwxr-xr-x 1 root root 22598 11月 27 16:13 rc.sysinit
[root@onlsbc1 rc.d]#
注意.
RAMディスク化したのは、システムが書き込む可能性があるディレクトリ
のみである。 この他にもユーザおよびルートが書き込む可能性がある
ディレクトリとして /home、/root がある。 ここは、他のマシンの
ディレクトリをNFSマウントして使う等の処置をしてもらうことにする。
ここでは、この部分については何もしない。
(5-2). /ramfs/tmp 下のファイルの削除
[root@onlsbc1 tmp]# pwd
/ramfs/tmp
[root@onlsbc1 tmp]# ls -lRa
.:
合計 3
drwxrwxrwt 3 root root 1024 11月 27 04:02 .
drwxr-xr-x 5 root root 1024 11月 20 14:15 ..
drwxrwxrwx 2 bin bin 1024 11月 26 16:53 .iroha_unix
srwxrwxr-x 1 inoue inoue 0 11月 26 16:54 .kon1
./.iroha_unix:
合計 2
drwxrwxrwx 2 bin bin 1024 11月 26 16:53 .
drwxrwxrwt 3 root root 1024 11月 27 04:02 ..
srwxrwxrwx 1 bin bin 0 11月 26 16:53 IROHA
[root@onlsbc1 tmp]#
[root@onlsbc1 tmp]# rm -f .iroha_unix/IROHA
[root@onlsbc1 tmp]# rm -f .kon1
[root@onlsbc1 tmp]# ls -lRa
.:
合計 3
drwxrwxrwt 3 root root 1024 11月 27 16:21 .
drwxr-xr-x 5 root root 1024 11月 20 14:15 ..
drwxrwxrwx 2 bin bin 1024 11月 27 16:21 .iroha_unix
./.iroha_unix:
合計 2
drwxrwxrwx 2 bin bin 1024 11月 27 16:21 .
drwxrwxrwt 3 root root 1024 11月 27 16:21 ..
[root@onlsbc1 tmp]#
(6). ブートテスト
(6-1). コンパクトフラッシュ上のLinuxシステムを立ち上げる
[root@onlsbc1 /]# reboot
Broadcast message from root (pts/0) (Wed Nov 27 16:31:09 2002):
The system is going down for reboot NOW!
[root@onlsbc1 /]#
MBR部のGRUBが起動し、以下のメニューが表示された。
|
V
RAM SIZE=32MB, Red Hat Linux 7.3 (2.4.18-3)
RAM SIZE=32MB, Compact Flash Red Hat Linux 7.3 (2.4.18-3) <-- この項目
を選択
|
V
/dev/hdc1部のGRUBが起動し、以下のメニューが表示された。
|
V
32MB RAM Disk, Red Hat Linux (2.4.18-3)<--- この項目を選択
|
V
ブート処理は進んで、INITが実行されRAMディスク作成も正常に実行できた。
システムはシャットダウンした後、正常に立ち上がった。
[inoue@onlpara inoue]$ ssh onlsbc1
inoue@onlsbc1's password:
Last login: Wed Nov 27 16:36:21 2002 from onlnote2.kek.jp
[inoue@onlsbc1 inoue]$ df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 241949 219621 9836 96% /
none 152332 0 152332 0% /dev/shm
[inoue@onlsbc1 inoue]$ ls -l /
合計 110
drwxr-xr-x 2 root root 2048 11月 13 19:37 bin
drwxr-xr-x 3 root root 1024 11月 13 19:40 boot
drwxr-xr-x 18 root root 82944 11月 27 16:34 dev
lrwxrwxrwx 1 root root 9 11月 20 14:16 etc -> ramfs/etc
drwxr-xr-x 4 root root 1024 11月 13 19:47 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 6 root root 3072 11月 13 19:42 lib
drwx------ 2 root root 12288 11月 13 19:12 lost+found
drwxr-xr-x 3 root root 1024 11月 13 11:15 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
dr-xr-xr-x 40 root root 0 11月 28 2002 proc
drwxr-xr-x 6 root root 1024 11月 27 16:33 ramfs
drwxr-x--- 2 root root 1024 11月 13 14:15 root
drwxr-xr-x 2 root root 3072 11月 13 19:41 sbin
lrwxrwxrwx 1 root root 9 11月 20 14:16 tmp -> ramfs/tmp
drwxr-xr-x 15 root root 1024 11月 13 19:34 usr
lrwxrwxrwx 1 root root 9 11月 20 14:16 var -> ramfs/var
[inoue@onlsbc1 inoue]$ ls -l /ramfs
合計 17
drwxr-xr-x 31 root root 3072 11月 27 16:33 etc
drwx------ 2 root root 12288 11月 27 16:33 lost+found
drwxrwxrwt 3 root root 1024 11月 27 16:21 tmp
drwxr-xr-x 16 root root 1024 11月 13 19:42 var
[inoue@onlsbc1 inoue]$
ok. RAMディスクがマウントされている。
(6-2). リブートする
[root@onlsbc1 inoue]# reboot
Broadcast message from root (pts/0) (Wed Nov 27 16:51:19 2002):
The system is going down for reboot NOW!
[root@onlsbc1 inoue]#
:
:
Stopping crond: [ OK ]
Shutting down APM daemon: [ OK ]
Saving random seed: [ OK ]
Stopping portmapper: [ OK ]
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Flushing all chains: [ OK ]
Removing user defined chains: [ OK ]
Resetting built-in chains to the default ACCEPT policy [ OK ]
Starting killall: [ OK ]
Sending all process TERM signal... su(pam_unix)[986]: session closed for user
root [ OK ]
Sending all process KILL signal... md: recovery thread got woken up...
md: recovery thread finised: [ OK ]
Syncing hardware clock to system time [ OK ]
Turning off quotas: [ OK ]
Unmounting file systems: umount2: Device or resource busy
unmount: /ramfs: Illegal seek
[ FAILED ]
INIT: no more processes left in this runlevel
ここで停止している。
/ramfs のアンマウントが考慮されてない。 シャットダウン時の /ramfs の
アンマウントの処置が必要だ。
(6-3). シャットダウン時の手続きを調べる
Shutdownはinitプロセスにシグナルを送りランレベ ルの変更を依頼する。
o ランレベル0はシステムを停止する
o ランレベル6はシステムをリブートす る
o ランレベル1はシステムの管理業務が行なえる状態(シングルユーザモード)
にする
システムの停止又はリブート時にどのような動作がなされるかは、/etc/inittab
ファイル中のそれぞれのランレベルの適切なエントリーを参照。
[root@onlsbc1 etc]# cat /etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg,
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
# Things to run in every runlevel.
ud::once:/sbin/update
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
# Run xdm in runlevel 5
# xdm is now a separate service
x:5:respawn:/etc/X11/prefdm -nodaemon
[root@onlsbc1 etc]#
halt および reboot 時の処理は rc0.d および rc6.d 下のスクリプトの中で
やればよいことがわかる。 実際には、rc0.d および rc6.d 下のファイルは全て
/etc/rc.d/init.d 下のファイルへのシンボリックリンクであるから、
/etc/rc.d/init.d 下のスクリプトを修正することになる。
(6-4). init.d 下のスクリプトのチェック
上記の項目(6-2)の実行結果の記録に注目。
:
:
Syncing hardware clock to system time [ OK ]
Turning off quotas: [ OK ]
Unmounting file systems: umount2: Device or resource busy
unmount: /ramfs: Illegal seek
[ FAILED ]
INIT: no more processes left in this runlevel
umount のエラーを表示している直前のメッセージを出力しているスクリプトを
確認する。
[inoue@onlsbc1 rc.d]$ pwd
/etc/rc.d
[inoue@onlsbc1 rc.d]$ grep Syncing */*
init.d/halt:runcmd $"Syncing hardware clock to system time" /sbin/hwclock $CLOCK
FLAGS
rc0.d/S01halt:runcmd $"Syncing hardware clock to system time" /sbin/hwclock $CLO
CKFLAGS
rc6.d/S01reboot:runcmd $"Syncing hardware clock to system time" /sbin/hwclock $C
LOCKFLAGS
[inoue@onlsbc1 rc.d]$
[inoue@onlsbc1 rc.d]$ grep Turning */*
init.d/halt:[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
init.d/halt:[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotao
ff -aug
rc0.d/S01halt:[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
rc0.d/S01halt:[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quot
aoff -aug
rc6.d/S01reboot:[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
rc6.d/S01reboot:[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/qu
otaoff -aug
[inoue@onlsbc1 rc.d]$
rc0.d/S01halt および rc6.d/S01reboot のスクリプトの中で、"Turning off
quotas:" のメッセージを出力している。
[inoue@onlsbc1 rc.d]$ pwd
/etc/rc.d
[inoue@onlsbc1 rc.d]$ ls -l rc0.d/S01halt
lrwxrwxrwx 1 root root 14 11月 28 09:44 rc0.d/S01halt -> ../ini
t.d/halt
[inoue@onlsbc1 rc.d]$ ls -l rc6.d/S01reboot
lrwxrwxrwx 1 root root 14 11月 28 09:44 rc6.d/S01reboot -> ../i
nit.d/halt
[inoue@onlsbc1 rc.d]$
つまり、/etc/rc.d/init.d/haltスクリプトが "Turning off quotas:" の
メッセージを出力している。 この処理をした直後に /ramfs の umount を行う
ように修正しよう。
(6-5). /etc/rc.d/init.d/haltスクリプトの修正
現在、使用している onlsbc1 のLinuxシステムは、コンパクトフラッシュ上の
ものである。 つまり、/etcディレクトリ等はRAMディスクになっているので
/etc下のファイルを修正しても、システムを立ち上げ直すと修正した部分は
消えてしまい反映されない。 そこで、一旦、2.5"のIDEディスク上のLinuxシス
テムを立ち上げてコンパクトフラッシュ上のファイルシステムをマウントして
修正することにする。
[inoue@onlpara inoue]$ ssh onlsbc1
The authenticity of host 'onlsbc1 (130.87.153.3)' can't be established.
RSA key fingerprint is 83:6d:2a:db:5b:38:f4:65:0c:b8:bd:eb:c2:e7:87:a9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'onlsbc1,130.87.153.3' (RSA) to the list of known hos
ts.
inoue@onlsbc1's password:
Last login: Thu Nov 28 09:40:51 2002
[inoue@onlsbc1 inoue]$ su
Password:
[root@onlsbc1 inoue]# mount -t ext3 /dev/hdc1 /mnt1
[root@onlsbc1 inoue]# df -k
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hdc1 7360792 2216068 4770812 32% /
/dev/hda5 10475668 166124 9777396 2% /home
/dev/hda6 9685276 32828 9160460 1% /home2
/dev/hda7 10080488 32828 9535592 1% /home3
none 152332 0 152332 0% /dev/shm
/dev/hdc1 241949 219621 9836 96% /mnt1
[root@onlsbc1 inoue]#
[root@onlsbc1 init.d]# pwd
/mnt1/etc/rc.d/init.d
[root@onlsbc1 init.d]# ls
anacron canna gpm ipchains keytable netfs random single
apmd crond halt iptables killall network rawdevices sshd
atd functions httpd kdcrotate kudzu portmap sendmail syslog
[root@onlsbc1 init.d]# mv halt BACK-halt
[root@onlsbc1 init.d]# cp BACK-halt halt
[root@onlsbc1 init.d]# ls -l
合計 81
-rwxr-xr-x 1 root root 5153 3月 28 2002 BACK-halt
-rwxr-xr-x 1 root root 934 6月 25 2001 anacron
-rwxr-xr-x 1 root root 1458 4月 15 2002 apmd
-rwxr-xr-x 1 root root 1176 1月 18 2002 atd
-rwxr-xr-x 1 root root 1319 4月 10 2002 canna
-rwxr-xr-x 1 root root 1316 4月 15 2002 crond
-rwxr-xr-x 1 root root 9962 3月 13 2002 functions
-rwxr-xr-x 1 root root 1541 4月 10 2002 gpm
-rwxr-xr-x 1 root root 5153 11月 29 11:00 halt
-rwxr-xr-x 1 root root 2188 4月 10 2002 httpd
-rwxr-xr-x 1 root root 3313 2月 22 2002 ipchains
-rwxr-xr-x 1 root root 5528 3月 4 2002 iptables
-rwxr-xr-x 1 root root 1084 3月 1 2002 kdcrotate
-rwxr-xr-x 1 root root 1273 4月 15 2002 keytable
-rwxr-xr-x 1 root root 487 1月 31 2001 killall
-rwxr-xr-x 1 root root 1919 4月 18 2002 kudzu
-rwxr-xr-x 1 root root 5104 3月 13 2002 netfs
-rwxr-xr-x 1 root root 6390 4月 13 2002 network
-rwxr-xr-x 1 root root 1831 2月 28 2002 portmap
-rwxr-xr-x 1 root root 1544 3月 13 2001 random
-rwxr-xr-x 1 root root 2295 1月 31 2001 rawdevices
-rwxr-xr-x 1 root root 1830 4月 8 2002 sendmail
-rwxr-xr-x 1 root root 1329 2月 28 2001 single
-rwxr-xr-x 1 root root 2647 4月 5 2002 sshd
-rwxr-xr-x 1 root root 1369 4月 18 2002 syslog
[root@onlsbc1 init.d]#
[root@onlsbc1 init.d]# vi halt
:
# Turn off swap, then unmount file systems.
SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
[ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug
# Unmount file systems, killing processes if we have to.
# Unmount loopback stuff first
# <-- by E.Inoue : from here
umount /ramfs
# --> to here
remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/moun
ts`
:
"halt" 216L, 5212C written
[root@onlsbc1 init.d]#
(6-6). ブートの実行(その2)
2.5"IDEディスク上のLinuxシステムを reboot する。
[root@onlsbc1 init.d]# reboot
Broadcast message from root (pts/0) (Fri Nov 29 11:08:17 2002):
The system is going down for reboot NOW!
Read from remote host onlsbc1: Connection reset by peer
Connection to onlsbc1 closed.
[inoue@onlpara inoue]$
コンパクトフラッシュ上のシステムが立ち上がった。
[inoue@onlpara inoue]$ ssh onlsbc1
The authenticity of host 'onlsbc1 (130.87.153.3)' can't be established.
RSA key fingerprint is 0b:79:9e:79:ac:c3:9e:10:c6:98:cc:7c:46:3e:96:3e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'onlsbc1,130.87.153.3' (RSA) to the list of known hos
ts.
inoue@onlsbc1's password:Last login: Wed Nov 27 08:53:50 2002 from onlnote2.kek.jp
[inoue@onlsbc1 inoue]$
[inoue@onlsbc1 init.d]$ pwd
/etc/rc.d/init.d
[inoue@onlsbc1 init.d]$ ls -l
合計 81
-rwxr-xr-x 1 root root 5153 3月 28 2002 BACK-halt
-rwxr-xr-x 1 root root 934 6月 25 2001 anacron
-rwxr-xr-x 1 root root 1458 4月 15 2002 apmd
-rwxr-xr-x 1 root root 1176 1月 18 2002 atd
-rwxr-xr-x 1 root root 1319 4月 10 2002 canna
-rwxr-xr-x 1 root root 1316 4月 15 2002 crond
-rwxr-xr-x 1 root root 9962 3月 13 2002 functions
-rwxr-xr-x 1 root root 1541 4月 10 2002 gpm
-rwxr-xr-x 1 root root 5212 11月 29 11:03 halt
-rwxr-xr-x 1 root root 2188 4月 10 2002 httpd
-rwxr-xr-x 1 root root 3313 2月 22 2002 ipchains
-rwxr-xr-x 1 root root 5528 3月 4 2002 iptables
-rwxr-xr-x 1 root root 1084 3月 1 2002 kdcrotate
-rwxr-xr-x 1 root root 1273 4月 15 2002 keytable
-rwxr-xr-x 1 root root 487 1月 31 2001 killall
-rwxr-xr-x 1 root root 1919 4月 18 2002 kudzu
-rwxr-xr-x 1 root root 5104 3月 13 2002 netfs
-rwxr-xr-x 1 root root 6390 4月 13 2002 network
-rwxr-xr-x 1 root root 1831 2月 28 2002 portmap
-rwxr-xr-x 1 root root 1544 3月 13 2001 random
-rwxr-xr-x 1 root root 2295 1月 31 2001 rawdevices
-rwxr-xr-x 1 root root 1830 4月 8 2002 sendmail
-rwxr-xr-x 1 root root 1329 2月 28 2001 single
-rwxr-xr-x 1 root root 2647 4月 5 2002 sshd
-rwxr-xr-x 1 root root 1369 4月 18 2002 syslog
[inoue@onlsbc1 init.d]$ vi halt
:
# Unmount file systems, killing processes if we have to.
# Unmount loopback stuff first
# <-- by E.Inoue : from here
umount /ramfs
# --> to here
remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/moun
ts`
:
[inoue@onlsbc1 init.d]$
コンパクトフラッシュ上のシステムを reboot する。
[root@onlsbc1 init.d]# reboot
Broadcast message from root (pts/0) (Fri Nov 29 14:48:10 2002):
The system is going down for reboot NOW!
[root@onlsbc1 init.d]#
:
Syncing hardware clock to system time [ OK ]
Turning off quotas: [ OK ]
Unmounting file systems: umount2: Device or resource busy
unmount: /ramfs: Illegal seek
[ FAILED ]
INIT: no more processes left in this runlevel
症状は変わらない。 スクリプトのこの時点で /ramfs をアンマウントできない
としても何も問題はない。 スクリプトの実行を中断しないで、処理を先に
進めてやるようにしよう。
[root@onlsbc1 init.d]# pwd
/mnt1/etc/rc.d/init.d
[root@onlsbc1 init.d]# vi halt
:
# Unmount file systems, killing processes if we have to.
# Unmount loopback stuff first
# <-- by E.Inoue : from here
#umount /ramfs
# --> to here
remaining=`awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/moun
ts`
:
if [ "$retry" -lt 3 ]; then
LANG=C runcmd $"Unmounting file systems (retry): " umount -f $r
emaining
else
LANG=C runcmd $"Unmounting file systems: " umount -f $remaining
fi
sleep 2
remaining=`halt_get_remaining | sort -r`
# <-- by E.Inoue : from here
# echo $"$remaining"
["$remaining" = /ramfs ] && break
# --> to here
[ -z "$remaining" ] && break
/sbin/fuser -k -m $sig $remaining >/dev/null
:
"halt" 222L, 5314C written
[root@onlsbc1 init.d]#
2.5"IDEディスク上のLinuxシステムを reboot する。
[root@onlsbc1 init.d]# reboot
Broadcast message from root (pts/0) (Fri Nov 29 17:16:09 2002):
The system is going down for reboot NOW!
[root@onlsbc1 init.d]#
コンパクトフラッシュ上のシステムが立ち上がった。
コンパクトフラッシュ上のシステムを reboot する。
:
Unmounting file systems: umount2: Device or resource busy
unmount: /ramfs: Illegal seek
[ FAILED ]
/etc/rc6.d/S01reboot:[/ramfs: No such file or directory
INIT: no more processes left in this runlevel
となった。 $remaining をクリアしておかないと、スクリプトの後ろの方で、
再度マウントしようとするので上記のようなメッセージが出力される。
[root@onlsbc1 init.d]# pwd
/mnt1/etc/rc.d/init.d
[root@onlsbc1 init.d]# vi halt
:
# <-- by E.Inoue : from here
# echo $"$remaining"
["$remaining" = /ramfs ] && $remaining < /dev/null ; break
# --> to here
:
"halt" 222L, 5339C written
[root@onlsbc1 init.d]#
[root@onlsbc1 init.d]# reboot
Broadcast message from root (pts/0) (Fri Nov 29 17:53:03 2002):
The system is going down for reboot NOW!
[root@onlsbc1 init.d]#
ok. [FAILED] のメッセージを表示した後、スクリプトの処理は進んで、Linux
システムはリブートした。
(6-7). [FAILED] のメッセージを表示しないで処理を進めるように修正
[root@onlsbc1 init.d]# pwd
/mnt1/etc/rc.d/init.d
[root@onlsbc1 init.d]# vi halt
:
sig=
retry=3
remaining=`halt_get_remaining | sort -r`
# <-- by E.Inoue : from here
#echo $"$remaining"
if [ ${remaining:1:5} = ramfs ]; then
# echo "eqaul"
["$remaining" = /ramfs ] && $remaining < /dev/null
else
# echo " not eqaul"
# --> to here
while [ -n "$remaining" -a "$retry" -gt 0 ]
do
if [ "$retry" -lt 3 ]; then
LANG=C runcmd $"Unmounting file systems (retry): " umount -f $r
emaining
else
LANG=C runcmd $"Unmounting file systems: " umount -f $remaining
fi
sleep 2
remaining=`halt_get_remaining | sort -r`
# <-- by E.Inoue : from here
# echo $"$remaining"
# ["$remaining" = /ramfs ] && $remaining < /dev/null ; break
# --> to here
[ -z "$remaining" ] && break
/sbin/fuser -k -m $sig $remaining >/dev/null
sleep 5
retry=$(($retry-1))
sig=-9
done
# <-- by E.Inoue : from here
fi
# --> to here
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
# remove the crash indicator flag
:
"halt" 235L, 5586C written
[root@onlsbc1 init.d]#
立ち上げ直す。
[root@onlsbc1 init.d]# reboot
Broadcast message from root (pts/1) (Wed Dec 4 14:20:23 2002):
The system is going down for reboot NOW!
[root@onlsbc1 init.d]#
コンパクトフラッシュ上のシステムが立ち上がった。
コンパクトフラッシュ上のシステムを reboot する。
:
Syncing hardware clock to system time [ OK ]
Turning off quotas: [ OK ]
/etc/rc.d/S01halt: [/ramfs: No such file or drectory
Rebooting system...
:
ok. [FAILED] のメッセージを表示しないでリブートは実行された。
シャットダウンした場合について確認する。
ot@onlsbc1 init.d]# /sbin/shutdown -h now
:
Syncing hardware clock to system time [ OK ]
Turning off quotas: [ OK ]
/etc/rc.d/S01halt: [/ramfs: No such file or dirctory
Halting system...
md: stopping all md devices.
flushing ide devices: hda hdc
Power down.
ok. 正常にシャットダウンできた。 これで、Linuxシステムの一部を
RAMディスク化する作業は完了。
---xxxx