下一页 上一页 目录

4. initrd 指南,用于 root 挂载 RAID

这是制作包含 raid 救援工具的 'initrd' 内存磁盘的步骤。

具体而言,本文档涉及 RAID1 和 RAID5 的实现。

4.1 安全提醒

救援文件系统可以独立使用。如果您的 raid 阵列挂载失败,您将只能使用已挂载并运行的救援系统。请采取适当的安全预防措施!!!

4.2 构建内核和 Raid 工具

首先必须完成的是修补和构建您的内核,并熟悉 raid 工具。请务必包含附录 E 中的 Gadi 的 raid stop 补丁。配置、挂载和测试您的 raid 设备。如何执行此操作的详细信息包含在 raidtools 包中,并在本文档稍后部分进行简要回顾。

4.3 构建 initrd 救援和启动文件系统

我使用 Slackware-3.4 发行版来构建救援/启动文件系统和生产机器的文件系统。任何 Linux 发行版都应该可以正常工作。如果您使用不同的发行版,请查看此过程的 Slackware 特定部分,并根据您的需求进行修改。

我使用 loadlin 从 dos 分区启动内核镜像和内存磁盘,仅仅是因为我的系统中存在需要 dos 配置软件的特殊设备。Lilo 也能同样出色地工作,并且可以使用一个小型 linux 分区来代替,该分区仅包含 raid/boot 文件和 lilo 记录。

对于 raid 启动/救援系统,我选择使用 Slackware 'setup' 脚本创建一个最小的内存磁盘系统,然后在我的内存磁盘上的干净 Slackware 安装之上安装 'linuxthreads' 包和 'raidtools'。我使用了完全相同的步骤来构建生产系统。因此,救援系统和生产系统非常相似。

此安装过程为我提供了一个“裸”系统(保存文件副本),我将覆盖

        /lib/modules/2.x.x......
        /etc .... with a modified fstab, mdtab, raidX.conf, raidboot.conf
        /etc/rc.d
        /dev/md*

来自我当前系统的文件,以针对特定内核和机器进行自定义,以便在其上运行/即将运行。

这使得启动/救援系统与在 root 挂载 raid 设备上运行的系统相同,只是稍微精简了一些,同时允许库等修订始终保持最新。

4.4 启动逐步说明

从 root 用户主目录 (/root) 开始

        cd /root
        mkdir raidboot
        cd raidboot

创建挂载点以进行操作

        mkdir mnt
        mkdir mnt2

创建一个足够大的文件来进行文件系统安装。这将比最终的救援文件系统大得多。我选择了 24 兆字节,因为 16 兆字节不够大

        dd if=/dev/zero of=build bs=1024k count=24
将该文件与循环设备关联,并在该文件上生成 ext2 文件系统

        losetup /dev/loop0 build
        mke2fs -v -m0 -L initrd /dev/loop0
        mount /dev/loop0 mnt

4.5 安装发行版 - Slackware 特定

...跳过 Slackware 特定内容 并转到下一节。

现在已创建并挂载了一个空文件系统,运行 “setup”。

Specify         /root/raidboot/mnt

作为“目标”。源是您通常从中安装的任何内容。选择您要安装的软件包并继续,但不要配置。

选择“专家”提示模式。

我选择了 “A”、“AP” 和 “N”,仅安装运行系统所需的最低限度,外加我熟悉的编辑器(vi、jed、joe),这些编辑器都相当紧凑。

