Thursday, February 12, 2009

检查根文件系统是否为网络文件系统

追踪网络问题时,看到这么一段bash脚本,发现应该很有用.

      # Don't shut the network down if root is on NFS or a network
    # block device.
        rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/mtab)
        rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
   
    if [[ "$rootfs" =~ ^nfs ]] || [[ "$rootopts" =~ "_netdev|_rnetdev" ]] ; then
        exit 1
    fi

关于/etc/mtab 的作用,可以看busybox关于mount命令是否支持/etc/mtab这个配置选项的描述:
config FEATURE_MTAB_SUPPORT
    bool "Support for the old /etc/mtab file"
    default n
    depends on MOUNT || UMOUNT
    select FEATURE_MOUNT_FAKE
    help
      Historically, Unix systems kept track of the currently mounted
      partitions in the file "/etc/mtab". These days, the kernel exports
      the list of currently mounted partitions in "/proc/mounts", rendering
      the old mtab file obsolete. (In modern systems, /etc/mtab should be
      a symlink to /proc/mounts.)

      The only reason to have mount maintain an /etc/mtab file itself is if
      your stripped-down embedded system does not have a /proc directory.
      If you must use this, keep in mind it's inherently brittle (for
      example a mount under chroot won't update it), can't handle modern
      features like separate per-process filesystem namespaces, requires
      that your /etc directory be writeable, tends to get easily confused
      by --bind or --move mounts, won't update if you rename a directory
      that contains a mount point, and so on. (In brief: avoid.)

      About the only reason to use this is if you've removed /proc from
      your kernel.

endmenu


Wednesday, February 11, 2009

printk

printk可以在任何上下文中调用.其有16K(具体数值menuconfig可以配置)的ring buffer. dmesg显示的就是这部分数据.故如果打印过多,dmesg只能查看到最新的打印,无法得到自开机以来全部的内核打印.

printk的信息级别:
#define    KERN_EMERG    "<0>"    /* system is unusable            */
#define    KERN_ALERT    "<1>"    /* action must be taken immediately    */
#define    KERN_CRIT    "<2>"    /* critical conditions            */
#define    KERN_ERR    "<3>"    /* error conditions            */
#define    KERN_WARNING    "<4>"    /* warning conditions            */
#define    KERN_NOTICE    "<5>"    /* normal but significant condition    */
#define    KERN_INFO    "<6>"    /* informational            */
#define    KERN_DEBUG    "<7>"    /* debug-level messages            */

当不指定级别时,kernel会默认成KERN_WARNING级别

printk最后直接调用或间接调用_call_console_drivers把字符输出到console. 只代码中可以看到:
只有msg_log_level小于console_loglevel的信息才会输出.kernel默认console_loglevel为7( 即 KERN_DEBUG, 故KERN_DEBUG的信息不会输出到console).
/*
 * Write out chars from start to end - 1 inclusive
 */
static void _call_console_drivers(unsigned long start,
                unsigned long end, int msg_log_level)
{
    if (msg_log_level < console_loglevel &&
            console_drivers && start != end) {
        if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
            /* wrapped write */
            __call_console_drivers(start & LOG_BUF_MASK,
                        log_buf_len);
            __call_console_drivers(0, end & LOG_BUF_MASK);
        } else {
            __call_console_drivers(start, end);
        }
    }
}

故要查看在console上看不到的内核信息,即 msg level >= console_loglevel 的信息,可以使用dmesg.

要配置console_loglevel,可以在启动kernel时加上loglevel=n这个选项.也可以在应用层通过syslog系统调用(glibc对应的函数为klogctl)来动态修改.


printk 支持同时向多个console输出字符, 其维护一个console_drivers链表,分别调用
void register_console(struct console *console)
int unregister_console(struct console *console)
来添加或删除console.
其实这个console只是提供内核打印输出的功能.  在串口驱动初始化时, 一般会注册一个console.


Tuesday, February 10, 2009

全国性付费频道运营机构

中数传媒:cctv
上海文广互动电视有限公司: 上海文广新闻传媒集团(SMG)
华诚电影电视数字节目有限公司:由电影频道节目中心(CCTV-6)、中国电影集团公司共同出资
鼎视传媒:由北京北广传媒数字电视有限公司、中央人民广播电台、天津时代天创传媒发展有限公司、山东省广播电视总台、安徽电视台五家股东共同组建成立。

节目由这四个机构各自独立制定销售价格。网络公司只作为本地广播电视网络运营商,负责付费频道用户接入,无权对付费频道内容进行调整、变更,也无权调整其销售价格.

fedora发行版覆盖的kernel版本

fedora 5 kernel-2.6.15-1.2054 kernel-2.6.20-1.2320
fedora 6 kernel-2.6.18-1.2798 kernel-2.6.22.14-72
fedora 7 kernel-2.6.21-1.3194 kernel-2.6.23.17-88
fedora 8 kernel-2.6.23.1-42 kernel-2.6.26.8-57

Thursday, February 05, 2009

提高内存电压解决内存错误问题

表弟的电脑经常蓝屏,并且程序时不时会弹内存读写错误的提示.  这样棘手的问题我也没什么经验.  不过不得以得硬着头皮上, 谁叫他用的电脑是我以前用的.

这样的现象肯定和内存不稳定有关系. 主板上只是插了一根512M的内存,所以不存在多条内存兼容的问题. 

内存不稳定归要到底是内存总线上的波形不是特别的标准, 一定概率下会读写出错.  最好的方法当然是用示波器量一下波形,就波形的缺陷针对性的解决. 没有这样的条件的话, 就只能试试提高电压,降低时钟频率,延长读写时序时间, 都有助于提高稳定性.

看了一下主板的手册,bios里有很多与超频相关的配置, 这样的话进行上述调整就容易的多, 看来当初主板选型真是有先见之明.

进入bios将内存电压调到2.6V,  然后运行memtest86+,  跑了300%都没问题, 接着进入windows运行了一段时间, 也没什么异常. 看来问题解决了.

网上查到的解释:
内存(DIMM)电压控制功能
内存电压调整是为了对付有些品质不是很好内存颗粒而设置的。运行频率提升后,内存的工作压力增加,如果内存颗粒品质不是很好的话,会出现蓝屏、死机等错误。为了能使超频后内存工作稳定,有时就需要加一点内存电压就可以稳定工作了。因为较高的内存工作电压可以使杂讯减弱。内存电压调整的范围根据主机板设计而定,各型号主板提供的设置范围根据主板设计以及采用内存的种类不同而不同。

不过内存电压调高意味着功耗增加,在温度方面也要同步考虑.