/sbin下h开头的命令不多,仅有4个
halt hdparm hotplug hwclock
halt:停止系统,他和reboot,poweroff等命令属于同一个功能集。
halt命令不不接参数,仅仅有几个选项来决定如何停止系统
-n: 停止系统前不做同步(sync),适合快速关机和那些仅仅只有只读访问的系统。
-w: 仅在wtmp文件中写一条reboot记录,然后退出,他的用处是什么?
-d: 不写reboot记录到wtmp文件中
-f: 强制停机/重启,但不调用shutdown.shutdown是一种安全的关闭系统的方式。
-p: 如果支持,系统关闭后掉电。否则只是停止系统.
hdparm: 获取和设置硬盘参数,当我一次看到hdparm命令和其说明时,我以为我发现了一个秘笈,因为说明中提到,他可以设置一些关键的参数,让你的硬盘提速。同时在网上也找到了不少有关这个命令的介绍,大多数都说可以显著提高硬盘响应速度,还有很多人的标题干脆是“瞬间提高你的Linux的速度”。其实大部分介绍中,主要是修改两个参数,一个是设置DMA为enable,另外一个是设置I/0为32位。
我测试过这两个参数,对硬盘的响应速度确实有很大的影响,特别是DMA的设置,有相差好几倍的效果。
然后实际上,后来的Linux分发版本,对于硬盘的优化早在系统启动中就已经做好了。
而我知道的是,仅仅只有2.2的内核默认是不打开DMA模式的,因此在2.2的内核,利用hdparm -c 1 /dev/hdx的方式来提高硬盘响应速度是有效果的,但是2.2的内核毕竟是古董了。
另外hdparm的man提到hdparm仅仅只是设置ATA/IDE硬盘参数,而对SCSI硬盘是没有用的,当然也对后来出现的SATA,SAS硬盘无效了。 我没有测试过SCSI硬盘,也没有测试过SATA,SAS硬盘,所以现在还不能给出一个确切的答案。
我们看看后来的linux版本是如何在启动是针对不同硬盘做的优化的,下面的脚本片段来自/etc/rc.d/rc.sysinit文件
# 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.
#
disk[0]=s;
disk[1]=hda; disk[2]=hdb; disk[3]=hdc; disk[4]=hdd;
disk[5]=hde; disk[6]=hdf; disk[7]=hdg; disk[8]=hdh;
disk[9]=hdi; disk[10]=hdj; disk[11]=hdk; disk[12]=hdl;
disk[13]=hdm; disk[14]=hdn; disk[15]=hdo; disk[16]=hdp;
disk[17]=hdq; disk[18]=hdr; disk[19]=hds; disk[20]=hdt;
if [ -x /sbin/hdparm ]; then
for device in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
unset MULTIPLE_IO USE_DMA EIDE_32BIT LOOKAHEAD EXTRA_PARAMS
if [ -f /etc/sysconfig/harddisk${disk[$device]} ]; then
. /etc/sysconfig/harddisk${disk[$device]}
HDFLAGS[$device]=
if [ -n “$MULTIPLE_IO” ]; then
HDFLAGS[$device]=”-q -m$MULTIPLE_IO”
fi
if [ -n “$USE_DMA” ]; then
HDFLAGS[$device]=”${HDFLAGS[$device]} -q -d$USE_DMA”
fi
if [ -n “$EIDE_32BIT” ]; then
HDFLAGS[$device]=”${HDFLAGS[$device]} -q -c$EIDE_32BIT”
fi
if [ -n “$LOOKAHEAD” ]; then
HDFLAGS[$device]=”${HDFLAGS[$device]} -q -A$LOOKAHEAD”
fi
if [ -n “$EXTRA_PARAMS” ]; then
HDFLAGS[$device]=”${HDFLAGS[$device]} $EXTRA_PARAMS”
fi
else
HDFLAGS[$device]=”${HDFLAGS[0]}”
fi
if [ -e “/proc/ide/${disk[$device]}/media” ]; then
hdmedia=`cat /proc/ide/${disk[$device]}/media`
if [ “$hdmedia” = “disk” -o -f “/etc/sysconfig/harddisk${disk[$device]}” ]; then
if [ -n “${HDFLAGS[$device]}” ]; then
action $”Setting hard drive parameters for ${disk[$device]}: ” /sbin/hdparm ${HDFLAGS[$device]} /dev/${disk[$device]}
fi
fi
fi
done
fi
这段脚本是所有的IDE硬盘,根据/etc/sysconfig/harddisks文件的策略而设置硬盘的参数. 从这里我们似乎可以看出,sdx设备并不再设置之内,由此是不是可以肯定hdparm对SCSI设备不支持呢?
我们再看看harddisks文件
#
# WARNING !!!
#
# The kernel will autodetect the correct settings for most drives.
# Overriding these settings with hdparm can cause data corruption and/or
# data loss.
# Leave this file as it is unless you know exactly what you're doing !!
#
#
#
# These options are used to tune the hard drives -
# read the hdparm man page for more information
# Set this to 1 to enable DMA. This might cause some
# data corruption on certain chipset / hard drive
# combinations. This is used with the “-d” option
# USE_DMA=1
# Multiple sector I/O. a feature of most modern IDE hard drives,
# permitting the transfer of multiple sectors per I/O interrupt,
# rather than the usual one sector per interrupt. When this feature
# is enabled, it typically reduces operating system overhead for disk
# I/O by 30-50%. On many systems, it also provides increased data
# throughput of anywhere from 5% to 50%. Some drives, however (most
# notably the WD Caviar series), seem to run slower with multiple mode
# enabled. Under rare circumstances, such failures can result in
# massive filesystem corruption. USE WITH CAUTION AND BACKUP.
# This is the sector count for multiple sector I/O – the “-m” option
#
# MULTIPLE_IO=16
# (E)IDE 32-bit I/O support (to interface card)
#
# EIDE_32BIT=3
# Enable drive read-lookahead
#
# LOOKAHEAD=1
# Add extra parameters here if wanted
# On reasonably new hardware, you may want to try -X66, -X67 or -X68
# Other flags you might want to experiment with are -u1, -a and -m
# See the hdparm manpage (man hdparm) for details and more options.
#
EXTRA_PARAMS=
从这个文件的注释我们能够看出,它将影响硬盘效果最明显的参数单独列了出来,而将其他参数放到了EXTRA_PARAMS里。
因此对于hdparm命令的众多参数而言,我们需要去了解的不太多。
hotplug:Linux下热插拔支持脚本。
hwclock:查询和设置硬件时钟(RTC).系统启动时,需要从硬件时钟中读出时间来设置系统系统,这个过程在/etc/rc.d/rc.sysinit脚本中采用hwclock $CLOCKFLAGS的方式来实现。
这里的参数$CLOCKFLAGS分为两部分,一部分是–hctosys,表示同步的方式是硬件时钟到系统时钟。另外一部分参数是时间设置的标准,是标准时间(utc),还是本地时间(localtim).
而关闭系统时,则相反,似乎用-systohc的参数来将系统时钟同步到硬件时钟。