linux 下的init 0,1,2,3,4,5,6知识介绍

一. init是Linux系统操作中不可缺少的程序之一。

  所谓的init进程,它是一个由内核启动的用户级进程。

  内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后,就通过启动一个用户级程序init的方式,完成引导进程。所以,init始终是第一个进程(其进程编号始终为1)。

  内核会在过去曾使用过init的几个地方查找它,它的正确位置(对Linux系统来说)是/sbin/init。如果内核找不到init,它就会试着运行/bin/sh,如果运行失败,系统的启动也会失败。
 

二. init一共分为7个级别,这7个级别的所代表的含义如下

0:停机或者关机(千万不能将initdefault设置为0)

1:单用户模式,只root用户进行维护

2:多用户模式,不能使用NFS(Net File System)

3:完全多用户模式(标准的运行级别)

4:安全模式

5:图形化(即图形界面)

6:重启(千万不要把initdefault设置为6)

其实,可以通过查看/etc/rc.d/中的rc*.d的文件来对比理解。。

init 0,对应的系统会运行,/etc/rc.d/rc0.d里指定的程序。我们来看下名称

[root@localhost  ~]# ls /etc/rc.d/rc0.d 
K01dnsmasq    K15ksmtuned  K35nmb         K60crond       K74lm_sensors  K83portreserve     K85rpcgssd    K88iscsi     K90network       <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S00killall</span>
K10cups       K16ksm       K35smb         K66gpsd        K75netfs       K84NetworkManager  K85rpcidmapd  K88rsyslog   K92ip6tables     <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S01halt</span>
K10saslauthd  K20nfs       K36mysqld      K69rpcsvcgssd  K75udev-post   K84wpa_supplicant  K86nfslock    K89iscsid    K92iptables
K10xfs        K25sshd      K50haldaemon   K70vboxdrv     K76openvpn     K85mdmonitor       K87alsasound  K89netplugd  K98qemu
K15gpm        K30sendmail  K50netconsole  K74acpid       K83bluetooth   K85messagebus      K87rpcbind    K89rdisc     K99lvm2-monitor

依照上述红色字体,开机会执行的两个进程是killall和halt,这两个都表示为终止进程。故init 0是用于表示关机的。

init 1,对应的系统会运行,/etc/rc.d/rc1.d里指定的程序。

[root@localhost ~] # ls /etc/rc.d/rc1.d
K01dnsmasq    K15ksmtuned  K35nmb         K60crond       K74lm_sensors   K84NetworkManager  K85rpcidmapd  K88rsyslog   K92ip6tables     <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S99single</span>
K10cups       K16ksm       K35smb         K66gpsd        K75netfs        K84wpa_supplicant  K86nfslock    K89iscsid    K92iptables
K10saslauthd  K20nfs       K36mysqld      K69rpcsvcgssd  K76openvpn      K85mdmonitor       K87alsasound  K89netplugd  K98qemu
K10xfs        K25sshd      K50haldaemon   K70vboxdrv     K83bluetooth    K85messagebus      K87rpcbind    K89rdisc    <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);"> S02lvm2-monitor</span>
K15gpm        K30sendmail  K50netconsole  K74acpid       K83portreserve  K85rpcgssd         K88iscsi      K90network   <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S26udev-post</span>

这个级别启动的服务有三个,udev、lvm相关的和single(单用户模式的服务)。故此级别是单用户模式,只有root能用,不支持其他用户。

init 2,对应的系统会运行,/etc/rc.d/rc2.d里指定的程序。