lqqqqqqqq SELECTING PACKAGES FROM SERIES A (BASE LINUX SYSTEM) qqqqqqqqk
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x   [X] aaa_base  Basic filesystem, shell, and utils - REQUIRED    x x
x x   [X] bash      GNU bash-1.14.7 shell - REQUIRED                 x x
x x   [X] devs      Device files found in /dev - REQUIRED            x x
x x   [X] etc       System config files & utilities - REQUIRED       x x
x x   [X] shadow    Shadow password suite - REQUIRED                 x x
x x   [ ] ide       Linux 2.0.30 no SCSI (YOU NEED 1 KERNEL)         x x
x x   [ ] scsi      Linux 2.0.30 with SCSI (YOU NEED 1 KERNEL)       x x
x x   [ ] modules   Modular Linux device drivers                     x x
x x   [ ] scsimods  Loadable SCSI device drivers                     x x
x x   [X] hdsetup   Slackware setup scripts - REQUIRED               x x
x x   [ ] lilo      Boots Linux (not UMSDOS), DOS, OS/2, etc.        x x
x x   [ ] bsdlpr    BSD lpr - printer spooling system                x x
x x   [ ] loadlin   Boots Linux (UMSDOS too!) from MS-DOS            x x
x x   [ ] pnp       Plug'n'Play configuration tool                   x x
x x   [ ] umsprogs  Utilities needed to use the UMSDOS filesystem    x x
x x   [X] sysvinit  System V-like INIT programs - REQUIRED           x x
x x   [X] bin       GNU fileutils 3.12, elvis, etc. - REQUIRED       x x
x x   [X] ldso      Dynamic linker/loader - REQUIRED                 x x
x x   [ ] ibcs2     Runs SCO/SysVr4 binaries                         x x
x x   [X] less      A text pager utility - REQUIRED                  x x
x x   [ ] pcmcia    PCMCIA card services support                     x x
x x   [ ] getty     Getty_ps 2.0.7e - OPTIONAL                       x x
x x   [X] gzip      The GNU zip compression - REQUIRED               x x
x x   [X] ps        Displays process info - REQUIRED                 x x
x x   [X] aoutlibs  a.out shared libs - RECOMMENDED                  x x
x x   [X] elflibs   The ELF shared C libraries - REQUIRED            x x
x x   [X] util      Util-linux utilities - REQUIRED                  x x
x x   [ ] minicom   Serial transfer and modem comm package           x x
x x   [ ] cpio      The GNU cpio backup/archiving utility            x x
x x   [X] e2fsbn    Utilities for the ext2 file system               x x
x x   [X] find      GNU findutils 4.1                                x x
x x   [X] grep      GNU grep 2.0                                     x x
x x   [ ] kbd       Change keyboard mappings                         x x
x x   [X] gpm       Cut and paste text with your mouse               x x
x x   [X] sh_utils  GNU sh-utils 1.16 - REQUIRED                     x x
x x   [X] sysklogd  Logs system and kernel messages                  x x
x x   [X] tar       GNU tar 1.12 - REQUIRED                          x x
x x   [ ] tcsh      Extended C shell version 6.07                    x x
x x   [X] txtutils  GNU textutils-1.22 - REQUIRED                    x x
x x   [ ] zoneinfo  Configures your time zone                        x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
从 “AP” 系列中,我仅使用 “JOE”(我喜欢的编辑器)和 “MC”(一个小型且有用的文件管理工具)。您可以选择系统上需要的实用程序。
lqqqqqqqqq SELECTING PACKAGES FROM SERIES AP (APPLICATIONS) qqqqqqqqqk
x x     [ ] ispell    The International version of ispell          x x
x x     [ ] jove      Jonathan's Own Version of Emacs text editor  x x
x x     [ ] manpgs    More man pages (online documentation)        x x
x x     [ ] diff      GNU diffutils                                x x
x x     [ ] sudo      Allow special users limited root access      x x
x x     [ ] ghostscr  GNU Ghostscript version 3.33                 x x
x x     [ ] gsfonts1  Ghostscript fonts (part one)                 x x
x x     [ ] gsfonts2  Ghostscript fonts (part two)                 x x
x x     [ ] gsfonts3  Ghostscript fonts (part three)               x x
x x     [ ] jed       JED programmer's editor                      x x
x x     [X] joe       joe text editor, version 2.8                 x x
x x     [ ] jpeg      JPEG image compression utilities             x x
x x     [ ] bc        GNU bc - arbitrary precision math language   x x
x x     [ ] workbone  a text-based audio CD player                 x x
x x     [X] mc        The Midnight Commander file manager          x x
x x     [ ] mt_st     mt ported from BSD - controls tape drive     x x
x x     [ ] groff     GNU troff document formatting system         x x
x x     [ ] quota     User disk quota utilities                    x x
x x     [ ] sc        The 'sc' spreadsheet                         x x
x x     [ ] texinfo   GNU texinfo documentation system             x x
x x     [ ] vim       Improved vi clone                            x x
x x     [ ] ash       A small /bin/sh type shell - 62K             x x
x x     [ ] zsh       Zsh - a custom *nix shell                    x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
从 “N” 软件包中,我仅加载了 TCPIP。这实际上不是必需的,但非常方便,并且允许在修复或更新 root raid 阵列卸载的情况下访问网络。TCPIP 还包含 “biff”,某些 “A” 中的应用程序会使用它。如果您不安装 “N”,您可能仍然需要安装 biff 软件包。
lqqqq SELECTING PACKAGES FROM SERIES N (NETWORK/NEWS/MAIL/UUCP) qqqqqk
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x    [ ] apache    Apache WWW (HTTP) server                      x x
x x    [ ] procmail  Mail delivery/filtering utility               x x
x x    [ ] dip       Handles SLIP/CSLIP connections                x x
x x    [ ] ppp       Point-to-point protocol                       x x
x x    [ ] mailx     The mailx mailer                              x x
x x    [X] tcpip     TCP/IP networking programs                    x x
x x    [ ] bind      Berkeley Internet Name Domain server          x x
x x    [ ] rdist     Remote file distribution utility              x x
x x    [ ] lynx      Text-based World Wide Web browser             x x
x x    [ ] uucp      Taylor UUCP 1.06.1 with HDB && Taylor configs x x
x x    [ ] elm       Menu-driven user mail program                 x x
x x    [ ] pine      Pine menu-driven mail program                 x x
x x    [ ] sendmail  The sendmail mail transport agent             x x
x x    [ ] metamail  Metamail multimedia mail extensions           x x
x x    [ ] smailcfg  Extra configuration files for sendmail        x x
x x    [ ] cnews     Spools and transmits Usenet news              x x
x x    [ ] inn       InterNetNews news transport system            x x
x x    [ ] tin       The 'tin' news reader (local or NNTP)         x x
x x    [ ] trn       'trn' for /var/spool/news                     x x
x x    [ ] trn-nntp  'trn' for NNTP (install 1 'trn' maximum)      x x
x x    [ ] nn-spool  'nn' for /var/spool/news                      x x
x x    [ ] nn-nntp   'nn' for NNTP (install 1 'nn' maximum)        x x
x x    [ ] netpipes  Network pipe utilities                        x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
安装完成后,对所有其他内容说“否”(对所有配置请求说“否”),然后退出脚本。

