2015年8月24日月曜日

NASの自作 Part23

Linuxのブートプロセスについて調べました。
どうやら、BIOS -> ブートローダ -> initramfs -> initramfs init -> init といった順で起動されるようです。今回のケースではinitの前にRAIDの構築処理が実行されているようなので容疑者である initramfs を調べます。

# 展開用に一時ディレクトリの作成
mkdir /tmp/initramfs
cd /tmp/initramfs
# initramfsのイメージを解凍
gunzip -c /boot/initrd.img-3.2.0-4-amd64 | cpio -ivd
# mdadmの設定を発見
cat etc/mdadm/mdadm.conf
DEVICE partitions
HOMEHOST 
ARRAY /dev/md0 metadata=1.2 name=OMV-NODE804:10DisksRAID6 UUID=22a559e2:1d468c1e:75c0ffeb:2b2e8494
# これもmdadmに関連する設定っぽいです
cat conf/mdadm
MD_HOMEHOST='OMV-NODE804'
MD_DEVS=all

やはり、initramfs にRAIDを構築する処理が含まれているようです。 initramfsのイメージのタイムスタンプを見てみると、ちょうど初めてRAIDを設定した日と一致します。おそらくRAIDの設定をすると、その設定に応じて initramfs のイメージが再作成されるのだと推測されます。

ls -lrt /boot/
total 35500
-rw-r--r-- 1 root root  2842400 Aug  5 08:21 vmlinuz-3.2.0-4-amd64
-rw-r--r-- 1 root root  2114623 Aug  5 08:27 System.map-3.2.0-4-amd64
-rw-r--r-- 1 root root   129281 Aug  5 08:27 config-3.2.0-4-amd64
drwxr-xr-x 3 root root    12288 Aug 18 22:50 grub
-rw-r--r-- 1 root root 15622006 Aug 18 23:57 initrd.img-3.2.0-4-amd64.old-dkms
-rw-r--r-- 1 root root 15622782 Aug 19 23:22 initrd.img-3.2.0-4-amd64

この initramfs のイメージをカスタマイズしてSASカードを認識させるような処理を追加すれば解決するような気もしますが、今の私の知識ではかなりの時間がかかりそうです。ここはNASの完成を優先したいので、ブートプロセスの後半でRAIDの再構築を実行してこの問題の解決をはかりたいと思います。
まず、 /etc/init.d の下にRAID再構築のためのシェルスクリプトを作成します。名前は reassemble-raid.sh としました。

#! /bin/sh
### BEGIN INIT INFO
# Provides:          reassemble-raid
# Required-Start:    bootlogd
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: re-assemble raid
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Author: burton9999dev@gmail.com
echo "#### reassemble-raid.sh" > /dev/kmsg
#
# Function that starts the daemon/service
#

do_start()
{
    sleep 30
    mdadm --stop /dev/md0
    mdadm --assemble --scan
    mount -a
    return 0
}

#
# Function that stops the daemon/service
#
do_stop()
{
    # Do nothing
    return 0
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    # Do nothing
    return 0
}

case "$1" in
  start)
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
  #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    exit 3
    ;;
esac

:

このスクリプトを起動時に実行するように設定します。