[root@localhost ~ ]# ls /etc/rc.d/rc2.d/
K01dnsmasq    K20nfs       K36mysqld      K74lm_sensors      K85rpcgssd    K89netplugd      <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S08iptables</span>    <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S23NetworkManager  S30vboxdrv    S99local</span>
K10saslauthd  K25sshd      K50haldaemon   K75netfs           K85rpcidmapd  K89rdisc         S12rsyslog     S24portreserve     S35qemu
K10xfs        K30sendmail  K50netconsole  K76openvpn         K86nfslock    K90network       S13rpcbind     S25cups            S85gpm
K15ksmtuned   K35nmb       K66gpsd        K83bluetooth       K88iscsi      S02lvm2-monitor  S15mdmonitor   S26acpid           S90crond
K16ksm        K35smb       K69rpcsvcgssd  K84wpa_supplicant  K89iscsid     S08ip6tables     S22messagebus  S26udev-post       S99alsasound

这个级别启动的服务多了,NetworkManager/iptables/acpid/alsa都已经开启,但是nfs,smb,openvpn相关服务没有开启,这个级别不支持nfs。

init 3 , 对应的系统运行/etc/rc.d/rc3.d

[root@localhost ~] # ls /etc/rc.d/rc3.d/
K01dnsmasq    K30sendmail    K74lm_sensors      K89rdisc         S08iptables  S18rpcidmapd       S25cups       S35qemu       S85ksmtuned   S99local
K10saslauthd  K36mysqld      K76openvpn         K90network       S12rsyslog   S19rpcgssd         S25netfs      S50bluetooth  S90crond
K10xfs        K50netconsole  K84wpa_supplicant  K99lvm2-monitor  S13iscsi     S22messagebus      S26acpid      S50haldaemon  S91nmb
K20nfs        K66gpsd        K85mdmonitor       S07iscsid        S13rpcbind   S23NetworkManager  S26udev-post  S84ksm        S91smb
K25sshd       K69rpcsvcgssd  K89netplugd        S08ip6tables     S14nfslock   S24portreserve     S30vboxdrv    S85gpm        S99alsasound

这个级别nfs服务是开启的,被成为完全多用户模式。

init 4

[root@localhost ~ ]# ls /etc/rc.d/rc4.d/
K01dnsmasq    K30sendmail    K66gpsd            K85mdmonitor     S07iscsid     S13rpcbind     S23NetworkManager  S26udev-post  S84ksm        S99local
K10saslauthd  K35nmb         K69rpcsvcgssd      K89netplugd      S08ip6tables  S14nfslock     S24portreserve     S30vboxdrv    S85gpm
K10xfs        K35smb         K74lm_sensors      K89rdisc         S08iptables   S18rpcidmapd   S25cups            S35qemu       S85ksmtuned
K20nfs        K36mysqld      K76openvpn         K90network       S12rsyslog    S19rpcgssd     S25netfs           S50bluetooth  S90crond
K25sshd       K50netconsole  K84wpa_supplicant  K99lvm2-monitor  S13iscsi      S22messagebus  S26acpid           S50haldaemon  S99alsasound

此模式被称为安全模式。

init 5

[root@localhost ~ ]# ls /etc/rc.d/rc5.d/
K01dnsmasq    K25sshd        K66gpsd         K84wpa_supplicant  K87rpcbind   K90network       S22messagebus      S26udev-post  S84ksm        S99local
K10saslauthd  K30sendmail    K69rpcsvcgssd   K85mdmonitor       K88iscsi     K99lvm2-monitor  S23NetworkManager  S30vboxdrv    S85ksmtuned
K10xfs        K36mysqld      K74lm_sensors   K85rpcgssd         K89iscsid    S08ip6tables     S25cups            S35qemu       S91nmb
K15gpm        K50netconsole  K76openvpn      K85rpcidmapd       K89netplugd  S08iptables      S25netfs           S50bluetooth  S91smb
K20nfs        K60crond       K83portreserve  K86nfslock         K89rdisc     S12rsyslog       S26acpid           S50haldaemon  S99alsasound

完全的图形化界面模式

 init 6

