/sbin目录下c开头的命令也没有多少,列出如下
cardctl cardmgr change_console chkconfig clock consoletype cryptsetup ctrlaltdel
其中clock还是软连接。
[root@lancy sbin]# ls -l clock
lrwxrwxrwx 1 root root 7 9月 7 12:07 clock -> hwclock
因此这个留待h*命令的时候来学习。
cardctl和cardmgr是对PCMCIA设备的操作,不过似乎直接使用这两个命令来管理PCMCIA设别的机会应该很少。一来PCMCIA插槽只在笔记本上有,二来目前Linux下能支持的PCMCIA设备还真不多,似乎除了一些无线网卡和很少的无线上网卡支持外,其他的我就不清楚了,所以这两个命令我没用过,看了man手册,也没有看出名堂,忽略之。
change_console: 改变终端,这个命令是init来用的,我怎么加参数来执行,也没有看出什么变化,man手册说的很少,忽略之。
chkconfig:更新和查询系统服务的运行级别信息。我们知道大部分的Linux发行版本都有0-6共7个级别的运行模式,先抛开关机的0级别和重启的6级别,那么就还有1-5共5个运行级别,Linux系统允许你定义在不动的运行级别默认启动不动的系统服务。而实际上所有的执行脚本都是在/etc/rc.d/init.d/下面。
而每个不同级别的可以运行的系统服务定义在/etc/rc.d/rc[0-6].d里,里面只有软连接。软连接分成了两种类型,一种是K开始的软连接,一种是S开头的软连接。分别表示需要停止的服务和启动的服务。其中启动顺序有连接名中的数字决定,数字越小,启动的优先级就越高。
很显然如果要我们手工来管理这些连接,恐怕表示一件容易的事情。也是chkconfig就出现了。
目前Linux下的chkconfig主要完成5个方面的功能:
增加可以管理的系统服务
移走可以管理的系统服务
列出当前服务器的启动信息
改变系统服务的启动信息
检查特定服务的启动状态
我们举一个例子阐述上面的5个功能
假设我们写了一个服务程序,我们希望像其他系统服务那样可以定义不同级别的启动停止方式,而不是简单的加入到/etc/rc.d/rc.local文件中。那么我们首先要创建一个运行脚本放到/etc/rc.d/init.d目录下,并设置好权限。如果你不知道如何修改,那么你可以考参init.d目录下的任何一个运行脚本。下面的是我的一个最简单的脚本
[root@lancy init.d]# cat /etc/rc.d/init.d/test
#! /bin/sh
#
# test simple test system service for management by chkconfig
#
# Source function library.
. /etc/rc.d/init.d/functions
# Set defaults
start(){
echo -n “Starting test: ”
/usr/local/bin/tmy start
RETAL=$?
echo
}
stop(){
echo -n “Stopping test: ”
/usr/local/bin/tmy stop
RETVAL=$?
echo
}
restart(){
stop
start
}
# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
*)
echo “Usage: test {start|stop|}”
RETVAL=1
esac
exit $RETVAL
[root@lancy init.d]# cat /usr/local/bin/tmy
#!/bin/bash
if [ $1 = “start” ];then
echo “have started my services”
elif [ $1 = “stop” ]; then
echo “have stoped myservices”
fi
exit 0
现在你可以使用/etc/init.d/test start|stop的方式启动这个服务。但是
chkconfig --list test test 服务不支持 chkconfig
所以,接下来我们要把这个服务器加入到可管理系统服务中,我们需要在执行脚本中加入两行让chkconfig 识别的注释
# chkconfig:2345 20 80
# description: test simple test system service for management by chkconfig
这两行注释是告诉chkconfig命令,这脚本应该在2,3,4,5这4个级别启动,且启动优先级是20,而对应的停止优先级是80。 加入后,我们再试试chkconfig命令
[root@lancy init.d]# chkconfig --list test
test 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add test”)
恩,至少chkconfig认识出了test,而且也说了可以被管理,只是没有加入。
根据提示,我们需要加入他
[root@lancy init.d]# chkconfig --add test
[root@lancy init.d]# echo $?
0
[root@lancy init.d]# chkconfig --list test test
0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
这和我们期望的是一样的。然后我们看看test软连接
[root@lancy init.d]# ls -l /etc/rc.d/rc6.d/K80test
lrwxrwxrwx 1 root root 14 1月 27 20:47 /etc/rc.d/rc6.d/K80test -> ../init.d/test
[root@lancy init.d]# ls -l /etc/rc.d/rc3.d/S20test
lrwxrwxrwx 1 root root 14 1月 27 20:47 /etc/rc.d/rc3.d/S20test -> ../init.d/test
到此,test服务已经加入了可被chkconfig管理的系统服务范围内。那么我们事实修改和删除看看。
[root@lancy init.d]# chkconfig --list test test
0:关闭 1:关闭 2:启用 3:启用
4:启用 5:启用 6:关闭
[root@lancy init.d]# chkconfig --level 3 test off
[root@lancy init.d]# chkconfig --list test test
0:关闭 1:关闭 2:启用 3:关闭 4:启用 5:启用 6:关闭
[root@lancy init.d]# ls -l /etc/rc.d/rc3.d/K80test
lrwxrwxrwx 1 root root 14 1月 27 20:54 /etc/rc.d/rc3.d/K80test -> ../init.d/test
[root@lancy init.d]# chkconfig --del test
[root@lancy init.d]# chkconfig --list test
test 服务支持 chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add test”)
如果要彻底删除test服务,那么就只要删除test执行脚本就行了。
consoletype: 打印连接到标注输入的终端类型;这是Asianux特有的命令,他根据终端的不同类型打印出不同的信息。
如果是虚拟终端(/dev/tty* 或者不是串行终端的/dev/console),打印出vt
如果标准输入是串行终端(/dev/console 和或者/dev/ttyS*),打印serial
如果标准输入是伪终端(/dev/pts/*),打印pty
[root@lancy sbin]# who
root pts/0 Jan 27 19:41 (:0.0)
[root@lancy sbin]# consoletype
pty
[root@lancy sbin]# who
root tty1 Jan 27 21:05
[root@lancy sbin]# consoletype
vt
[root@lancy tmp]# cat test.c
#include
#include
int main()
{
int fd1,fd2;
fd1=open(“test.sh”,O_RDONLY);
if (!fd1)
{
perror(“error open test.sh”);
exit(65);
}
fd2=dup2(fd1,0);
system(“/sbin/consoletype >/tmp/a”);
return 0;
}
[root@lancy tmp]# gcc test.c -o test
[root@lancy tmp]# ./test
[root@lancy tmp]# cat a
serial
[root@lancy tmp]# consoletype
pty
cryptsetup: 对指定的设别进行加密,这里的设别必须是/dev/mapper下的设备,那这样看来2.4的内核是没有这个命令了。 他对应的应该有另外一个命令dm-crypt,但是我的系统上找不到。 该命令没有man手册,其help帮助如下:
[root@lancy /]# cryptsetup –help
Usage: cryptsetup [OPTION…] []
-v, –verbose Shows more detailed error messages
-c, –cipher=STRING The cipher used to encrypt the disk (see
/proc/crypto) (default: “aes”)
-h, –hash=STRING The hash used to create the encryption key from
the passphrase (default: “ripemd160″)
-y, –verify-passphrase Verifies the passphrase by asking for it twice
-d, –key-file=STRING Read the key from a file (can be /dev/random)
-s, –key-size=BITS The size of the encryption key (default: 256)
-b, –size=SECTORS The size of the device
-o, –offset=SECTORS The start offset in the backend device
-p, –skip=SECTORS How many sectors of the encrypted data to skip
at the beginning
Help options:
-?, –help Show this help message
–usage Show this help message
is one of:
create – create device
remove – remove device
reload – modify active device
resize – resize active device
status – show device status
is the device to create under /dev/mapper
is the encrypted device
这个help似乎也不能帮我们了解更多的内容。只好作测试了。
我用了一个U盘来创建LVM,这样在/dev/mapper下面就有对应的设备了。
[root@lancy /]# ls -l /dev/mapper/vg0-lv0
brw-rw—- 1 root disk 253, 0 1月 27 22:13 /dev/mapper/vg0-lv0
[root@lancy /]# mount /dev/mapper/vg0-lv0 /misc
[root@lancy /]# ls -l /misc
总用量 12
drwx—— 2 root root 12288 1月 27 22:21 lost+found
[root@lancy /]# touch /misc/one
[root@lancy /]# ls -l /misc
总用量 12
drwx—— 2 root root 12288 1月 27 22:21 lost+found
-rw-r–r– 1 root root 0 1月 27 22:22 one
[root@lancy /]# umount /misc
[root@lancy /]# cryptsetup create cytest /dev/mapper/vg0-lv0
Enter passphrase:mypassword
[root@lancy /]# ls -l /dev/mapper/vg0-lv0
brw-rw—- 1 root disk 253, 0 1月 27 22:13 /dev/mapper/vg0-lv0
[root@lancy /]# mount /dev/mapper/vg0-lv0 /misc
mount: /dev/mapper/vg0-lv0 already mounted or /misc busy
[root@lancy /]# cryptsetup remove cytest
[root@lancy /]# mount /dev/mapper/vg0-lv0 /misc
[root@lancy /]# ls -l /misc
总用量 12
drwx—— 2 root root 12288 1月 27 22:21 lost+found
-rw-r–r– 1 root root 0 1月 27 22:22 one
加密前的设备和加密后的设备我用od命令查看了输出值,发现没有不同,看了他不是根据内容加密的,具体情况需要查官方网站才知道了。
ctrlaltdel: 设置Ctrl-Alt-Del组合键的功能,这里有两种方式hard和soft。
hard表示当接受Ctrl-Alt-Del组合键时,系统立刻重启计算机,而不会调用sync(2)命令,也不会作其他一些准备,这有点类似不延时的reset按钮。
而soft则表示Ctrl-Alt-Del组合键按下时,他发送SIGINT信号给init进程,那剩下的事情就是看init如何做了。