# スクリプトの実行権を付与
chmod +x reassemble-raid.sh
# 起動時に実行されるよう設定
insserv -d reassemble-raid.sh
# 設定を確認
ls -l /etc/rc*.d/*reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc0.d/K02reassemble-raid.sh -> ../init.d/reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc1.d/K02reassemble-raid.sh -> ../init.d/reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc2.d/S01reassemble-raid.sh -> ../init.d/reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc3.d/S01reassemble-raid.sh -> ../init.d/reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc4.d/S01reassemble-raid.sh -> ../init.d/reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc5.d/S01reassemble-raid.sh -> ../init.d/reassemble-raid.sh
lrwxrwxrwx 1 root root 28 Aug 24 22:30 /etc/rc6.d/K02reassemble-raid.sh -> ../init.d/reassemble-raid.sh

PCを再起動してWebの管理画面を見てみると見事に10台構成でRAIDが構築されていることを確認できました。
起動後のdmesgはこんな感じに出力されています。とりあえずこれで次のステップに進めそうです。いつかdebianマスターになったら initramfs のカスタマイズもチャレンジしてみたいですね。

root@OMV-NODE804:~# dmesg | egrep '(sd|md|####)'
[    0.000000] Linux version 3.2.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Debian 3.2.68-1+deb7u3
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.2.0-4-amd64 root=UUID=6445948c-2f87-4c3c-a949-38a617780bc8 ro quiet
[    0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-3.2.0-4-amd64 root=UUID=6445948c-2f87-4c3c-a949-38a617780bc8 ro quiet
[    2.246686] usb usb1: Manufacturer: Linux 3.2.0-4-amd64 ehci_hcd
[    2.266621] usb usb2: Manufacturer: Linux 3.2.0-4-amd64 ehci_hcd
[    2.267026] usb usb3: Manufacturer: Linux 3.2.0-4-amd64 xhci_hcd
[    2.267282] usb usb4: Manufacturer: Linux 3.2.0-4-amd64 xhci_hcd
[    2.598635] Pid: 0, comm: swapper/2 Not tainted 3.2.0-4-amd64 #1 Debian 3.2.68-1+deb7u3
[    2.625566] sd 1:0:0:0: [sda] 234441648 512-byte logical blocks: (120 GB/111 GiB)
[    2.625573] sd 2:0:0:0: [sdb] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    2.625576] sd 2:0:0:0: [sdb] 4096-byte physical blocks
[    2.625612] sd 2:0:0:0: [sdb] Write Protect is off
[    2.625615] sd 2:0:0:0: [sdb] Mode Sense: 00 3a 00 00
[    2.625616] sd 1:0:0:0: [sda] Write Protect is off
[    2.625618] sd 1:0:0:0: [sda] Mode Sense: 00 3a 00 00
[    2.625633] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.625635] sd 2:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.625844] sd 3:0:0:0: [sdc] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    2.625846] sd 3:0:0:0: [sdc] 4096-byte physical blocks
[    2.625863] sd 3:0:0:0: [sdc] Write Protect is off
[    2.625864] sd 3:0:0:0: [sdc] Mode Sense: 00 3a 00 00
[    2.625872] sd 3:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    2.626292]  sda: sda1 sda2 < sda5 >
[    2.626481] sd 1:0:0:0: [sda] Attached SCSI disk
[    2.646726] sd 1:0:0:0: Attached scsi generic sg0 type 0
[    2.646753] sd 2:0:0:0: Attached scsi generic sg1 type 0
[    2.646774] sd 3:0:0:0: Attached scsi generic sg2 type 0
[    3.153794]  sdc: unknown partition table
[    3.153913] sd 3:0:0:0: [sdc] Attached SCSI disk
[    3.187286]  sdb: unknown partition table
[    3.187396] sd 2:0:0:0: [sdb] Attached SCSI disk
[    3.544516] md: md0 stopped.
[    3.544961] md: bind
[    3.545078] md: bind
[    4.038663] md: raid6 personality registered for level 6
[    4.038665] md: raid5 personality registered for level 5
[    4.038666] md: raid4 personality registered for level 4
[    4.038828] md/raid:md0: device sdb operational as raid disk 0
[    4.038829] md/raid:md0: device sdc operational as raid disk 1
[    4.039208] md/raid:md0: allocated 10592kB
[    4.039224] md/raid:md0: not enough operational devices (8/10 failed)
[    4.039330]  disk 0, o:1, dev:sdb
[    4.039331]  disk 1, o:1, dev:sdc
[    4.039707] md/raid:md0: failed to run raid set.
[    4.039800] md: pers->run() failed ...
[    4.149158] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[    4.271475] #### rcS
[    4.271879] #### rc
[    4.285089] #### mountkernfs.sh
[    4.320851] #### udev
[    4.407393] #### hdparm
[    5.283746] #### hdparm
[    5.284324] #### hdparm
[    5.377741] #### mountdevsubfs.sh
[    5.464819] #### bootlogd
[    5.477998] #### hdparm
[    5.478869] #### hwclock.sh
[    5.479698] #### hostname.sh
[    5.503911] #### keyboard-setup
[    5.621623] #### checkroot.sh
[    5.631675] Adding 4789244k swap on /dev/sda5.  Priority:-1 extents:1 across:4789244k SS
[    5.634896] EXT4-fs (sda1): re-mounted. Opts: (null)
[    5.651213] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
[    5.654642] #### checkroot-bootclean.sh
[    5.654939] #### kmod
[    5.655438] #### mtab.sh
[    5.655488] #### mdadm-raid
[    5.674219] #### lvm2
[    5.680366] #### mountkernfs.sh
[    5.718020] #### mountkernfs.sh
[    5.749598] #### mountdevsubfs.sh
[    5.774441] #### mountdevsubfs.sh
[    5.822404] #### checkfs.sh
[    5.840385] #### mountall.sh
[    6.005198] #### mountall-bootclean.sh
[    6.029545] #### openmediavault
[    6.030175] #### procps
[    6.030951] #### resolvconf
[    6.031413] #### udev-mtab
[    6.032366] #### urandom
[    6.065252] #### networking
[    6.177060] #### rpcbind
[    6.237930] #### nfs-common
[    6.284611] sd 6:0:0:0: [sdd] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.284622] sd 6:0:0:0: [sdd] 4096-byte physical blocks
[    6.284696] sd 6:0:0:0: Attached scsi generic sg3 type 0
[    6.284736] sd 6:0:0:0: [sdd] Write Protect is off
[    6.284745] sd 6:0:0:0: [sdd] Mode Sense: 00 3a 00 00
[    6.284797] sd 6:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.285151] sd 6:0:1:0: [sde] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.285163] sd 6:0:1:0: [sde] 4096-byte physical blocks
[    6.285577] sd 6:0:1:0: Attached scsi generic sg4 type 0
[    6.285628] sd 6:0:1:0: [sde] Write Protect is off
[    6.285639] sd 6:0:1:0: [sde] Mode Sense: 00 3a 00 00
[    6.285694] sd 6:0:1:0: [sde] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.286293] sd 6:0:2:0: [sdf] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.286302] sd 6:0:2:0: [sdf] 4096-byte physical blocks
[    6.286413] sd 6:0:2:0: [sdf] Write Protect is off
[    6.286421] sd 6:0:2:0: [sdf] Mode Sense: 00 3a 00 00
[    6.286470] sd 6:0:2:0: [sdf] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.286802] sd 6:0:2:0: Attached scsi generic sg5 type 0
[    6.287348] sd 6:0:3:0: [sdg] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.287357] sd 6:0:3:0: [sdg] 4096-byte physical blocks
[    6.287844] sd 6:0:3:0: [sdg] Write Protect is off
[    6.287854] sd 6:0:3:0: [sdg] Mode Sense: 00 3a 00 00
[    6.287902] sd 6:0:3:0: [sdg] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.288053] sd 6:0:3:0: Attached scsi generic sg6 type 0
[    6.288679] sd 6:0:4:0: [sdh] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.288687] sd 6:0:4:0: [sdh] 4096-byte physical blocks
[    6.288816] sd 6:0:4:0: [sdh] Write Protect is off
[    6.288826] sd 6:0:4:0: [sdh] Mode Sense: 00 3a 00 00
[    6.288839] sd 6:0:4:0: Attached scsi generic sg7 type 0
[    6.288877] sd 6:0:4:0: [sdh] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.289948] sd 6:0:5:0: Attached scsi generic sg8 type 0
[    6.291090] sd 6:0:6:0: Attached scsi generic sg9 type 0
[    6.291618] sd 6:0:7:0: Attached scsi generic sg10 type 0
[    6.293175] sd 6:0:5:0: [sdi] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.293186] sd 6:0:5:0: [sdi] 4096-byte physical blocks
[    6.293295] sd 6:0:5:0: [sdi] Write Protect is off
[    6.293304] sd 6:0:5:0: [sdi] Mode Sense: 00 3a 00 00
[    6.293350] sd 6:0:5:0: [sdi] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.296648] sd 6:0:6:0: [sdj] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.296660] sd 6:0:6:0: [sdj] 4096-byte physical blocks
[    6.296757] sd 6:0:6:0: [sdj] Write Protect is off
[    6.296766] sd 6:0:6:0: [sdj] Mode Sense: 00 3a 00 00
[    6.296808] sd 6:0:6:0: [sdj] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.297362] sd 6:0:7:0: [sdk] 5860533168 512-byte logical blocks: (3.00 TB/2.72 TiB)
[    6.297371] sd 6:0:7:0: [sdk] 4096-byte physical blocks
[    6.297459] sd 6:0:7:0: [sdk] Write Protect is off
[    6.297467] sd 6:0:7:0: [sdk] Mode Sense: 00 3a 00 00
[    6.297507] sd 6:0:7:0: [sdk] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[    6.828162]  sde: unknown partition table
[    6.828360] sd 6:0:1:0: [sde] Attached SCSI disk
[    6.835051]  sdf: unknown partition table
[    6.835194] sd 6:0:2:0: [sdf] Attached SCSI disk
[    6.840488]  sdi: unknown partition table
[    6.840616] sd 6:0:5:0: [sdi] Attached SCSI disk
[    6.840699]  sdg: unknown partition table
[    6.840802] sd 6:0:3:0: [sdg] Attached SCSI disk
[    6.846153]  sdk: unknown partition table
[    6.846289] sd 6:0:7:0: [sdk] Attached SCSI disk
[    6.847987]  sdh: unknown partition table
[    6.848106] sd 6:0:4:0: [sdh] Attached SCSI disk
[    6.852860]  sdj: unknown partition table
[    6.853001] sd 6:0:6:0: [sdj] Attached SCSI disk
[    6.864162] #### hdparm
[    6.866795] #### hdparm
[    6.867091] #### hdparm
[    6.871241] #### hdparm
[    6.873645] #### hdparm
[    6.881278] #### hdparm
[    6.883350] #### hdparm
[    6.952695]  sdd: unknown partition table
[    6.952856] sd 6:0:0:0: [sdd] Attached SCSI disk
[    6.964155] Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
[    6.974720] #### mountnfs.sh
[    6.978697] #### mountnfs-bootclean
[    6.985112] #### bootmisc.sh
[    6.987552] #### hdparm
[    6.989046] #### kbd
[    7.005246] #### console-setup
[    7.096385] #### quota
[    7.098893] #### stop-bootlogd-single
[    7.103230] #### rc
[    7.109190] #### reassemble-raid.sh
[    7.109397] #### rpcbind
[    7.109436] #### nfs-common
[    7.142792] #### acpid
[    7.147175] #### openmediavault-engined
[    7.152921] #### mdadm
[   37.037753] md: md0 stopped.
[   37.037768] md: unbind
[   37.099813] md: export_rdev(sdb)
[   37.099996] md: unbind
[   37.171527] md: export_rdev(sdc)
[   37.197198] md: md0 stopped.
[   37.200471] md: bind
[   37.200797] md: bind
[   37.201107] md: bind
[   37.201420] md: bind
[   37.201727] md: bind
[   37.202037] md: bind
[   37.202345] md: bind
[   37.202648] md: bind
[   37.202956] md: bind
[   37.203157] md: bind
[   37.215060] md/raid:md0: device sdb operational as raid disk 0
[   37.215067] md/raid:md0: device sdg operational as raid disk 9
[   37.215073] md/raid:md0: device sdf operational as raid disk 8
[   37.215079] md/raid:md0: device sdk operational as raid disk 7
[   37.215085] md/raid:md0: device sdd operational as raid disk 6
[   37.215092] md/raid:md0: device sdi operational as raid disk 5
[   37.215098] md/raid:md0: device sdj operational as raid disk 4
[   37.215104] md/raid:md0: device sde operational as raid disk 3
[   37.215110] md/raid:md0: device sdh operational as raid disk 2
[   37.215116] md/raid:md0: device sdc operational as raid disk 1
[   37.217450] md/raid:md0: allocated 10592kB
[   37.218123] md/raid:md0: raid level 6 active with 10 out of 10 devices, algorithm 2
[   37.218143]  disk 0, o:1, dev:sdb
[   37.218149]  disk 1, o:1, dev:sdc
[   37.218154]  disk 2, o:1, dev:sdh
[   37.218159]  disk 3, o:1, dev:sde
[   37.218164]  disk 4, o:1, dev:sdj
[   37.218170]  disk 5, o:1, dev:sdi
[   37.218175]  disk 6, o:1, dev:sdd
[   37.218180]  disk 7, o:1, dev:sdk
[   37.218185]  disk 8, o:1, dev:sdf
[   37.218190]  disk 9, o:1, dev:sdg
[   37.218307] md0: detected capacity change from 0 to 24003666247680
[   37.229423] #### rmnologin
[   37.229634] #### rc.local
[   37.237578] #### bootlogd
[   37.728902]  md0: unknown partition table

0 件のコメント:

コメントを投稿