通用线程: 高级文件系统实现者指南,第 6 部分

豆豆网   技术应用频道   2008年04月15日  【字号: 收藏本文

内容摘要:Daniel Robbins 通过向您演示如何在 Linux 2.4 下来安装这些高级文件系统回答这些问题。在这一安装过程中,Daniel 向您演示了如何使用一个初始化封装器来(最终!)将您的系统转换到“devfs mode”。

  初始化封装器中的更多内容

mount -n /proc
devfs="yes"
for copt in `cat /proc/cmdline`
do
  if [ "${copt%=*}" = "wrapper" ]
  then
    parms=${copt##*=}
    #parse wrapper option
    if [ "${parms/nodevfs//}" != "${parms}" ]
    then
      devfs="no"
    fi
  fi
done

  如果运行到这一代码块,那就意味着在系统引导期间,正在启动;作为处理的第一条命令,将 /proc 安装到根文件系统,这个 /proc 当前为只读。在那之后,执行一个大而复杂的 bash 代码块,该代码块利用了一个非常便利的 Linux 特性。您可能不了解这一特性,内核允许查看 /proc/cmdline 的内容来弄清楚 LILO 或 GRUB 传给内核什么选项。在我们的开发机器中,/proc/cmdline 的内容如下所示:

  /proc/cmdline 的内容

# cat /proc/cmdline
root=/dev/hda6 hda=89355,16,63 mem=524224K

  在上面的代码中,利用已有的 /proc/cmdline,通过它来查找一个我们自己创建的、称为 wrapper 的内核引导变量。如果 wrapper=nodevfs 出现在内核引导选项中,那么该脚本知道不去启动 devfs。然而,如果这一变量没有出现在 /proc/cmdline 中,那么封装器将进行 devfs 初始化。这里的含意是说您可以通过使用 wrapper=nodevfs 内核引导选项来禁止 devfs。如果这么做的话, devfs 变量将被设置成 no ;否则它将被设置成 yes 。

  封装它

  下面是该封装器的剩余部分:

  初始化封装器的剩余部分

if [ "$devfs" = "yes" ]
then
if [ -e /dev/.devfsd ]
then
  clear
  echo
  echo "The init wrapper has detected that /dev has been automatically mounted by"
  echo "the kernel. This will prevent devfs from automatically saving and"
  echo "restoring device permissions. While not optimal, your system will still"
  echo "be able to boot, but any perm/ownership changes or creation of new compat."
  echo "device nodes will not be persistent across reboots until you fix this"
  echo "problem."
  echo
  echo "Fortunately, the fix for this problem is quite simple; all you need to"
  echo "do is pass the "devfs=nomount" boot option to the kernel (via GRUB"
  echo "or LILO) the next time you boot. Then /dev will not be auto-mounted."
  echo "The next time you compile your kernel, be sure that you do not"
  echo "enable the "Automatically mount filesystem at boot" devfs kernel"
  echo "configuration option. Then the "devfs=nomount" hack will no longer be"
  echo "needed."
  echo
   read -t 15 -p "(hit Enter to continue or wait 15 seconds...)"
else 
  mount -n /dev /dev-state -o bind
  mount -n -t devfs none /dev
  if [ -d /dev-state/compat ]
  then
      echo Copying devices from /dev-state/compat to /dev
      cp -ax /dev-state/compat/* /dev
  fi
fi
/sbin/devfsd /dev >/dev/null 2>&1;
fi
exec /sbin/init.system $*

来源:ibm    作者:Daniel Robbins    责编:豆豆技术应用

正在加载评论...