Dec 24, 2002
onlsbc1: コンパクトフラッシュ上のLinuxシステムの読み出し専用化
--- RAMディスク(その4) #7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(http://www-online.kek.jp/~inoue/para-CAMAC/
Work/SBC-RAM7.html)
高エネルギー加速器研究機構
素粒子原子核研究所
物理、オンライングループ
井上 栄二
目的
並列CAMACで使用するSBC上のLinuxシステムを、コンパクトフラッシュ上に
構築した。 コンパクトフラッシュ上に、現在構築してあるLinuxシステムは
通常のシステムと同じで、システムはコンパクトフラッシュに対して読み
書きを行っている。 ここで注意すべきことは、コンパクトフラッシュには
構造上書き込み回数に限界があるという点である。 したがって、コンパク
トフラッシュ上のシステムは、読み出し専用として構築するのが望ましい。
読み出し専用化システムの構築作業をするために、512MBのコンパクトフ
ラッシュ上にRed Hat Linux 8.0 のシステムを構築した。 このコンパクト
フラッシュを使って読み出し専用化システムを構築する。(その4)
(1). 方針
(2). ルートファイルシステムの整備
(3). RAMディスク化の検討
(4). /etc/rc.d/rc.sysinit の調査
(5). /etc/rc.d/rc.sysinit の修正
(6). ブートテスト
--------------------------------------------------------------------
(1). 方針
コンパクトフラッシュは書き込み回数に限界があるので読み出し専用として使用
するのが望ましい。 ここでは、コンパクトフラッシュを読み出し専用化する
ために、/var、/tmp、/etcなどのRAMディスク化について検討する。 テストでは
512MBのコンパクトフラッシュ上に構築した Red Hat Linux 8.0 のシステムを
使う。 /etc/rc.d下のスクリプト、rc.sysinit を修正してRAMディスク化の作業
を行う。
(2). ルートファイルシステムの整備
(2-1). コンパクトフラッシュ上のファイル構成
システムインストール後の、現在の /ディレクトリ構成は次のとおり。
[root@onlsbc1 inoue]# df -k
Filesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/hda5 505605 86900 392601 19% /
/dev/hda1 101089 9166 86704 10% /boot
/dev/hda2 10080520 75952 9492500 1% /home
none 152188 0 152188 0% /dev/shm
/dev/hda3 10080520 3968400 5600052 42% /usr
/dev/hda6 1027768 153676 821884 16% /var
/dev/hdc1 483886 432600 26290 95% /mnt
[root@onlsbc1 inoue]# cd /mnt
[root@onlsbc1 mnt]# ls -l
合計 147
drwxr-xr-x 2 root root 2048 12月 13 00:20 bin
drwxr-xr-x 3 root root 1024 12月 13 00:20 boot
drwxr-xr-x 20 root root 116736 12月 18 16:48 dev
drwxr-xr-x 25 root root 2048 12月 18 16:49 etc
drwxr-xr-x 5 root root 1024 12月 13 00:31 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 5 root root 3072 12月 13 00:21 lib
drwx------ 2 root root 12288 12月 13 00:06 lost+found
drwxr-xr-x 3 root root 1024 12月 12 15:52 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
drwxr-xr-x 2 root root 1024 12月 13 00:06 proc
drwxr-x--- 3 root root 1024 12月 17 16:08 root
drwxr-xr-x 2 root root 3072 12月 13 00:20 sbin
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 16 root root 1024 12月 18 08:52 usr
drwxr-xr-x 17 root root 1024 12月 13 00:29 var
[root@onlsbc1 mnt]#
現在立ち上がっているのは、2.5" IDE上のLinuxシステムである。 このシステ
ムの /mnt に 512MBのコンパクトフラッシュのLinuxシステムをマウントして
RAMディスク化の作業を進める。
(2-2). コンパクトフラッシュ上のファイル構成の変更
/etc/rc.d/rc.sysinitファイルの中で、RAMディスク構築の作業を行うので、
initrd実行後には /etc下のディレクトリ構造は存在していなければならない。
上記の項目(2-1)で示したディレクトリ構成を、図2の構成に変更する。
[root@onlsbc1 mnt]# pwd
/mnt
[root@onlsbc1 mnt]# ls -l
合計 147
drwxr-xr-x 2 root root 2048 12月 13 00:20 bin
drwxr-xr-x 3 root root 1024 12月 13 00:20 boot
drwxr-xr-x 20 root root 116736 12月 18 16:48 dev
drwxr-xr-x 25 root root 2048 12月 18 16:49 etc
drwxr-xr-x 5 root root 1024 12月 13 00:31 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 5 root root 3072 12月 13 00:21 lib
drwx------ 2 root root 12288 12月 13 00:06 lost+found
drwxr-xr-x 3 root root 1024 12月 12 15:52 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
drwxr-xr-x 2 root root 1024 12月 13 00:06 proc
drwxr-x--- 3 root root 1024 12月 17 16:08 root
drwxr-xr-x 2 root root 3072 12月 13 00:20 sbin
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 16 root root 1024 12月 18 08:52 usr
drwxr-xr-x 17 root root 1024 12月 13 00:29 var
[root@onlsbc1 mnt]#
[root@onlsbc1 mnt]# mkdir ramfs
[root@onlsbc1 mnt]# mv etc ramfs
[root@onlsbc1 mnt]# mv tmp ramfs
[root@onlsbc1 mnt]# mv var ramfs
[root@onlsbc1 mnt]#
/etc、/tmp、/var から ramfs の下にそれぞれシンボリックリンクを張る。
[root@onlsbc1 mnt]# ln -s ramfs/etc etc
[root@onlsbc1 mnt]# ln -s ramfs/tmp tmp
[root@onlsbc1 mnt]# ln -s ramfs/var var
[root@onlsbc1 mnt]#
[root@onlsbc1 mnt]# ls -l
合計 144
drwxr-xr-x 2 root root 2048 12月 13 00:20 bin
drwxr-xr-x 3 root root 1024 12月 13 00:20 boot
drwxr-xr-x 20 root root 116736 12月 18 16:48 dev
lrwxrwxrwx 1 root root 9 12月 18 17:37 etc -> ramfs/etc
drwxr-xr-x 5 root root 1024 12月 13 00:31 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 5 root root 3072 12月 13 00:21 lib
drwx------ 2 root root 12288 12月 13 00:06 lost+found
drwxr-xr-x 3 root root 1024 12月 12 15:52 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
drwxr-xr-x 2 root root 1024 12月 13 00:06 proc
drwxr-xr-x 5 root root 1024 12月 18 17:36 ramfs
drwxr-x--- 3 root root 1024 12月 17 16:08 root
drwxr-xr-x 2 root root 3072 12月 13 00:20 sbin
lrwxrwxrwx 1 root root 9 12月 18 17:37 tmp -> ramfs/tmp
drwxr-xr-x 16 root root 1024 12月 18 08:52 usr
lrwxrwxrwx 1 root root 9 12月 18 17:37 var -> ramfs/var
[root@onlsbc1 mnt]#
[root@onlsbc1 mnt]# ls -l ramfs
合計 4
drwxr-xr-x 25 root root 2048 12月 18 16:49 etc
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 17 root root 1024 12月 13 00:29 var
[root@onlsbc1 mnt]#
(2-3). /mnt/ramfs/etc の下のシンボリックリンクのチェック
ルートファイルシステムの構成を変更した際にシンボリックリンクが壊れた
可能性がある。 シンボリックリンクを調べる。
[root@onlsbc1 etc]# pwd
/mnt/etc
[root@onlsbc1 etc]# ls -l grub.conf
lrwxrwxrwx 1 root root 22 12月 13 00:31 grub.conf -> ../boot/gr
ub/grub.conf
[root@onlsbc1 etc]# ls -lL grub.conf
ls: grub.conf: そのようなファイルやディレクトリはありません
[root@onlsbc1 etc]#
以下のシンボリックリンクが切れてしまった。
/etc/grub.conf
張りなおす。
[root@onlsbc1 etc]# rm grub.conf
rm: remove シンボリックリンク `grub.conf'? y
[root@onlsbc1 etc]# ln -s ../../boot/grub/grub.conf grub.conf
[root@onlsbc1 etc]# ls -lL grub.conf
-rw------- 1 root root 582 12月 16 16:24 grub.conf
[root@onlsbc1 etc]#
(2-3-1). /mnt/ramfs/etc/httpd の下のシンボリックリンクのチェック
[root@onlsbc1 etc]# pwd
/mnt/etc
[root@onlsbc1 etc]# ls -l httpd/modules
lrwxrwxrwx 1 root root 27 12月 13 00:29 httpd/modules -> ../../
usr/lib/httpd/modules
[root@onlsbc1 etc]# ls -lL httpd/modules
ls: httpd/modules: そのようなファイルやディレクトリはありません
[root@onlsbc1 etc]#
以下のシンボリックリンクが切れてしまった。
/etc/httpd/modules
張りなおす。
[root@onlsbc1 httpd]# pwd
/mnt/etc/httpd
[root@onlsbc1 httpd]# rm modules
rm: remove シンボリックリンク `modules'? y
[root@onlsbc1 httpd]# ln -s ../../../usr/lib/httpd/modules modules
[root@onlsbc1 httpd]# ls -lL modules
合計 1053
-rwxr-xr-x 1 root root 10232 9月 5 06:23 mod_access.so
-rwxr-xr-x 1 root root 8813 9月 5 06:23 mod_actions.so
:
:
-rwxr-xr-x 1 root root 10981 9月 5 06:23 mod_vhost_alias.so
[root@onlsbc1 httpd]#
(2-3-2). /mnt/ramfs/etc/sysconfig/network-scripts の下のシンボリックリンク
のチェック
[root@onlsbc1 etc]# pwd
/mnt/etc
[root@onlsbc1 etc]# ls -l sysconfig/network-scripts/ifdown
lrwxrwxrwx 1 root root 20 12月 13 00:12 sysconfig/network-scrip
ts/ifdown -> ../../../sbin/ifdown
[root@onlsbc1 etc]# ls -lL sysconfig/network-scripts/ifdown
ls: sysconfig/network-scripts/ifdown: そのようなファイルやディレクトリはありませ
ん
[root@onlsbc1 etc]# ls -l sysconfig/network-scripts/ifup
lrwxrwxrwx 1 root root 18 12月 13 00:12 sysconfig/network-scrip
ts/ifup -> ../../../sbin/ifup
[root@onlsbc1 etc]# ls -lL sysconfig/network-scripts/ifup
ls: sysconfig/network-scripts/ifup: そのようなファイルやディレクトリはありません
[root@onlsbc1 etc]#
以下のシンボリックリンクが切れてしまった。
/etc/sysconfig/network-scripts/ifdown
/etc/sysconfig/network-scripts/ifup
張りなおす。
[root@onlsbc1 network-scripts]# pwd
/mnt/etc/sysconfig/network-scripts
[root@onlsbc1 network-scripts]# ls -l ifdown ifup
lrwxrwxrwx 1 root root 20 12月 13 00:12 ifdown -> ../../../sbin
/ifdown
lrwxrwxrwx 1 root root 18 12月 13 00:12 ifup -> ../../../sbin/i
fup
[root@onlsbc1 network-scripts]# rm ifdown ifup
rm: remove シンボリックリンク `ifdown'? y
rm: remove シンボリックリンク `ifup'? y
[root@onlsbc1 network-scripts]# ln -s ../../../../sbin/ifdown ifdown
[root@onlsbc1 network-scripts]# ln -s ../../../../sbin/ifup ifup
[root@onlsbc1 network-scripts]# ls -lL ifdown ifup
-rwxr-xr-x 1 root root 3268 8月 28 07:03 ifdown
-rwxr-xr-x 1 root root 9223 9月 5 02:03 ifup
[root@onlsbc1 network-scripts]#
(2-4). /mnt/ramfs/tmp の下のシンボリックリンクのチェック
[root@onlsbc1 mnt]# pwd
/mnt
[root@onlsbc1 mnt]# ls -laLR tmp
tmp:
合計 2
drwxrwxrwt 2 root root 1024 12月 17 17:12 .
drwxr-xr-x 5 root root 1024 12月 18 17:36 ..
[root@onlsbc1 mnt]#
/mnt/tmp の下にはファイルは存在しない。
(2-5). /mnt/ramfs/var の下のシンボリックリンクのチェック
/mnt/ramfs/var の下をチェックしたところシンボリックリンクが切れている
ものはなかった。
(3). RAMディスク化の検討
(3-1). RAMディスク化のための操作手順
RAMディスク化のためのコマンドは /mnt/etc/rc.d/rc.sysinitファイルの中に
追記する。 ここで行う操作は、
(1). RAMディスクを初期化する。
(2). /mnt/ramfs下のファイルをRAMディスクにコピーする。
(3). RAMディスクを /ramfsにマウントする。
である。
(3-2). カーネルパラメータについてのチェック
RAMディスク用に確保すべきサイズを調べる。
[root@onlsbc1 ramfs]# pwd
/mnt/ramfs
[root@onlsbc1 ramfs]# ls -l
合計 4
drwxr-xr-x 25 root root 2048 12月 19 10:49 etc
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 17 root root 1024 12月 13 00:29 var
[root@onlsbc1 ramfs]# du -k
:
:
265 ./var/www/icons
329 ./var/www
9066 ./var
11108 .
[root@onlsbc1 ramfs]#
ramfs下の etc、tmp、varを収めるRAMディスクのサイズは約 12MB必要である。
しかし、カーネルが作成できるRAMディスクの最大サイズは、標準では4MBで
ある。 Red Hat Linux ディストリビューションで採用されているカーネル
組み込み型のドライバの場合は、カーネル起動時に "ramdisk_size=32" の
ようにオプションを渡せば、最大サイズを変更できる。 以下の例では最大
サイズを 32MBに変更して作業を進めることにする。
チェック:
512MBのコンパクトフラッシュ上のLinuxシステムを、"ramdisk_size=32"の
オプションで起動し直して、実際に使用できるRAMディスクのサイズを確かめて
みる。 /boot/grub/grub.conf を以下のように、RAMディスクの拡張オプション
を付加した項目を追加する。
(3-2-1). /mnt/boot/grub/grub.confファイルの修正
[root@onlsbc1 grub]# pwd
/mnt/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]#
[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
timeout=0
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-14)
root (hd0,0)
# kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ ramdisk_size=32768
initrd /boot/initrd-2.4.18-14.img
~
"grub.conf" 18L, 650C 書込み
[root@onlsbc1 grub]#
上で変更したのは、コンパクトフラッシュ上の grub.confファイルである。
現在のRAMディスク化のテストシステムでは、512MBのコンパクトフラッシュと
2.5"のIDEハードディスクが両方接続されている。 そして512MBのコンパクト
フラッシュ上のLinuxシステムは、2.5"のIDEハードディスクのMBRの grubから
起動するようにしている。 したがって、上で行った変更と同じ変更を、2.5"の
IDEハードディスクのMBRの grub.confファイルにも行っておく。
[root@onlsbc1 grub]# pwd
/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
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda5
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-14)
root (hd0,0)
kernel /vmlinuz-2.4.18-14 ro root=LABEL=/1
initrd /initrd-2.4.18-14.img
title Compact Flash: Red Hat Linux (2.4.18-14)
root (hd1,0)
# kernel /boot/vmlinuz-2.4.18-14 ro root=/dev/hdc1
kernel /boot/vmlinuz-2.4.18-14 ro root=/dev/hdc1 ramdisk_size=32768
initrd /boot/initrd-2.4.18-14.img
title Compact Flash chain: Red Hat Linux (2.4.18-14)
root (hd1,0)
makeactive
"grub.conf" 27L, 893C 書込み
[root@onlsbc1 grub]#
システムをリブートする。
[root@onlsbc1 grub]# reboot
Broadcast message from root (pts/0) (Thu Dec 19 14:41:01 2002):
The system is going down for reboot NOW!
512MB のコンパクトフラッシュ上のLinuxシステムが立ち上がった。
[inoue@onlpara inoue]$ ssh onlsbc1
The authenticity of host 'onlsbc1 (130.87.153.3)' can't be established.
RSA key fingerprint is 81:28:f3:2a:7f:bf:12:d0:03:72:e7:8b:a6:b1:f6:9c.
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:
[inoue@onlsbc1 inoue]$ df -k
Filesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/hdc1 483886 432666 26224 95% /
none 152188 0 152188 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 39 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 12月 12 15:52 floppy
[root@onlsbc1 inoue]# mount -n -o rw /dev/ram0 /mnt
[root@onlsbc1 inoue]# df -k
Filesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/hdc1 483886 432666 26224 95% /
none 152188 0 152188 0% /dev/shm
[root@onlsbc1 inoue]# ls -l /mnt
合計 12
drwx------ 2 root root 12288 12月 19 14:49 lost+found
[root@onlsbc1 inoue]#
/ramfs 下のファイルを RAMディスクにコピーする。
[root@onlsbc1 /]# ls -l
合計 143
drwxr-xr-x 2 root root 2048 12月 13 00:20 bin
drwxr-xr-x 3 root root 1024 12月 13 00:20 boot
drwxr-xr-x 20 root root 116736 12月 19 14:43 dev
lrwxrwxrwx 1 root root 9 12月 18 17:37 etc -> ramfs/etc
drwxr-xr-x 5 root root 1024 12月 13 00:31 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 5 root root 3072 12月 13 00:21 lib
drwx------ 2 root root 12288 12月 13 00:06 lost+found
drwxr-xr-x 3 root root 1024 12月 19 14:49 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
dr-xr-xr-x 39 root root 0 12月 19 2002 proc
drwxr-xr-x 5 root root 1024 12月 18 17:36 ramfs
drwxr-x--- 3 root root 1024 12月 17 16:08 root
drwxr-xr-x 2 root root 3072 12月 13 00:20 sbin
lrwxrwxrwx 1 root root 9 12月 18 17:37 tmp -> ramfs/tmp
drwxr-xr-x 16 root root 1024 12月 18 08:52 usr
lrwxrwxrwx 1 root root 9 12月 18 17:37 var -> ramfs/var
[root@onlsbc1 /]#
[root@onlsbc1 /]# cp -pdr ramfs/etc /mnt
[root@onlsbc1 /]# cp -pdr ramfs/tmp /mnt
[root@onlsbc1 /]# cp -pdr ramfs/var /mnt
[root@onlsbc1 /]#
[root@onlsbc1 /]# ls -l /mnt
合計 16
drwxr-xr-x 25 root root 2048 12月 19 14:42 etc
drwx------ 2 root root 12288 12月 19 14:49 lost+found
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 17 root root 1024 12月 13 00:29 var
[root@onlsbc1 /]#
[root@onlsbc1 /]# cd /mnt
[root@onlsbc1 mnt]# du -k
:
:
329 ./var/www
9130 ./var
11184 .
[root@onlsbc1 mnt]#
/mntにマウントしてあるRAMディスクに、約12MBのファイルを書き込んだ。
(3-2-4). /mntをアンマウントして、/ramfs にマウントし直す
/mnt にマウントしてあるRAMディスクをアンマウントして、/ramfs にマウント
し直す。
[root@onlsbc1 /]# pwd
/
[root@onlsbc1 /]# umount /mnt
[root@onlsbc1 /]# mount -n -o rw /dev/ram0 /ramfs
[root@onlsbc1 /]# ls -l
合計 143
drwxr-xr-x 2 root root 2048 12月 13 00:20 bin
drwxr-xr-x 3 root root 1024 12月 13 00:20 boot
drwxr-xr-x 20 root root 116736 12月 19 14:43 dev
lrwxrwxrwx 1 root root 9 12月 18 17:37 etc -> ramfs/etc
drwxr-xr-x 5 root root 1024 12月 13 00:31 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 5 root root 3072 12月 13 00:21 lib
drwx------ 2 root root 12288 12月 13 00:06 lost+found
drwxr-xr-x 3 root root 1024 12月 12 15:52 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
dr-xr-xr-x 39 root root 0 12月 19 2002 proc
drwxr-xr-x 6 root root 1024 12月 19 15:26 ramfs
drwxr-x--- 3 root root 1024 12月 17 16:08 root
drwxr-xr-x 2 root root 3072 12月 13 00:20 sbin
lrwxrwxrwx 1 root root 9 12月 18 17:37 tmp -> ramfs/tmp
drwxr-xr-x 16 root root 1024 12月 18 08:52 usr
lrwxrwxrwx 1 root root 9 12月 18 17:37 var -> ramfs/var
[root@onlsbc1 /]#
[root@onlsbc1 /]# df -k
Filesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/hdc1 483886 432666 26224 95% /
none 152188 0 152188 0% /dev/shm
[root@onlsbc1 /]# ls -l /mnt
合計 1
drwxr-xr-x 2 root root 1024 12月 12 15:52 floppy
[root@onlsbc1 /]# ls -l ramfs
合計 16
drwxr-xr-x 25 root root 2048 12月 19 14:42 etc
drwx------ 2 root root 12288 12月 19 14:49 lost+found
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 17 root root 1024 12月 13 00:29 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 12月 19 15:36 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-ブロック 使用 使用可 使用% マウント位置
/dev/hdc1 483886 432666 26224 95% /
none 152188 0 152188 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]#
[root@onlsbc1 rc.d]# vi rc.sysinit
#!/bin/bash
#
# /etc/rc.sysinit - run once at boot time
#
# Taken in part from Miquel van Smoorenburg's bcheckrc.
#
:
# Rerun ourselves through initlog
:
# If we're using devfs, start devfsd now - we need the old device names
:
# 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 system font
:
# Set the hostname.
:
# Initialize USB controller and HID devices
:
# Possibly update quotas if fsck was run on /.
:
# check for arguments passed from kernel
:
# Remount the root filesystem read-write.
:
# LVM initialization
:
# Start up swapping.
:
# 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 if 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.
:
# Reread in network configuration data.
:
# Reset the hostname.
:
# 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 ICE 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
:
# Ooh, firewire too.
:
# If they asked for ide-scsi, load it
:
# 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.
#
:
# Boot time profiles. Yes, this should be somewhere else.
:
# 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). コンパクトフラッシュの /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
合計 35
drwxr-xr-x 2 root root 1024 12月 13 00:29 init.d
-rwxr-xr-x 1 root root 2330 7月 14 15:12 rc
-rwxr-xr-x 1 root root 220 7月 11 2001 rc.local
-rwxr-xr-x 1 root root 22095 8月 23 06:10 rc.sysinit
drwxr-xr-x 2 root root 1024 12月 13 00:29 rc0.d
drwxr-xr-x 2 root root 1024 12月 13 00:29 rc1.d
drwxr-xr-x 2 root root 1024 12月 13 00:29 rc2.d
drwxr-xr-x 2 root root 1024 12月 13 00:29 rc3.d
drwxr-xr-x 2 root root 1024 12月 13 00:29 rc4.d
drwxr-xr-x 2 root root 1024 12月 13 00:29 rc5.d
drwxr-xr-x 2 root root 1024 12月 13 00:29 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" 776L, 22314C written
[root@onlsbc1 rc.d]#
[root@onlsbc1 rc.d]# ls -l rc.sysinit
-rwxr-xr-x 1 root root 22314 12月 19 16:47 rc.sysinit
[root@onlsbc1 rc.d]#
注意.
RAMディスク化したのは、システムが書き込む可能性があるディレクトリ
のみである。 この他にもユーザおよびルートが書き込む可能性がある
ディレクトリとして /home、/root がある。 ここは、他のマシンの
ディレクトリをNFSマウントして使う等の処置をしてもらうことにする。
ここでは、この部分については何もしない。
(6). ブートテスト
(6-1). コンパクトフラッシュ上のLinuxシステムを立ち上げる
[root@onlsbc1 /]# reboot
Broadcast message from root (pts/0) (Thu Dec 19 16:58:41 2002):
The system is going down for reboot NOW!
[root@onlsbc1 /]#
MBR部のGRUBが起動し、以下のメニューが表示された。
|
V
Red Hat Linux (2.4.18-14)
Compact Flash: Red Hat Linux (2.4.18-14) <-- この項目を選択
|
V
ブート処理は進んで、INITが実行されRAMディスク作成も正常に実行できた。
システムはシャットダウンした後、正常に立ち上がった。
[inoue@onlpara inoue]$ ssh onlsbc1
inoue@onlsbc1's password:
[inoue@onlsbc1 inoue]$ df -k
Filesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/hdc1 483886 432671 26219 95% /
none 152188 0 152188 0% /dev/shm
[inoue@onlsbc1 inoue]$ ls -l /
合計 143
drwxr-xr-x 2 root root 2048 12月 13 00:20 bin
drwxr-xr-x 3 root root 1024 12月 13 00:20 boot
drwxr-xr-x 20 root root 116736 12月 19 17:01 dev
lrwxrwxrwx 1 root root 9 12月 18 17:37 etc -> ramfs/etc
drwxr-xr-x 5 root root 1024 12月 13 00:31 home
drwxr-xr-x 2 root root 1024 6月 22 2001 initrd
drwxr-xr-x 5 root root 3072 12月 13 00:21 lib
drwx------ 2 root root 12288 12月 13 00:06 lost+found
drwxr-xr-x 3 root root 1024 12月 12 15:52 mnt
drwxr-xr-x 2 root root 1024 8月 24 1999 opt
dr-xr-xr-x 38 root root 0 12月 20 2002 proc
drwxr-xr-x 6 root root 1024 12月 19 17:00 ramfs
drwxr-x--- 3 root root 1024 12月 17 16:08 root
drwxr-xr-x 2 root root 3072 12月 13 00:20 sbin
lrwxrwxrwx 1 root root 9 12月 18 17:37 tmp -> ramfs/tmp
drwxr-xr-x 16 root root 1024 12月 18 08:52 usr
lrwxrwxrwx 1 root root 9 12月 18 17:37 var -> ramfs/var
[inoue@onlsbc1 inoue]$ ls -l /ramfs
合計 16
drwxr-xr-x 25 root root 2048 12月 19 17:14 etc
drwx------ 2 root root 12288 12月 19 17:00 lost+found
drwxrwxrwt 2 root root 1024 12月 17 17:12 tmp
drwxr-xr-x 17 root root 1024 12月 13 00:29 var
[inoue@onlsbc1 inoue]$
ok. RAMディスクがマウントされている。
(6-2). リブートする
[root@onlsbc1 inoue]# reboot
Broadcast message from root (pts/0) (Thu Dec 19 17:17:48 2002):
The system is going down for reboot NOW!
[root@onlsbc1 inoue]#
:
:
Stopping sshd: [ 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 ]
Starting killall: [ OK ]
Sending all process TERM signal... [ OK ]
Sending all process KILL signal... md: recovery thread got woken up...
md: recovery thread finised: [ OK ]
Syncing hardware clock to system time [ 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). シャットダウン時の手続きを調べる
512MBのコンパクトフラッシュ上のLinuxシステムを立ち上げて調べる。
Shutdownはinitプロセスにシグナルを送りランレベ ルの変更を依頼する。
o ランレベル0はシステムを停止する
o ランレベル6はシステムをリブートす る
o ランレベル1はシステムの管理業務が行なえる状態(シングルユーザモード)
にする
システムの停止又はリブート時にどのような動作がなされるかは、/etc/inittab
ファイル中のそれぞれのランレベルの適切なエントリーを参照。
[root@onlsbc1 inoue]# 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 inoue]#
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 ]
Unmounting file systems: umount2: Device or resource busy
unmount: /ramfs: Illegal seek
[ FAILED ]
INIT: no more processes left in this runlevel
umount のエラーを表示している直前のメッセージを出力しているスクリプトを
確認する。
[root@onlsbc1 rc.d]# pwd
/etc/rc.d
[root@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
[root@onlsbc1 rc.d]#
rc0.d/S01halt および rc6.d/S01reboot のスクリプトの中で、"Syncing
hardware clock to system time" のメッセージを出力している。
[root@onlsbc1 rc.d]# pwd
/etc/rc.d
[root@onlsbc1 rc.d]# ls -l init.d/halt
-rwxr-xr-x 1 root root 5075 8月 14 11:01 init.d/halt
[root@onlsbc1 rc.d]# ls -l rc0.d/S01halt
lrwxrwxrwx 1 root root 14 12月 19 17:26 rc0.d/S01halt -> ../ini
t.d/halt
[root@onlsbc1 rc.d]# ls -l rc6.d/S01reboot
lrwxrwxrwx 1 root root 14 12月 19 17:26 rc6.d/S01reboot -> ../i
nit.d/halt
[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]#
つまり、/etc/rc.d/init.d/haltスクリプトが "Syncing hardware clock to
system time" のメッセージを出力している。 この時点で /ramfsを umount
しなくても何も問題ない。 /ramfsのumountはしないで、処理を先に進めるよう
に変更しよう。
(6-5). /etc/rc.d/init.d/haltスクリプトの修正
現在、使用している onlsbc1 のLinuxシステムは、コンパクトフラッシュ上の
ものである。 つまり、/etcディレクトリ等はRAMディスクになっているので
/etc下のファイルを修正しても、システムを立ち上げ直すと修正した部分は
消えてしまい反映されない。 そこで、一旦、2.5"のIDEディスク上のLinuxシス
テムを立ち上げてコンパクトフラッシュ上のファイルシステムをマウントして
修正することにする。
リブートする
[root@onlsbc1 rc.d]# reboot
Broadcast message from root (pts/0) (Fri Dec 20 16:20:14 2002):
The system is going down for reboot NOW!
[root@onlsbc1 rc.d]#
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 a2:22:30:33:6c:fa:3e:76:02:09:a5:76:14:d9:14:53.
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:
[inoue@onlsbc1 inoue]$ su
Password:
[root@onlsbc1 inoue]# mount -t ext3 /dev/hdc1 /mnt
[root@onlsbc1 inoue]# df -k
Filesystem 1K-ブロック 使用 使用可 使用% マウント位置
/dev/hda5 505605 86903 392598 19% /
/dev/hda1 101089 9166 86704 10% /boot
/dev/hda2 10080520 75932 9492520 1% /home
none 152188 0 152188 0% /dev/shm
/dev/hda3 10080520 3968400 5600052 42% /usr
/dev/hda6 1027768 154552 821008 16% /var
/dev/hdc1 483886 432671 26219 95% /mnt
[root@onlsbc1 inoue]#
[root@onlsbc1 init.d]# pwd
/mnt/etc/rc.d/init.d
[root@onlsbc1 init.d]# ls
functions httpd keytable kudzu network random saslauthd sshd
halt kdcrotate killall netfs portmap rawdevices single syslog
[root@onlsbc1 init.d]# mv halt BACK-halt
[root@onlsbc1 init.d]# cp BACK-halt halt
[root@onlsbc1 init.d]# ls -l
合計 58
-rwxr-xr-x 1 root root 5075 8月 14 11:01 BACK-halt
-rwxr-xr-x 1 root root 10068 7月 14 15:39 functions
-rwxr-xr-x 1 root root 5075 12月 20 16:32 halt
-rwxr-xr-x 1 root root 2366 9月 5 06:23 httpd
-rwxr-xr-x 1 root root 1084 8月 3 05:09 kdcrotate
-rwxr-xr-x 1 root root 1347 9月 5 08:06 keytable
-rwxr-xr-x 1 root root 481 7月 6 06:15 killall
-rwxr-xr-x 1 root root 1919 9月 3 16:29 kudzu
-rwxr-xr-x 1 root root 5024 6月 26 18:20 netfs
-rwxr-xr-x 1 root root 6402 7月 10 17:26 network
-rwxr-xr-x 1 root root 1901 8月 7 05:52 portmap
-rwxr-xr-x 1 root root 1516 6月 26 18:20 random
-rwxr-xr-x 1 root root 2211 6月 26 18:34 rawdevices
-rwxr-xr-x 1 root root 1260 9月 3 08:48 saslauthd
-rwxr-xr-x 1 root root 1175 7月 10 17:58 single
-rwxr-xr-x 1 root root 2647 8月 14 13:08 sshd
-rwxr-xr-x 1 root root 1369 6月 24 09:29 syslog
[root@onlsbc1 init.d]#
[root@onlsbc1 init.d]# vi halt
:
sig=
retry=3
remaining=`halt_get_remaining | sort -r`
# <-- by E.Inoue : from here
if [ ${remaining:1:5} = ramfs ]; then
["$remaining" = /ramfs ] && $remaining < /dev/null
else
# --> 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`
[ -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
:
lt" 214L, 5264C 書込み
[root@onlsbc1 init.d]#
立ち上げ直す。
[root@onlsbc1 inoue]# reboot
Broadcast message from root (pts/1) (Tue Dec 24 16:32:08 2002):
The system is going down for reboot NOW!
コンパクトフラッシュ上のシステムが立ち上がった。
コンパクトフラッシュ上のシステムを reboot する。
:
Syncing hardware clock to system time [ OK ]
/etc/rc.d/S01halt: line 156: [/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 ]
/etc/rc.d/S01halt: line 156: [/ramfs: No such file or dirctory
Halting system...
md: stopping all md devices.
flushing ide devices: hda hdc
Power down.
ok. 正常にシャットダウンできた。 これで、Red Hat Linux 8.0システムの
一部をRAMディスク化する作業は完了。
---xxxx