[root@localhost ~ ]# ls /etc/rc.d/rc6.d/
K01dnsmasq    K15ksmtuned  K35nmb         K60crond       K74lm_sensors  K83portreserve     K85rpcgssd    K88iscsi     K90network       <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S00killall</span>
K10cups       K16ksm       K35smb         K66gpsd        K75netfs       K84NetworkManager  K85rpcidmapd  K88rsyslog   K92ip6tables     <span style="padding: 0px; margin: 0px; color: rgb(255, 0, 0);">S01reboot</span>
K10saslauthd  K20nfs       K36mysqld      K69rpcsvcgssd  K75udev-post   K84wpa_supplicant  K86nfslock    K89iscsid    K92iptables
K10xfs        K25sshd      K50haldaemon   K70vboxdrv     K76openvpn     K85mdmonitor       K87alsasound  K89netplugd  K98qemu
K15gpm        K30sendmail  K50netconsole  K74acpid       K83bluetooth   K85messagebus      K87rpcbind    K89rdisc     K99lvm2-monitor

这个级别里,只有两个服务,一个为killall,一个是reboot,即,关闭现在的系统,重启。故此级别是重启。

不同的系统版本,可能里面的文件会不同,如果要查看,可以通过ll来看,其实他们都是软连接。

原文地址:http://m.blog.csdn.net/blog/woshizyq/9798191

  • 1
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
很抱歉,作为AI语言模型,我无法编写实际的Linux驱动程序。但是,我可以给您提供一些参考和指导,帮助您开始编写自己的i2c驱动程序。 在Linux中,i2c驱动程序通常使用i2c-dev和i2c-algo-bit内核模块。i2c-dev模块允许用户空间程序通过文件系统接口与i2c总线通信,而i2c-algo-bit模块提供了一种算法,用于在i2c总线上实现位操作。 以下是编写i2c驱动程序的一般步骤: 1. 包含必要的头文件 #include <linux/i2c.h> #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> 2. 定义i2c_driver结构体 static struct i2c_driver my_i2c_driver = { .driver = { .name = "my_i2c_driver", .owner = THIS_MODULE, }, .id_table = my_i2c_idtable, .probe = my_i2c_probe, .remove = my_i2c_remove, }; 在这里,您需要定义一个i2c_driver结构体,其中包括驱动程序的名称、所有者以及probe和remove函数指针。 3. 实现i2c_driver的probe和remove函数 static int my_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { // 处理i2c设备的初始化 return 0; } static int my_i2c_remove(struct i2c_client *client) { // 处理i2c设备的卸载 return 0; } 在probe函数中,您需要编写初始化i2c设备的代码。在remove函数中,您需要编写卸载i2c设备的代码。 4. 注册i2c_driver static struct i2c_device_id my_i2c_idtable[] = { { "my_i2c_device", 0 }, { }, }; MODULE_DEVICE_TABLE(i2c, my_i2c_idtable); static int __init my_i2c_init(void) { return i2c_add_driver(&my_i2c_driver); } static void __exit my_i2c_exit(void) { i2c_del_driver(&my_i2c_driver); } module_init(my_i2c_init); module_exit(my_i2c_exit); 在这里,您需要定义一个i2c_device_id结构体数组,其中包括i2c设备的名称和ID。然后,您需要使用i2c_add_driver函数注册i2c_driver,并使用i2c_del_driver函数注销i2c_driver。 5. 实现i2c设备的读写函数 您还需要实现i2c设备的读写函数,以便用户空间程序可以通过文件系统接口与i2c设备通信。以下是一个简单的读函数的示例: static ssize_t my_i2c_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { struct i2c_client *client = file->private_data; int ret; // 从i2c设备读取数据 ret = i2c_master_recv(client, buf, count); if (ret < 0) { return ret; } return ret; } 对于写函数,您需要使用i2c_master_send函数向i2c设备发送数据。 总的来说,编写i2c驱动程序需要深入了解Linux内核和i2c总线的工作原理。因此,如果您是初学者,建议先学习一些基本的Linux驱动程序编写知识,并在尝试编写i2c驱动程序之前对i2c总线进行更深入的了解。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨痕诉清风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值