4.6 安装 linux pthreads

现在您必须安装 “linuxthreads-0.71” 库。我包含了 linuxthreads Makefile 的此差异,而不是手动解释安装的详细信息。保存原始 Makefile,应用差异,然后

        cd /usr/src/linuxthreads-0.71
  patch
        make
        make install
-------------------diff Makefile.old  Makefile.raid-----------------
2a3,13
> # If you are building "linuxthreads" for installation on a mount
> # point which is not the "root" partition, redefine 'BUILDIR' to
> # the mount point to use as the "root" directory
> # You may wish to do this if you are building an 'initial ram disk'
> # such as used with bootable root raid devices.
> # REQUIRES ldconfig version 1.9.5 or better
> # do ldconfig -v to check
> #
> BUILDIR=/root/raidboot/mnt
> #BUILDIR=
> 
81,82c92,93
<       install pthread.h $(INCLUDEDIR)/pthread.h
<       install semaphore.h $(INCLUDEDIR)/semaphore.h
---
>       install pthread.h $(BUILDIR)$(INCLUDEDIR)/pthread.h
>       install semaphore.h $(BUILDIR)$(INCLUDEDIR)/semaphore.h
84c95
<       test -f /usr/include/sched.h || install sched.h $(INCLUDEDIR)/sched.h
---
>       test -f $(BUILDIR)/usr/include/sched.h || install sched.h $(BUILDIR)$(INCLUDEDIR)/sched.h
86,89c97,103
<       install $(LIB) $(LIBDIR)/$(LIB)
<       install $(SHLIB) $(SHAREDLIBDIR)/$(SHLIB)
<       rm -f $(LIBDIR)/$(SHLIB0)
<       ln -s $(SHAREDLIBDIR)/$(SHLIB) $(LIBDIR)/$(SHLIB0)
---
>       install $(LIB) $(BUILDIR)$(LIBDIR)/$(LIB)
>       install $(SHLIB) $(BUILDIR)$(SHAREDLIBDIR)/$(SHLIB)
>       rm -f $(BUILDIR)$(LIBDIR)/$(SHLIB0)
>       ln -s $(SHAREDLIBDIR)/$(SHLIB) $(BUILDIR)$(LIBDIR)/$(SHLIB0)
> ifneq ($(BUILDIR),)
>       ldconfig -r ${BUILDIR} -n $(SHAREDLIBDIR)
> else
91c105,106
<       cd man; $(MAKE) MANDIR=$(MANDIR) install
---
> endif
>       cd man; $(MAKE) MANDIR=$(BUILDIR)$(MANDIR) install

4.7 安装 Raid 工具

下一步是安装 raid 工具。raidtools-0.42

您必须运行 “configure” 脚本,以将 Makefile 指向内存磁盘文件的构建目录

  cd /usr/src/raidtools-0.42
  configure --sbindir=/root/raidboot/mnt/sbin --prefix=/root/raidboot/mnt/usr
  make
  make install
现在!!install 的 Makefile 不完全正确,因此请执行以下操作进行清理。这将在未来的版本中修复,以便不再需要重新链接。

修复 make install 错误

Makefile 中 'LINKS' 中指定的文件链接必须删除并重新链接才能正常运行。

        cd /root/raidboot/mnt/sbin
        ln -fs mdadd mdrun
        ln -fs mdadd mdstop

4.8 从新文件系统中删除不需要的目录和文件。

从文件系统中删除以下目录(注意:不要从您正在运行的系统中删除),很容易做到,猜猜我是怎么发现的!!!

        cd /root/raidboot/mnt
        rm -r home/ftp/*
        rm -r lost+found
        rm -r usr/doc
        rm -r usr/info
        rm -r usr/local/man
        rm -r usr/man
        rm -r usr/openwin
        rm -r usr/share/locale
        rm -r usr/X*
        rm -r var/man
        rm -r var/log/packages
        rm -r var/log/setup
        rm -r var/log/disk_contents

4.9 创建 /dev/mdx

最后一步只是将 /dev/md* 设备从当前文件系统复制到救援文件系统。您可以使用 mknode 创建这些设备。

        cp -a /dev/md* /root/raidboot/mnt/dev

4.10 创建适用于 initrd 的裸文件系统

现在您有了一个干净的可重复使用的文件系统,可以进行自定义。自定义后,如果 raid 设备损坏且需要 raid 工具来修复它们,则可以使用此文件系统进行救援。通过添加 linuxrc 文件(将在下一节中讨论),它还将用于启动和 root 挂载 raid 设备。

将文件系统复制到较小的设备以用于 initrd 文件,16 兆字节应该足够大。

创建较小的文件系统并挂载它

        cd /root/raidboot
        dd if=/dev/zero of=bare.fs bs=1024k count=16
将该文件与循环设备关联,并在该文件上生成 ext2 文件系统
        losetup /dev/loop1 bare.fs
        mke2fs -v -m0 -L initrd /dev/loop1
        mount /dev/loop1 mnt2
将 “build” 文件系统复制到 “bare.fs”
        cp -a mnt/* mnt2
在自定义之前保存 “bare.fs” 系统,以便以后轻松更新。“build” 文件系统不再需要,可以删除。
        cd /root/raidboot
        umount mnt
        umount mnt2
        losetup -d /dev/loop0
        losetup -d /dev/loop1
        rm build
        cp bare.fs rescue
        gzip -9 bare.fs

创建 BOOT/RESCUE initrd 文件系统

现在从开发平台复制与内核匹配的系统相关项,或者您可以手动修改救援文件系统中的文件以匹配您的目标系统。

        losetup /dev/loop0 rescue
        mount /dev/loop0 mnt
确保您的 etc 目录中没有 *~、core 和日志文件。接下来的 2 个命令会创建一些警告消息,请忽略它们。
        cp -dp /etc/* mnt/etc
        cp -dp /etc/rc.d/* mnt/etc/rc.d

        mkdir  mnt/lib/modules
        cp -a  /lib/modules/2.x.x mnt/lib/modules <--- your current 2.x.x

救援系统更正

编辑以下文件以更正它们以适应您的救援系统。下面列出的一些文件名是 Slackware 特有的,但在其他发行版中具有等效项。

        cd mnt

Non-network
        etc/fstab
        etc/mdtab       should work OK
Network
        etc/hosts
        etc/resolv.conf 
        etc/hosts.equiv         and related files
        etc/rc.d/rc.inet1       correct ip#, mask, gateway, etc...
        etc/rc.d/rc.S           remove entire section on file system status
                from:
                        # Test to see if the root partition is read-only
                to but not including:
                        # remove /etc/mtab* so that mount will .....
                                This avoids the annoying warning that
                                the ramdisk is mounted rw.
        etc/rc.d/rc.xxxxx       others as required, see later on in this doc
        root/.rhosts            if present
        home/xxxx/xxxx          others as required

    WARNING:    The above procedure moves your password and shadow
                files onto the rescue disk!!!!!

    WARNING:    You may not wish to do this for security reasons.
为您系统独有的 /dev/disk... 创建任何用于挂载的目录。这些是用于启动系统的挂载点(启动分区和备份启动分区)。我的系统使用 loadlin 从 dos 启动,但是 linux 分区和 lilo 也可以正常工作。我的系统使用
        cd /root/raidboot/mnt           <--- initrd root
        mkdir dosa                      dos partition mount point
        mkdir dosb                      dos mirror mount point
救援文件系统已完成!

您在检查救援文件系统中的文件后会注意到,仍然可以删除许多文件。我没有这样做,因为这会过度复杂化此过程,并且大多数 raid 系统都具有足够的磁盘和内存。如果您想精简文件系统,请继续!

4.11 使 'initrd' 启动 RAID 设备 - linuxrc

要使救援磁盘启动 raid 设备,您只需要复制可执行脚本文件

linuxrc

到设备的根目录。

linuxrc 文件的操作理论在 附录 G,linuxrc 操作理论 中讨论。

附录 D过时的 linuxrc 和 shutdown 脚本 中包含一个非常简单且更容易理解(工作)的 linuxrc。将以下文本复制到 linuxrc 并保存在您的开发区域中。

 -------------------- linuxrc ----------------------
#!/bin/sh
# ver 1.13 3-6-98
#
################# BEGIN 'linuxrc' ##################
#                DEFINE FUNCTIONS                  #
####################################################
# Define 'Fault' function in the event something 
# goes wrong during the execution of 'linuxrc'
#
FaultExit () {
# correct fstab to show '/dev/ram0' for rescue system
    /bin/cat /etc/fstab | {
    while read Line
    do  
        if [ -z "$( echo ${Line} | /usr/bin/grep md0 )" ]; then
            echo ${Line}
        else
            echo "/dev/ram0 / ext2 defaults 1 1"
        fi
    done
    } > /etc/tmp.$$
    /bin/mv /etc/tmp.$$ /etc/fstab
#       point root at /dev/ram0 (the rescue system)
        echo 0x100>/proc/sys/kernel/real-root-dev
        /bin/umount /proc
        exit
}

# Define 'Warning' procdure to print banner on boot terminal
#
Warning () {
    echo '*********************************'
    echo -e " $*"
    echo '*********************************'
}

# Define 'SplitKernelArg' to help extract 'Raid' related kernel arguments
SplitKernelArg () { eval $1='$( IFS=,; echo $2)' }

#Define 'SplitConfArgs' to help extract system configuration arguments
SplitConfArgs () {
    RaidBootType=$1
    RaidBootDevice=$2
    RaidConfigPath=$3
}
########################################################
################### MAIN linuxrc #######################
########################################################
# mount the proc file system
/bin/mount /proc

# Get the boot partition and configuration location from command line
CMDLINE=`/bin/cat /proc/cmdline`
for Parameter in $CMDLINE; do
    Parameter=$( IFS='='; echo ${Parameter} )
    case $Parameter in
        Raid*) SplitKernelArg $Parameter;;
    esac
done

# check for 'required raid boot'
if [ -z "${Raid_Conf}" ]; then
    Warning Kernel command line \'Raid_Conf\' missing
    FaultExit
fi
SplitConfArgs $Raid_Conf

# tmp mount the boot partition
/bin/mount -t ${RaidBootType} ${RaidBootDevice} /mnt

# get etc files from primary raid system
pushd /etc

# this will un-tar into 'etc' (see rc.6)
if [ ! -f /mnt/${RaidConfigPath}/raidboot.etc ]; then
# bad news, this file should be here
    Warning required file \'raidboot.etc\' \
    missing from ${RaidBootDevice}/${RaidConfigPath} \\n \
    \\tUsing rescue system defaults
else
    /bin/tar -xf /mnt/${RaidConfigPath}/raidboot.etc
fi
# get 'real' raidboot device for this boot
# status path, and name of raidX.conf
if [ ! -f /mnt/${RaidConfigPath}/raidboot.cfg ]; then
# bad news, this file should be here
    Warning required file 'raidboot.cfg' \
    missing from ${RaidBootDevice}/${RaidConfigPath}\\n \
    \\tUsing rescue system defaults
# Get the first raidX.conf file name in $RArg1
    RaidBootDevs=$RaidBootDevice
    RaidStatusPath=$RaidConfigPath
    for RaidConfigEtc in $( ls raid*.conf )
    do break; done
else
    {
    read RaidBootDevs
    read RaidStatusPath
    read RaidConfigEtc
    } < /mnt/${RaidConfigPath}/raidboot.cfg

fi
popd
/bin/umount /mnt

# Set a flag in case the raid status file is not found
#
RAIDOWN="raidboot.ro not found"
RAIDREF="raidgood.ref not found"
echo "Reading md0 shutdown status."

# search for raid shutdown status
for Device in ${RaidBootDevs}
do
#   these filesystem types should be in 'fstab' since
#   the partitions must be mounted for a clean raid shutdown
    /bin/mount ${Device} /mnt
    if [ -f /mnt/${RaidStatusPath}/raidboot.ro ]; then
        RAIDOWN=`/bin/cat /mnt/${RaidStatusPath}/raidboot.ro`
        RAIDREF=`/bin/cat /mnt/${RaidStatusPath}/raidgood.ref`
        /bin/umount /mnt
        break
    fi
    /bin/umount /mnt
done
# Test for a clean shutdown with array matching reference
if [ "${RAIDOWN}" != "${RAIDREF}" ]; then
    Warning shutdown ERROR ${RAIDOWN}
    FaultExit
fi

# The raid array is clean, remove shutdown status files
for Device in ${RaidBootDevs}
do
    /bin/mount ${Device} /mnt
    /bin/rm -f /mnt/${RaidStatusPath}/raidboot.ro
    /bin/umount /mnt
done

# Write a clean superblock on all raid devices

echo "write clean superblocks"
/sbin/mkraid -f --only-superblock /etc/${RaidConfigEtc}

# Activate raid array(s)
if [ -z "$Raid_ALT" ]; then
    /sbin/mdadd -ar
else
    /sbin/mdadd $Raid_ALT
fi

#  If there are errors - BAIL OUT and leave rescue running
if [ $? -ne 0 ]; then
   Warning some RAID device has errors
   FaultExit
fi

# Everything is fine, let the kernel mount /dev/md0
# tell the kernel to switch to /dev/md0 as the /root device
# The 0x900 value is the device number calculated by:
#  256*major_device_number + minor_device number
echo "/dev/md0 mounted on root"
echo 0x900>/proc/sys/kernel/real-root-dev
# umount /proc to deallocate initrd device ram space
/bin/umount /proc
exit
#------------------ end linuxrc ----------------------
将 'linuxrc' 添加到 initrd 启动设备
        cd /root/raidboot
        chmod 777 linuxrc
        cp -p linuxrc mnt

4.12 修改 rc 脚本以进行 SHUTDOWN

要完成安装,请修改 rc 脚本以在关机时将 md 状态保存到真实 root 设备。

In slackware this is rc.0 -> rc.6
In debian 'bo' this is in both 'halt' and 'reboot'

If you implement this in another distribution, please e-mail
the instructions and sample files so they can be included here.
我对 Bohumil Chalupa 的 raid stop 解决方法进行了轻微修改。他的原始解决方案在 附录 A 中介绍。

由于生产系统上除了 md0 之外没有剩余的 linux 分区,因此启动分区用于存储 raidOK 只读状态。我选择在每个重复的启动分区中写入一个文件,其中包含关机时 md 阵列的状态,并表示 md 设备已重新挂载为 RO。这允许系统在任何硬盘驱动器发生故障时都能安全运行。

修改了关机脚本以调用 rc.raidown,该脚本保存必要的信息以成功重启和挂载 raid 设备。各种 linux 发行版的关机脚本示例在 附录 B 中显示。

要捕获 raid 阵列关机状态,请在任何 case 语句(如果存在)之后但在实际关机(kills、状态保存等)开始之前以及文件系统卸载之前插入对 rc.raidown 的调用。

############ Save raid boot and status info ##############
#
  if [ -x /etc/rc.d/rc.raidown ]; then
    /etc/rc.d/rc.raidown
  fi
################## end raid boot #########################
在所有文件系统卸载后(root 文件系统“不会”卸载),但在任何断电状态检查之前添加
################ for raid arrays #########################
# Stop all known raid arrays (except root which won't stop)
  if [ -x /sbin/mdstop ]; then
    echo "Stopping raid"
    /sbin/mdstop -a
  fi
##########################################################
这将干净地停止除 root 之外的所有 raid 设备。Root 状态在 raidstat.ro 中传递到下一次启动。

将 rc 文件复制到您的新 raid 阵列、仍然挂载在 /root/raidboot/mnt 上的救援文件系统以及开发系统(如果它在同一台机器上)。

根据需要修改救援 etc/fstab,并确保救援 mdtab 正确。

现在将救援磁盘复制到您的 dos 分区,一切都应该准备好将 raid 设备作为 root 启动。

        umount mnt
        losetup -d /dev/loop0
        gzip -9 rescue
将 rescue.gz 复制到您的启动分区。

剩下的就是创建配置文件 raidboot.conf 并通过重启来测试新的文件系统。

4.13 配置 RAIDBOOT - raidboot.conf

示例配置文件后面的注释解释了这三行中的每一行。此示例文件适用于具有重复启动分区的 4 驱动器 raid5 scsii 阵列,启动分区位于驱动器 sda1 和 sdb1 上。在此处放置描述您的文件系统的参数。

  /dev/sda1 /dev/sdb1
  linux
  raid5.conf
# comments may only be placed 'after' the three
# configuration lines.
#
# This is 'raidboot.conf'
#
# line one, the partition(s) containing the 'initrd' raid-rescue system
#       It is not necessary to boot from these partitions, however,
#       since the rescue system will not fit on floppy, it is necessary
#       to know which partitions are to be used to load the rescue system
#
# line two, the path to the raidboot config information
#       Where the shutdown status, etc... is located at boot time
#       It does NOT include the mount point information, only 'path'
#       /mntpoint/'path'
#
# line -3-, name of the raid configuration file
#       Current raid configuration file i.e. raid1.conf, raid5.conf

4.14 RESCUE 和 RAID 的内核 'loadlin 和 lilo' 变量

RESCUE 和 RAID 系统有两个内核变量,只需要指定第一个。

这两个参数中的任何一个都可以在 lilo 或 loadlin 启动参数文件中或在 loadlin 内核命令行中指定。必须注意不要超过最大行长度,但是,如果使用命令行(128 个字符)。

使用 lilo 启动时,参数以以下形式包含在 lilo 配置文件中

append="Raid_Conf=msdos,/dev/sda1,raidboot"
append="Raid_ALT=-r,-p5,/dev/md0,/dev/sda3 /dev/sdb3 /dev/sdc3 /dev/sdd3"
有关更多详细信息,请参阅 man lilo.conf

由于我有一些硬件需要 DOS 配置实用程序,因此我在系统上有一个小的 dos 分区。因此,我使用 loadlin 从 dos 分区启动 raid5 系统,并在配套磁盘上镜像(副本)。raid1 系统使用相同的方法。下面的示例使用 loadlin,但 lilo 的过程非常相似。

我的 dos root 系统包含一个小型编辑器以及实用程序,因此如果需要,我可以修改 loadlin 的启动参数,从而允许我在测试时在我的交换磁盘上重新启动 linux 系统。

dos 系统包含 linux 的这个树结构”

        c:\raidboot.bat
        c:\raidboot\loadlin.exe
        c:\raidboot\zimage
        c:\raidboot\rescue.gz
        c:\raidboot\raidboot.cfg
        c:\raidboot\raidboot.etc
        c:\raidboot\raidgood.ref
        c:\raidboot\raidstat.ro (only at shutdown)
linux.bat 包含
---------------------- linux.bat ---------------------------
echo "Start the LOADLIN process:"
c:\raidboot\loadlin @c:\raidboot\boot.par
-------------------- end linux.bat -------------------------
boot.par 包含
        # loadlin boot parameter file
        #
        # version 1.02 3-6-98

        # linux kernel image
        c:\linux\zimage

        # target root device
        root=/dev/md0
        #root=/dev/ram0
        #root=/dev/sdc5

        # mount root device as 'ro'
        ro

        # size of ram disk
        ramdisk_size=16384

        # initrd file name
        initrd=c:\raidboot\rescue.gz
        #noinitrd

        # memory ends here
        mem=131072k

        # points to raid boot device, configuration file
        # for floppy rescue boot, you may want to specify 
        # this on the command line instead of here
        # format 'filesystem-type,device,path-to-config-frm_mntpnt'
        Raid_Conf=msdos,/dev/sda1,raidboot

        # Alternate mdadd parameters
        # necessary when boot with non-redundant raid
        # otherwise, COMMENT OUT OR SPECIFY 'NULL'
        #Raid_ALT=-r,-p5,/dev/md0,/dev/sda3 /dev/sdb3 /dev/sdc3 /dev/sdd3

        # ethernet devices
        ether=10,0x300,eth0

***** >> NOTE!! the only difference between forcing the rescue system to
            run and the raid device mounting, is the loadlin parameter

                root=/dev/ram0          for the rescue system
                root=/dev/md0           for RAID

                With root=/dev/ram0 the RAID device will not mount
                and the rescue system will run unconditionally.

如果 RAID 阵列失败,救援系统将保持挂载和运行状态。


下一页 上一页 目录